COM/win32all QueryInterface

Ellers ellers at iinet.net.au
Mon Jan 6 02:54:31 EST 2003


Hi All

Maybe this is easy but I can't figure out how to take a COM IUnknown
object returned by a method call and use QueryInterface to get a
useful object back.

The Demo.MyWorker and Demo.MyConcreteClass are simplifications of a
real type library written in C++ (ATL7, MSStudio7). Everything works
if I do it in C++ but in python I can't do anything useful with the
object I get back.

Some code is below ...


worker = win32com.client.Dispatch( "Demo.MyWorker" )
		
( unk ) = worker.DoWork( \
		"Param1", 
		"Param2", 
		None
		)
		
mod = win32com.client.gencache.GetModuleForTypelib('{MYLBHERE-3D73-4FAE-808D-BA528C308670}',
0, 1, 0)
	
actualObject = unk.QueryInterface( mod.MyConcreteClass.CLSID,
pythoncom.IID_IDispatch )

print "Actual:", actualObject 
# prints something like <PyIDispatch at 0xcd39e4 with obj at 0x1492bc>

# Count is a property on the object - this will fail with:
#    AttributeError: get_Count
#
# I've tried all sorts of variants - GetCount, Count, Count() etc.
# HELP!
actualObject.get_Count


I thought IDispatch would dynamically figure out the Count property
and map get_Count, Count etc?

I'd rather it use a concrete (or pseudo-concrete?) class from the
makepy generated module (makepy works fine with the module BTW), e.g.:

   actualObject = unk.QueryInterface( mod.MyConcreteClass.CLSID,
mod.MyConcreteClass.IID?

   actualObject.Count

 but I can't figure out how to use QueryInterface to return a handle
to the python generated class with prior knowledge of
attributes/methods of the COM class.


Any tips greatly appreciated
Thanks
Ellers




More information about the Python-list mailing list