Using a TLB-defined interface with Python and COM

com, python

Solution

The questions asked is to link the custom TLB file with COM client to be developed in python. I have done a small example code for my COM server developed in C# and same is accessed by python client using "comtypes" package. The below snippet of code gives:

    import comtypes.client as CC
    import comtypes

    ccHandle = CC.CreateObject("CSharpServer.InterfaceImplementation")
    print (ccHandle)
    import comtypes.gen.CSharpServer as CS
    InterfaceHandle = ccHandle.QueryInterface(CS.IManagedInterface)

    print ("output of PrintHi function = ", InterfaceHandle.PrintHi("World"))

The above python script is for the C# COM server code available at http://msdn.microsoft.com/en-us/library/aa645738(v=vs.71).aspx (refer to the File 1: CSharpServer.cs).

Problem

I will try to keep this question as tight as possible, but if it seems that I am saying insane things, it is almost certainly because I am ignorant of some key point, so please do correct me. I am writing a program, in a Windows environment, that will interface with an existing application that has a COM interface to allow 3rd-party software to interact with it. I have read all of the documentation for this application, and it says that there is a TLB file that defines the functions and data available via COM. How do I use the TLB file with python? How do I discover the progID of the application so that I can interface with it (this isn't given in the documentation). I'm pretty lost. I have a fair amount of experience with Python, but I am completely new to developing in a Windows environment. Any help would be enormously helpful. I have been reading all the documentation on win32com, but I still have no clue what to do, as no one addresses -- as far as I have seen -- bringing in a TLB file.

Original source