[python-win32] Accessing methods from python-based COM DLL generated using py2exe

Tim Roberts timr at probo.com
Thu May 3 19:19:48 CEST 2012


Ellis, Alexis -FS wrote:
>
>  
>
> am trying to generate a DLL from a python script that can be accessed
> from a variety other programming platforms. 
>
> I am generating the python-based COM DLL using a distutils setup
> script that is called using py2exe. 
>
> The DLL is successfully generated and I can register it using
> regsvr32, but now I am not sure how to access the function within the dll.
>

Well, you have not actually created a COM server here.  What you have
registered is an empty COM server that defines no methods.  You haven't
actually used any methods from comtypes or comtypes.client at all.

You need to read the documentation for comtypes.server.  You have to
create an IDL file (Interface Description Language) that defines the
methods you expect to expose.  You compile that IDL to a type library
(TLB).  Then, you use comtypes.client.GetModule to generate a wrapper
for that IDL.  Then, your "testscript" module must derive from that
class, and implement the methods you declared.

comtypes creates an "early binding" COM server.  Depending on the
languages you want to use, you might find it easier to create a "late
binding" server using Pythoncom, as described here:
    http://showmedo.com/videotutorials/video?name=2190050&fromSeriesID=219

No IDL is required with this method.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list