Using a type library with win32com

Thomas Heller theller at python.net
Thu May 22 03:50:46 EDT 2003


jpersson1 at yahoo.com (Jan Persson) writes:

> Hi,
> 
> I have not seen a good answer to this in the previous (old) postings,
> so here we go again.
> 
> I would like to create a COM-server in Python (with an ordinary
> IDispatch interface) together with a type library (tlb file), so that
> environments which relies on type library information can be able to
> instantiate my class.
> 
> From the previous postings I have learnt to do the following:
> 
> 1. Create the Python class that implements my automation-server.
> 2. Create an IDL-file and compiled it with midl.exe.
> 3. Take the resulting tlb-file and register it with REGTLIB.EXE
> 4. Register the Python class with
> win32com.server.register.UseCommandLine().
> 
> But this does not seem to work.
> 
> Is this the correct way to do it or is win32com able to generate
> typelib information on it's own?
> 
> Does anyone have a working example on how to accomplish this?

If you want to live on the edge, you could check out the ctypes' COM
framework. It is supposed to have good support for type libraries and
will allow to implement and use custom and dual interfaces (pure
dispinterfaces are not too much my target for now).

There are some severe limitations at the moment because it is work in
progress, but the basic components are in place (except that currently
you can only implement local servers, not inproc servers).

I just started writing some documentation, and there is a sample which
implements (and uses) a dual interface described in a type library:
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/ctypes/ctypes/docs/sum_sample.stx?rev=1.1&content-type=text/vnd.viewcvs-markup

The ctypes home page is at
http://starship.python.net/crew/theller/ctypes.html.

Thomas




More information about the Python-list mailing list