[python-win32] Writing .NET component in Python

Thomas Heller theller at ctypes.org
Thu Sep 6 19:29:58 CEST 2007


Sidnei da Silva schrieb:
> [ Thomas Heller ]
>> Not sure what you mean by .NET port.  I have the impression (from reading, 
>> never
>> used .NET myself) that .NET is able to use COM objects.  It may be 
>> required that
>> the COM objects must have a type library.
> 
> That's my understanding too. If you search for articles on .NET and COM 
> Interop pretty much all of them talk about using type libraries.
> 
> Soo... the question is, how to create a type library for Python COM objects?
> 

The canonical answer is:  Write an IDL file, and compile it with the MIDL compiler:

midl mytypelib.idl /tlb mytypelib.tlb

This creates the 'mytypelib.tlb' typelibrary (among other files that you will not need).
A MIDL compiler is probably included in the free VC 2005 express edition, or maybe even
in the MS platform SDK.

The syntax of IDL files is documented on MS sites.  Also useful for reference
is the OLEVIEW program which allows to decompile existing type libraries.


The second approach would be to use pywin32 apis to create the type library programmatically;
there have been several attempts in the past but I have not yet seen a finished solution.


What I do NOT know:  Is the presence of a typelibrary file sufficient for accessing the COM object,
or must the typelib be integrated into the object itself?  There are interfaces that allow a COM
object to make its type information available to clients; I do not know if they are used by .NET
or not.

Thomas



More information about the python-win32 mailing list