COM Question - QueryInterface?

Stefan Migowsky smigowsky at
Tue Jun 8 08:01:51 EDT 1999


you get the IDispatch interface with this call prtoviding
you have an IUnknown.

>>>import pythoncom
   <PyIUnknown at 0x3bf86a4 with obj at 0x837ab0>
>>>IUnk.QueryInterface(pythoncom.IID_IDispatch)    # Query IDispatch
   <PyIDispatch at 0x3bf4d54 with obj at 0x837ab0>
_IUnknown) # Query IUnkown again
   <PyIUnknown at 0x3bf86a4 with obj at 0x837ab0>

You just have to get hold off at least one interface object.
If you use the wrapper classes generated by makepy you can get the 
interface by using the _oleobj_ attribute e.g:

>>>from win32com.client import Dispatch
>>>drives = Dispatch("AmAccess.Drives")
   <PyIDispatch at XXX with obj at XXX>

Hope this helps


> ----------
> Von: 	Chris Tavares[SMTP:]
> Gesendet: 	Dienstag, 8. Juni 1999 03:17:58
> An: 	python-list at
> Betreff: 	COM Question - QueryInterface?
> I've got a (hopefully easy) question about python's COM support.
> I'm developing a COM object in C++ which implements the COM collection
> idiom - an Item method that returns another object. The code in Python
> I'm using is something like this:
> from win32com.client import Dispatch
> drives = Dispatch("AmAccess.Drives")
> drive = drives.Item("c:")
> dir = drive.Item("some-area")
> On this last line, I get an AttributeError for Item.
> I think I know the reason why - the interface returned from 
> Drives.Item
> isn't a dual, it's an oleautomation compatible vtable interface.
> IDispatch on that object is implemented separately. So, PythonCOM sees
> the VT_UNKNOWN return type and wraps a PYIUnknown object around it. I
> need to be able to do a QueryInterface for IDispatch.
> How do I get Python to do that? There's a PyIID type, but 
> apparently it
> only works for class or progids.  Anyone got any suggestions?
> Thanks for any help,
> -Chris

More information about the Python-list mailing list