Accessing multiple interfaces in a COM object
Don Dwiggins
dwig at advancedmp.net
Mon May 21 18:17:09 EDT 2001
I have a DLL containing several classes written in VB6 that implement a
common interface (call it iA for present purposes). I want to instantiate
an object of one of those classes, then use methods of iA on it. I've been
totally unsuccessful in this so far.
I've googled the group archives for this, but none of the messages has led
to something that works for me. Also, nothing I've found in the
"Programming on Win32" book has helped.
For example, when I try (based on one of the messages):
o = Dispatch('dll.class1')
o._oleobj_.QueryInterface('IID-string-for-iA',pythoncom.IID_IDispatch)
I get
<PyIDispatch at 0x1391044 with obj at 0x148d2c>
... and I get the same if I reverse the order of the arguments! I've also
tried using pythoncom.IID_IUnknown in place of pythoncom.IID_IDispatch; the
only difference is that the result is a PyIUnknown instead of a PyIDispatch.
After considerable trial and error, I stumbled onto:
mod = gencache.GetModuleForProgID('dll.class1')
mod.class1.coclass_interfaces
which gave me:
[<class win32com.gen_py.some_GUID_string._class1 at xxx>,
<class win32com.gen_py.some_GUID_String._iA at yyy>]
OK, I continued with:
iAc = mod.class1.coclass_interfaces[1]
and sure enough, iAc has the methods I'm interested in. (Can I assume that
the implementations are those of class1?)
Now I can't work out how to get an instance of this class. I tried the
obvious:
iAi = iAc()
and got the following traceback:
File "<interactive input>", line 1, in ?
File "e:\python20\win32com\client\__init__.py", line 312, in __init__
oobj = pythoncom.new(self.CLSID)
com_error: (-2147221164, 'Class not registered', None, None)
I have the feeling that it can't be this difficult, and I'm missing
something somewhere.
Thanks in advance for any help here...
--
Don Dwiggins "Solvitur Ambulando"
Advanced MP Technology
dwig at advancedmp.net
More information about the Python-list
mailing list