Re: [python-win32] Bug - Passing byref an array to a com method interpreted as a single element
Tim Roberts wrote: rv...@free.fr wrote: It seems win32client do not interpret correctly the type expected by the COM server, here float() instead of pointer on an array of float. That statement is not accurate. The fault is not in win32client. The root of the problem is that the function definition in your type library is not COM-compliant. There are rules that need to be followed in order for a COM interface to work seamlessly across languages, and you have violated those rules. The proper way to pass an array is to use a SAFEARRAY. Your definition, for example, cannot possibly work in an out-of-process server, because there is no way for the marashaling code to know how much data to send across. The GetValues case is doubly hopeless. How can the server know how large the buffer is? How can the client know how much data will be returned? You are simply not allowed in COM to have that be assumed. Win32client is quite correct in interpreting your definition as it does. The fact that it works in VBA is an lucky accident. If you want this to work reliably, you need to change the interface. Having said all that, you may be able to do what you need with the "comtypes" module, which allows lower-level access to COM interfaces. -- Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc. smime.p7s Description: S/MIME Cryptographic Signature ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Bug - Passing byref an array to a com method interpreted as a single element
rv...@free.fr wrote: 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 ...|| From typelib COM interface |[id(0x0007), helpstring("Méthode GetValues")] HRESULT GetValues([in, out] double* pValues); # pointer on array of double [id(0x0008), helpstring("Méthode SetValues")] HRESULT SetValues([in] double* pValues);| ... It seems win32client do not interpret correctly the type expected by the COM server, here float() instead of pointer on an array of float. That statement is not accurate. The fault is not in win32client. The root of the problem is that the function definition in your type library is not COM-compliant. There are rules that need to be followed in order for a COM interface to work seamlessly across languages, and you have violated those rules. The proper way to pass an array is to use a SAFEARRAY. Your definition, for example, cannot possibly work in an out-of-process server, because there is no way for the marashaling code to know how much data to send across. The GetValues case is doubly hopeless. How can the server know how large the buffer is? How can the client know how much data will be returned? You are simply not allowed in COM to have that be assumed. Win32client is quite correct in interpreting your definition as it does. The fact that it works in VBA is an lucky accident. If you want this to work reliably, you need to change the interface. -- Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc. ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
[python-win32] Bug - Passing byref an array to a com method interpreted as a single element
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(0x0007), helpstring("Méthode GetValues")] HRESULT GetValues([in, out] double* pValues); # pointer on array of double [id(0x0008), 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