[python-win32] Bug - Passing byref an array to a com method interpreted as a single element
rvc69
rvc69 at free.fr
Tue Jan 22 01:07:17 EST 2019
Hello TimThank you for your response and time.Best regardsHerve
Envoyé depuis mon smartphone Samsung Galaxy.
-------- Message d'origine --------De : Tim Roberts <timr at probo.com> Date : 21/01/2019 18:57 (GMT+01:00) À : Python-Win32 List <python-win32 at python.org> Objet : Re: [python-win32] Bug - Passing byref an array to a com method interpreted as a single element
rvc69 at 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(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);|
...
> 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, timr at probo.com
Providenza & Boekelheide, Inc.
_______________________________________________
python-win32 mailing list
python-win32 at python.org
https://mail.python.org/mailman/listinfo/python-win32
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20190122/13b99a86/attachment.html>
More information about the python-win32
mailing list