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
_______________________________________________
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32

Reply via email to