[python-win32] Passing arrays by reference

Benoît Prigent benoit.prigent at raisonance.com
Wed May 20 09:13:44 CEST 2009


Hi all,

I found a thread that it similar to what I'm looking for:
http://mail.python.org/pipermail/python-win32/2002-November/000562.html
but I couldn't come up with a solution...

I have a C++ server with a COM interface, which I can access via JScript
without any problem, but when it comes to Python, it seems impossible to
pass an array from the server to the Python script by reference.


C++ method declaration (the method just copies BufIn into BufOut):
STDMETHODIMP CoServer::EchoArray(
    VARIANT BufIn,
    VARIANT * BufOut,
    ULONG* retVal)


IDL:
[id(1), helpstring("method EchoArray")] HRESULT EchoArray(
    [in]         VARIANT BufIn,
    [out]        VARIANT* BufOut,
    [out,retval] ULONG* retVal);
for this one, I tried to replace "[out] VARIANT* BufOut" by "[in,out]
VARIANT* BufOut" or by "[in] VARIANT BufOut" without any success.


Python script:

import win32com.client
import time
import os
Server = win32com.client.Dispatch("MyObject.Server")
ans = [1,2,3]
Server.EchoArray([0x11,0x22,0x33], ans)
print ans

# I am expecting ans=[0x11,0x22,0x33]
# but ans remains as defined earlier ans=[1,2,3]


Does anyone know how to pass an array by reference from a COM
interface to a Python script?

Thank you!
Ben


-- 
Benoît Prigent
Hardware Engineer
_______________________________________
Raisonance SAS
17 avenue Jean Kuntzmann
38330 Montbonnot Saint Martin
France

Phone:    +33 (0)4 76 61 02 39
Fax:      +33 (0)4 76 41 81 68
Email:    benoit.prigent at raisonance.com
Internet: http://www.raisonance.com


More information about the python-win32 mailing list