COM, Recieve by reference

Alex Martelli aleax at
Sun Sep 16 17:24:25 CEST 2001

Steve Allison wrote:

> Hi,
> I'm just starting out to investigate whether Python is a good choice
> of language for COM development.  One problem I have come across is
> how to pass variables into Python COM servers by reference.  For

Make sure the type library of the COM server is available to Python
(win32com.client.gencache.EnsureDispatch will do, for example), and
then COM arguments that are correctly described in the type library
will work.  The call signature comprises only [in] and [in,out] arguments,
and all [out] and [in,out] arguments are return values of the call.

> instance, in C++ I can have a COM server with a method like:
> int MyComServer::foo(int* x, int* y) {
>   *x = 21;
>   *y = 64;
>   return OK;
> }

C++ cannot give a complete description of a COM interface, as it
misses [in], [out] and [in,out] attributes in particular.  You need to
consider the interface, and thus the IDL (interface definition
language) description of the method, NOT the implementation,
which is unaccessible and irrelevant.

If the IDL is something like:
    HRESULT foo([out]LONG* x, [out]LONG* y)
then Python will call foo as an argumentless method, and receive
a tuple of two 32-bit integer results, for example.  If, say, one of
the argument is [in,out] instead:
    HRESULT foo([in,out]LONG* x, [out]LONG* y)
then Python will call f    HRESULT foo([out]LONG* x, [out]LONG* y)
oo with one argument (which goes in as the
initial value of *x) and still receive a tuple of two 32-bit integer
results (the final values of *x, *y).


More information about the Python-list mailing list