Problems passing arrays into COM objects using win32com

mb3242 at gmail.com mb3242 at gmail.com
Fri May 13 17:48:03 EDT 2005


Hello, I'm trying to use win32com to call a method in a COM object.
I'm having a problem with Python choosing the wrong type when wrapping
up lists into VARIANTs.

The function I'm trying to call in C++ looks like this:
HRESULT write([in] VARIANT * len, [in] VARIANT * saData, [out] VARIANT
* result);
Where saData contains a SafeArray of bytes and len is its length.  The
function returns any error information in result.

I'm using Python 2.4.1 with pywin32 build 204.  I access the COM object
using:
>>>  import win32com.client
>>>  o= win32com.client.Dispatch('foo.fooAPI.1')
>>>  o.write(2, [3,4])

If I run the COM object in the debugger, I can see what Python has
passed in.  len.vt = 0x0003; an integer as expected.  But saData.vt =
0x200C, an array of VARIANTs.  It should be an array of ints, but it's
not.

I've found a 1998 posting from the pythonCOM dev mailing list that
describes a similar problem, but the solution doesn't work for me:
http://mailman.pythonpros.com/pipermail/pycom-dev/1998q4/000006.html
Mark Hammond recommends using makepy to generate the type info ahead of
time, and using  win32com.client.Dispatch("...") instead of
win32com.client.dynamic.Dispatch("...").  At the time of that posting,
statically generated objects would map into arrays of ints (as
expected), while dynamically generated objects wouldn't.

This sounds reasonable, but I'm already doing what he recommends.  I've
looked around for other documentation, but I haven't had any luck. The
documentation (not surprisingly) hasn't kept up with changes over the
years. 

thanks,

Mark Brighton




More information about the Python-list mailing list