[python-win32] Creating a TLB for PythonCOM server

Mariano Reingart reingart at gmail.com
Sat Dec 18 07:24:41 CET 2010


Thanks very much Mark, pippo_server.py was exactly what I needed.

I was missing defining the _typelib_guid_, _typelib_version_,
_com_interfaces_ and then registering the type library with
pythoncom.LoadTypeLib and pythoncom.RegisterTypeLib.

VB doesn't complain now, all seems working fine, and with Ole2View I
can view TypeInfo!

Now I'll make a py2idl generator to automatically convert my classes.

Best regards,

Mariano Reingart
http://www.sistemasagiles.com.ar
http://reingart.blogspot.com



On Fri, Dec 17, 2010 at 10:48 PM, Mark Hammond <skippy.hammond at gmail.com> wrote:
> You should probably check out the "pippo" examples in the win32com\test
> directory for an example of associating the python COM object with the
> typelib.
>
> HTH,
>
> Mark
>
> On 16/12/2010 12:08 PM, Mariano Reingart wrote:
>>
>> Hello
>>
>> I'm trying to create a type library (TLB) using MIDL.EXE for a
>> PythonCom server, but I don't fully understand the brief MSDN
>> ducumentation:
>> http://msdn.microsoft.com/en-us/library/ms690150(v=VS.85).aspx
>>
>> I've been able to create the TLB file, but when using it in VB, I get
>> a Run-time error '13': "Type mismatch" with this code:
>>
>> Dim WSAA As PyAfipWs.WSAA
>> Set WSAA = CreateObject("WSAA")
>> Debug.Print WSAA.Version
>>
>> Testing it with python, makepy.py sucessfully creates the python
>> classes, but it doesn't use them when I do:
>>
>> win32com.client.Dispatch("WSAA")
>>
>> Following is the code in question:
>>
>> Python COM server (stripped version):
>> -------------------------------------
>>
>> class WSAA:
>>     _public_methods_ = ['CreateTRA']
>>     _public_attrs_ =  _readonly_attrs_ = ['Version']
>>     _reg_progid_ = "WSAA"
>>     _reg_clsid_ = "{6268820C-8900-4AE9-8A2D-F0A1EBD4CAC5}"
>>
>>     def __init__(self):
>>         self.Version = "1234"
>>
>>     def CreateTRA(self, service="wsfe", ttl=2400):
>>         return "pass"
>>
>>
>> full code at:
>> http://code.google.com/p/pyafipws/source/browse/pyafipws.py
>>
>>
>> IDL file (stripped version):
>> ----------------------------
>>
>> import "unknwn.idl","oaidl.idl";
>> [
>> uuid(6268820C-8900-4AE9-8A2D-F0A1EBD4CAC5),
>> helpstring("PyAfipWs WSAA interface"),
>> pointer_default(unique),
>> //dual,
>> //oleautomation
>> object
>> ]
>> interface WSAAif : IDispatch //IUnknown
>> {
>>    HRESULT CreateTRA([in] VARIANT service, [in] VARIANT ttl,
>>                    [out, retval] VARIANT * tra);
>>    [propget] HRESULT Version( [out, retval] VARIANT *  sign);
>> };
>>
>> [
>> uuid(a03d1423-b1ec-11d0-8c3a-00c04fc31d2f),
>> version(1.0),
>> helpstring("PyAfipWs Type Library"),
>> ] library PyAfipWs
>> {
>>   importlib("stdole32.tlb");
>>   [
>>   uuid(a03d1422-b1ec-11d0-8c3a-00c04fc31d2f),
>>   helpstring("WSAA Component Class")
>>   ] coclass WSAA
>>     {
>>     [default]interface WSAAif;
>>     }
>> }; //end library def
>>
>>
>>
>> I think I'm missing something and surely I'm doing something wrong
>> (related to IUnknown/IDispatch, dual/oleautomation/object, CLSID,
>> PROGID, etc.). I've tested many combinations and none seems to work.
>>
>>
>> Do you have any advice?
>>
>>
>> Thanks in advance,
>>
>> Mariano Reingart
>> http://www.sistemasagiles.com.ar
>> http://reingart.blogspot.com
>> _______________________________________________
>> python-win32 mailing list
>> python-win32 at python.org
>> http://mail.python.org/mailman/listinfo/python-win32
>
>


More information about the python-win32 mailing list