Python and COM?

Bill Tutt billtut at microsoft.com
Mon Jul 12 02:10:08 EDT 1999


> From: Mark Hammond [mailto:MHammond at skippinet.com.au]
> 
> 
> Karl Putland wrote in message 
> <7m9to7$6qg$82 at rks1.urz.tu-dresden.de>...
> > For a COM server implemented in python, can a type library 
> be generated?
> 
> No, but nearly :-)  Python has the framework and even some
> "proof-of-concept" code, but isnt done.

Err.. Mark means from within Python. That's not to say you can't build a
type library using an IDL file and MIDL.

Here's an example for the Python.Interperter COM server that exists in
win32com\servers\interp.py.

Unfortuantely, Python.Interpreter needs a slight change inorder to write an
IDL file.
Replace the  _public_methods_ line with:
	_dispid_to_func = { 1 : Eval, 2 : Exec }
A matching IDL that should work is attached below:
(As an added bonus, this should actually work)
The only GUID from interp.py is the coclass one. Every other GUID was just
generated.
Hope the below helps.... The MIDL docs in MSDN are certainly less than
useful. :(

// System idl include nonsense
import "oaidl.idl";
import "ocidl.idl";

[
	uuid(EB048AA4-C2D1-11d2-855D-00C04F797DBA),
	helpstring("Python.Interepreter dispinterface")
]
dispinterface IPythonInterpreter
{ properties: 
methods:
	[id(1)] HRESULT Eval([in] BSTR bstrExpression, [out, retval] VARIANT
pvarReturnValue);
	[id(2)] HRESULT Exec([in] BSTR bstrExpression);
};

[
	uuid(60240FE4-C2D2-11d2-855D-00C04F797DBA),
	version(1.0),
	helpstring("Python.Interpreter Type Library")
]
library PythonInterpreterLib
{
	importlib("stdole32.tlb");
	importlib("stdole2.tlb");

	[
		uuid(30BD3490-2632-11cf-AD5B-524153480001),
		helpstring("Python.Interpreter COClass")
	]
	coclass PythonInterpreter
	{
		[default] dispinterface IPythonInterpreter;
	};

}

Bill




More information about the Python-list mailing list