[python-win32] Importing an array from COM into Python

Dana Robinson derobins at scs.uiuc.edu
Tue Apr 4 21:14:39 CEST 2006


Hello,

I am trying to get the arrays out of this function (from the IDL):

[id(175), helpstring("method CreateFooBarArray")] HRESULT
CreateFooBarArray([out]DOUBLE** FooArray, [out] DOUBLE** BarArray,
[out,retval] ULONG* SizeOfFooBarArrays);

The two arrays (Foo and Bar) are created with malloc and filled with
useful data inside the COM object.

I am attempting to access them with the following Python code.

size = o.CreateFooBarArray(fooArray, barArray)

This does not work.  I get an error in \client\__init__.py at line 447 in
_ApplyTypes_.  It says "float() argument must be a string or number"
Other COM functions with simple types work fine.  I ran makepy.py over the
COM library and I'm using early-bound automation if that makes any
difference.

So I have two questions:

1) The COM object is brand new and created in-house so I can have it
changed to my liking.  What's the best way to pass a large array
(thousands of elements) of doubles out of a COM object into Python?  I
have Mark Hammond's book, which is very helpful, but passing arrays
between languages doesn't seem to be covered.

2) If the COM object handles the memory allocation, will the arrays be
properly garbage collected?

Actually, I have a third question.  Where can I find a searchable version
of the mailing list?  The one at python.org doesn't appear to be
searchable.

Thanks for your help.  I just switched from the digest to individual
mails, so if you respond this afternoon please cc me so I'll be able to
try your suggestions out before I go home.

Thanks,

Dana Robinson


More information about the Python-win32 mailing list