TypeLib for Python COM Server?

billtut at microsoft.com.bbs billtut at microsoft.com.bbs
Thu Jul 13 12:30:04 EDT 2000


Don't rely on the 1000 thing. You should specifically declare the dispid's
in the Python class.

Bill

 -----Original Message-----
From: 	Stefan Migowsky [mailto:smigowsky at dspace.de]
Sent:	Thursday, July 13, 2000 1:16 AM
To:	python-list at python.org
Subject:	RE: TypeLib for Python COM Server?

Hi,

there is no general support for typelib generation. But as I know all
propertiues and methods of a Python COM Server start with the dispid 1000.

So writing the IDL File by hand is no problem. Just take the same GUIDs,
Names and the right DispID. So here is a little example :

Python File :

_reg_clsid_ = "{5B24BFC0-EF45-11d3-9B5F-0090274354BC}"
_reg_libname_ = "PythonComInterpreter Typelib"

class PythonComInterpreter:
    """Interface PythonComInterpreter"""

    _public_methods_ = ['Exec','Eval']

    _reg_progid_     = "PythonComInterpreter"
    _reg_verprogid_  = "PythonComInterpreter.1"
    _reg_clsid_      =  '{281AC1E3-E3D2-11D3-9B37-00902722BDE1}'
    _reg_desc_       = "PythonComInterpreterClass"
    _reg_class_spec_ = "PythonComInterpreter.PythonComInterpreter"

 
    def __init__(self):
        self.Dict = {}
        self.Dict["__name__"] = "__main__"
        self.Dict["__builtins__"] = __builtins__
        self.Dict["__doc__"] = ""

    def Exec(self, Cmd):
        exec str(Cmd) in self.Dict

    def Eval(self, Cmd):
        return eval(str(Cmd),self.Dict)


if __name__ == '__main__':
  print 'Registering Python COM Server ...'
  import win32com.Server.register
  win32com.Server.register.UseCommandLine(PythonComInterpreter)
  print 'Registering finished'

######################################################################
Corresponding IDL File:
######################################################################

[
  uuid(5B24BFC0-EF45-11D3-9B5F-0090274354BC),    // _reg_clsid_ Typelib
  version(1.0),
  helpstring("PythonComInterpreter 1.0 Type Library")
]
library Interpreter
{
    importlib("STDOLE2.TLB");

    // Forward declare all types defined in this typelib
    dispinterface IPythonComInterpreter;

    [
      uuid(281AC1E3-E3D2-11D3-9B37-00902722BDE1), // _reg_clsid_
PythonComInterpreter Class
      helpstring("PythonComInterpreter Class")
    ]
    coclass PythonComInterpreter {                // _reg_progid_
PythonComInterpreter Class
        [default] dispinterface IPythonComInterpreter;
    };

    [
      uuid(F8887DE1-EF58-11D3-9B5F-0090274354BC),
      helpstring("IPythonComInterpreter Interface")
    ]
    dispinterface IPythonComInterpreter {
        properties:
        methods:
            [id(1000), helpstring("Executes a Pythonstatement")]
            VARIANT Exec([in] BSTR cmd);
            [id(1001), helpstring("Evals a Pythonstatement")]
            VARIANT Eval([in] BSTR cmd);
    };
};


	Stefan


>-----Original Message-----
>From: mlp at amrose.dk [mailto:mlp at amrose.dk]
>Sent: Wednesday, July 12, 2000 1:37 PM
>To: python-list at python.org
>Subject: TypeLib for Python COM Server?
>
>
>hi all.
>
>i'm in a situation where i'd like to have a typelib for a python com
>server, for use in a c++ client.
>
>i tried to just use midl on an idl i made to reflect the interface of
>the python server.  this didn't work out, since when compiling the
>client code the tlb file is not recognized.
>
>my question: is there an automatic, easy, or standard, way to produce a
>typelibrary for a com server implemented in python?  if not, is it
>possible at all?  if so, could anybody help me with the details?  a
>complete example would be splendid!
>
>python rules!
>'gards,
>morten lind petersen, denmark
>
>
>Sent via Deja.com http://www.deja.com/
>Before you buy.
>--
>http://www.python.org/mailman/listinfo/python-list
>

--
http://www.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list