[python-win32] Fixing type ID for an interface file generated by makepy
Brad Buran
bburan at cns.nyu.edu
Wed Jan 26 04:03:12 CET 2011
> This just occurred to me -- I'll bet that is supposed to be a pointer to
> an array of floats, isn't it? Then yes, you have a problem. That's not
> the proper way to pass an array in COM. In the dispatch mechanism,
> you're supposed to pass it as a safe array structure that contains
> sizing information. By declaring a float *, there's no way for the
> marshalling mechanism to know how large the array is.
Yes! That's what it is supposed to be (no wonder I wasn't able to
find it on Google, I assumed that VTS_PR4 was a standardized
constant). The manufacturer has acknowledged that they set it up
wrong, but it's unlikely they'll fix it.
> I think you are going to have to use other magic to access this
> function. I'm not sure there is any way to coerce makepy into
> generating an array of floats to satisfy a float *.
Hmm. As in abandoning win32com.Client and writing a Cython wrapper?
The function in question (ReadTag) takes both a pointer to an array of
floats plus a parameter, nWords, that indicates the size of the array.
Perhaps I could do something like this:
from array import array
a = array('f', [0, 0, 0, 0, 0])
iface = win32com.Client('RPco.X')
# last parameter to method is array size
iface.ReadTag('data', a, 0, len(a))
len(a) would provide the information the COM object needs about the
array size. However, when I attempt this code, I get the following
error:
*only length-1 arrays can be converted to Python scalars*
I'm a bit stumped at this point. Is there an easy way to marshal the
array into the right format needed?
Brad
More information about the python-win32
mailing list