1) the parameter type in the COM definition .py file was incorrect
2) the code shouldn't have been converting the parameter to a buffer object
The type of "indexlist" in the COM definition .py file.
def Read(self, x=defaultNamedNotOptArg, indexlist=defaultNamedNotOptArg, results=pythoncom.Missing): """method Read"""
return self._ApplyTypes_(2, 1, (24, 0), ((3, 1), (16396, 1), (16396, 2)),'Read', None,x, indexlist, results)
16396 - VT_VARIANT, VT_BYREF
which matches exactly the type in the IDL file
...VARIANT* indexlist,...
so makepy worked as expected. The problem is that the interface expected a single variant containing a safearray of integers, so a more proper IDL file might look like this
...SAFEARRAY(int) indexlist,...
I update the .py file with the correct type.
(0x2000 | 19) - VT_ARRAY, VT_IU4
Also, the python code was converting the parameter to a buffer object
addr = buffer(array.array ('L', addr)) // bad
which wasn't correct because this is a special case for the win32com code. All buffer objects are converted to safe arrays of bytes.
I removed that line and code.
After these two changes the code worked.
On 10/19/05, bob <[EMAIL PROTECTED]> wrote:
At 01:22 PM 10/19/2005, Shad Muegge wrote:
>Hi,
>
>I've just started looking at Python. I am trying to resolve an issue a
>user is having trying to access the COM interface in our application from
>Python.
>
>C++ code:
>
>STDMETHODIMP
>CMyClass::Read(
> const int x,
> VARIANT *indexlist, // IN: "safe" array of 4-byte integers
> VARIANT *results)
>
>
>Python code:
>
> def read(self, x, addr):
> try:
> addr = buffer(array.array ('L', addr))
> data = "" addr)
>...
>
>x.read(0, 0x12345678)
>
>The variant that shows up on the C++ code is a safearray of 1-byte
>integers with 4 elements: 12, 34, 56, 78.
>
>The API treats them each as individual "addresses"...
>
>Here's the COM definition from the .py file.
>
> def Read(self, x=defaultNamedNotOptArg, indexlist=defaultNamedNotOptArg,
> results=pythoncom.Missing):
> """method Read"""
> return self._ApplyTypes_(2, 1, (24, 0), ((3, 1), (16396, 1), (16396,
> 2)), 'Read', None,x
> , indexlist, results)
>
_______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32