[python-win32] Returning objects from COM

Mark Hammond mhammond at skippinet.com.au
Mon Sep 27 05:50:18 CEST 2004


> I don't know COM at all, and fter spending a few hours being
> confused by
> this, I hope someone have an answer for me:
>
> How do I return a custom Python object from a COM server? All
> examples and
> literature I find only allows me to return primitive types.
>
> Basically I want this to work:
>
> o = win32com.client.Dispatch("MyOwnObject.Name")
> " person is a complex object of type Person
> person = o.getPerson("John Doe")
> print person.getName()

You need to use win32com.server.util.wrap().  To get 'debugging' support for
these objects, pass 'useDispatcher=1' as a keyword param - this object will
then operate just like CoCreated objects registered with '--debug'.

Mark.



More information about the Python-win32 mailing list