win32com.client - parameter types

Alex Martelli aleaxit at
Tue Feb 27 14:23:13 CET 2001

"Tom Danielsen" <tom at> wrote in message
news:slrn99n5be.8f8.tom at
> I have a COM server with the following method:
>         [id(0x60020016)]
>         HRESULT getDict([out] IDispatch** pDictionary);
> which makepy made into:
>         def getDict(self, pDictionary=defaultNamedNotOptArg):
>                 return self._ApplyTypes_(0x60020016, \
>                         1, (24, 0), ((16393, 2),), \
>                         'getDict', None,pDictionary)

Not to worry -- this may be slightly misleading, but it DOES
in fact work just right.

> This is, the method returns its value in parameter 1.

That's what it does COMwise, but, for Python, this output
parameter IS transformed into a return value!

> VB and VBscript handles this, but I cannot get Python (2.0) to work.
> Is there any way to get at this value in Python?  Is there a way I
> can change the [out] to a [out, retval] and make Python return the
> value as the return value of the method call?  If so, how?

Nothing more than the makepy you've already done.

To try it out, I built a toy (ATL) project (inproc server, just
one object, project name toyatl, object name Toy) with IDL:

// toyatl.idl : IDL source for toyatl.dll

// This file will be processed by the MIDL tool to
// produce the type library (toyatl.tlb) and marshalling code.

import "oaidl.idl";
import "ocidl.idl";

  helpstring("IToy Interface"),
 interface IToy : IDispatch
  [id(1), helpstring("method getDict")] HRESULT getDict([out]IDispatch**

 helpstring("Toy ATL project TLB")
library TOYATLLib

  helpstring("Toy Class")
 coclass Toy
  [default] interface IToy;

and the 'obvious' implementation (FinalConstruct of the CToy class builds an
instance member that's a CComPtr<IDispatch> with a CoCreateInstance on
ProgId "Scripting.Dictionary"; method getDisp just calls a CopyTo on that
member).  After a makepy...:

Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> from win32com.client import Dispatch as disp
>>> x=disp("toyatl.Toy")
>>> a=x.getDict()
>>> a
<win32com.gen_py.clareg 1.0 Type Library.IDictionary>


More information about the Python-list mailing list