[python-win32] COM server AddIn
Johannes Brunen
jbrunen at datasolid.de
Mon Jul 4 11:11:03 CEST 2005
Hi,
I have a problem implementing a simple COM server AddIn which should satisfy a special COM interface
provided by an application I'm using.
The server application: CADdy.exe => type library CADdy.tlb
The AddIn interface of CADdy.tlb: ICADdyAddIn
From
gencache.EnsureModule('{9C3BB401-114D-11D4-AC72-00105A4925FC}', 0, 1, 2, bForDemand=True) # CADdy.tlb
I got
class ICADdyAddIn(DispatchBaseClass):
"""ICADdyAddIn Interface"""
CLSID = IID('{14F65AE1-4671-11D4-8B1A-00105A49278B}')
coclass_clsid = None
def Exit(self):
"""method Exit"""
return self._oleobj_.InvokeTypes(2, LCID, 1, (24, 0), (),)
def Init(self, theCADdy=defaultNamedNotOptArg):
"""method Init"""
return self._oleobj_.InvokeTypes(1, LCID, 1, (24, 0), ((9, 1),),theCADdy
)
_prop_map_get_ = {
"CLSID": (3, 2, (8, 0), (), "CLSID", None),
"Description": (5, 2, (8, 0), (), "Description", None),
"ProgId": (4, 2, (8, 0), (), "ProgId", None),
}
_prop_map_put_ = {
}
My AddIn COM server Addin.py:
##
## Addin1.py - A very simple CADdy AddIn COM server
##
from win32com import universal
from win32com.client import gencache
import pythoncom
import sys
gencache.EnsureModule('{9C3BB401-114D-11D4-AC72-00105A4925FC}', 0, 1, 2, bForDemand=True) # CADdy.tlb
universal.RegisterInterfaces('{9C3BB401-114D-11D4-AC72-00105A4925FC}', 0, 1, 2, ['ICADdyAddIn'])
class AddIn1:
_com_interfaces_ = ['ICADdyAddIn']
_public_methods_ = []
_reg_clsctx_ = pythoncom.CLSCTX_INPROC_SERVER
_reg_clsid_ = "{AB6C657A-2C26-4BD0-ABB8-D777BC91F199}" # From pythoncom.CreateGuid()
_reg_progid_ = "CADdyAddIn.PythonTest1"
_reg_policy_spec_ = "win32com.server.policy.EventHandlerPolicy"
def __init__(self):
self.appHostApp = None
def Init(self, theCADdy):
"""method Init"""
self.appHostApp = theCADdy
def Exit(self):
"""method Exit"""
self.appHostApp = None
def getCLSID(self):
return _reg_clsid_
def getProgId(self):
return _reg_progid_
def getDescription(self):
return "CADdy++ CADdyAddIn.PythonTest1"
if __name__ == '__main__':
import win32com.server.register
win32com.server.register.UseCommandLine(AddIn1)
This won't work! I can't start this COM server from my application.
First some questions: Do I have to write _public_methods_ = ['Init', 'Exit'] in order to satisfy the required interface ICADdyAddIn?
How do I handle the properties from ICADdyAddIn
_prop_map_get_ = {
"CLSID": (3, 2, (8, 0), (), "CLSID", None),
"Description": (5, 2, (8, 0), (), "Description", None),
"ProgId": (4, 2, (8, 0), (), "ProgId", None),
}
correctly? Do have to use _public_attrs_ and if so how do I use it correctly? I used the methods getCLSID, getProgId and getDescription
just to give it a try but they seem to be totaly wrong.
I used the excelAddIn.py demo as a start. However, is this the recommended way for writing a COM server addin?
I have to mention that I'm quite new to Python as well as to PythonCOM. So my questions may be quite naive,
but I would very much appreciate some help for this topic.
With best regards
Johannes
More information about the Python-win32
mailing list