win32com interface implementation example

K

kenchanningphd

Can someone post or point me to a fairly simple example where
a COM interface (other than the standard ones already exposed by the
win32com library) is implemented in python. I fear I am doing it
incorrectly.

Here is my example:
Suppose there is a COM interface "FOO" loaded in the windows registry
that has one method: add
Also suppose that COM object BAR has a method that expects a COM object
that implements FOO
-----------------------------------
import pythoncom
guid = pythoncom.CreateGuid()
class MyImplementation:
_public_methods_ = ["add"]
_reg_clsid_ = guid
_reg_progid_ = "MyImplementation"
_com_interfaces_ = [IID('{ID OF THE FOO INTERFACE}')]

def add(self,a,b):
print a + b


import win32com
win32com.server.register.UseCommandLine(MyImplementation)
MI = win32com.Dispatch("MyImplementation")
bar = win32com.Dispatch("BAR")
bar.somemethod(MI)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top