[python-win32] Bug - Passing byref an array to a com method interpreted as a single element
rvc69 at free.fr
rvc69 at free.fr
Mon Jan 21 01:15:54 EST 2019
Hello,
I'm trying to translate a VBA application to Python. I cannot change the COM Server as its works also with others programs.
It seems I have a problem with win32com.client by passing an array of double to a COM method.
VBA allows to pass arrays to COM server byref on the first element of the array
VBA WORKS : ' com object knows ALREADY the number of values to read or write from array
ReDim Preserve Values(0 To nbvalues - 1) ' array of nbvalues double
' setting values,
obj.SetValues Values(0) ' passing byref the address of the first element of the array to read in
' reverse method reading back values
obj.GetValues Values(0) ' passing byref the first address of the array to write in
>From typelib COM interface [id(0x00000007), helpstring("Méthode GetValues")]
HRESULT GetValues([in, out] double* pValues); # pointer on array of double
[id(0x00000008), helpstring("Méthode SetValues")]
HRESULT SetValues([in] double* pValues);
For Python win32com.client values=[1.0]*nbvalues # array of nbvalues values to set
# setting values, PYTHON complains for typeerror and expect just a float. It is not possible to pass the array of double
obj.SetValues (values[0]) # values[0] is pass byval as a single float to com server
#getting values,
obj.GetValues (values[0]) # PYTHON expect just a float, and worst PYTHON exit as the com server tries to write an array of float
Trying to pass to SetValues / GetValues something else than a float gives : return self._oleobj_.InvokeTypes(8, LCID, 1, (24, 0), ((16389, 1),),pValues
TypeError: float() argument must be a string or a number, not 'VARIANT'
It seems win32client do not interpret correctly the type expected by the COM server, here float() instead of pointer on an array of float.
Do you have any ideas of workaround to bypass the Type control and pass byref the adress of the array and not byval the value of the first element ?
Python 3.6 32 bits, pywin32-224
best regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20190121/9dd69c9d/attachment.html>
More information about the python-win32
mailing list