win32com.client - parameter types

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


"Tom Danielsen" <tom at teikom.no> wrote in message
news:slrn99n5be.8f8.tom at tnt.teikom.no...
>
>
> 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";

 [
  object,
  uuid(565B5BFD-0CB2-11D5-9E52-0060B0EB1D67),
  dual,
  helpstring("IToy Interface"),
  pointer_default(unique)
 ]
 interface IToy : IDispatch
 {
  [id(1), helpstring("method getDict")] HRESULT getDict([out]IDispatch**
pDictionary);
 };

[
 uuid(565B5BF1-0CB2-11D5-9E52-0060B0EB1D67),
 version(1.0),
 helpstring("Toy ATL project TLB")
]
library TOYATLLib
{
 importlib("stdole32.tlb");
 importlib("stdole2.tlb");

 [
  uuid(565B5BFE-0CB2-11D5-9E52-0060B0EB1D67),
  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...:

D:\pybridge>python
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>
>>>


Alex








More information about the Python-list mailing list