implement COM interface type library in python -


i have plugin i'm trying create sample application company work for. i'm trying write plugin in python.

the way plugin architecture works plugin needs implement interface defined in provided com type library. com client type library , in end gets registered com server registry , application giving classid late-bound com application.

i'm using pythoncom , win32com , have used makepy.py generate needed python code type libarary can't seem find way create class implements interface type library.

any pointers on appreciated.

thanks

when try run dispatch com object following exeption:

>>> interface = win32com.client.dispatch('{68ac7909-804f-4d6d-861c-8382daa7b029}') traceback (most recent call last): file "<stdin>", line 1, in <module> file "c:\python26\lib\site-packages\win32com\client\__init__.py", line 95, in dispatch dispatch, username = dynamic._getgooddispatchandusername(dispatch,username,clsctx) file "c:\python26\lib\site-packages\win32com\client\dynamic.py", line 108, in _getgooddispatchandusername return (_getgooddispatch(idispatch, clsctx), username) file "c:\python26\lib\site-packages\win32com\client\dynamic.py", line 85, in _getgooddispatch idispatch = pythoncom.cocreateinstance(idispatch, none, clsctx, pythoncom.iid_idispatch) pywintypes.com_error: (-2147221164, 'class not registered', none, none)

you can use win32com.client.dispatch():

object = win32com.client.dispatch("class.name")

this example activestate quick start guide:

>>> import win32com.client >>> w=win32com.client.dispatch("word.application") >>> w.visible=1 >>> w <win32com.gen_py.microsoft word 8.0 object library._application> 

if doesn't work, can use win32com.client.gencache.ensuremodule() make sure you've generated right cache module.

from win32com.client import dispatch win32com.client import gencache  # comes running: makepy.py -i "microsoft excel 14.0 object library" gencache.ensuremodule('{00020813-0000-0000-c000-000000000046}', 0, 1, 7) obj = dispatch("excel.application.14")  # gives <win32com.gen_py.microsoft excel 14.0 object library._application instance ...> print repr(obj) 

the same thing comtypes (simpler , supports custom interfaces)

from comtypes.client import createobject obj = createobject("excel.application") 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -