Two COM Questions: QueryInterface, and Callback Inheritance

Mark Hammond MarkH at ActiveState.com
Wed Jul 26 20:47:36 EDT 2000


[Posted and mailed]

> Okay, I didn't give enough detail, and I appreciate all your help.

And I gave misleading information :-(

The short-story is that you must pass _2_ params to QI in this example.
The first is the IID you are querying, and the second is the IID you want
returned.  Usually these are identical, but in these cases they are not.
The second param you want to pass is pythoncom.IID_IDispatch.

eg:
geo2._oleobj_.QueryInterface(
    '{EB5093C7-56F9-11D2-88CE-00C04FA35859}',
    pythoncom.IID_IDispatch
)

The long answer is that an alternative technique may make life easier for
you.  This alternative is to use the gencache module, and work with the
makepy generated module directly.

eg:

>>> import win32com.client.gencache
>>> mod =
win32com.client.gencache.GetModuleForProgID("DirectAnimation.DirectAnimati
onWindowedIntegratedMediaControl.1")
>>> mod
<module 'win32com.gen_py.34F681D0-3640-11CF-9294-00AA00B8A733x0x1x0' from
'c:\temp\gen_py\34F681D0-3640-11CF-9294-00AA00B8A733x0x1x0.pyc'>
>>> ob = mod.DAViewerControl()
>>> ob
<win32com.gen_py.DirectAnimation Library.DAViewerControl>
>>> # do something to get the geometry object, as per your example
>>> geometry = mod.IDA2Geometry(geo_ob)

Note the last line - we are attempting to get a geometry object from an
existing COM object.  Looking at the __init__ function of
win32com.client.DispatchBaseClass(), you should see that it is doing
exactly what my "short answer" above is - attempting the QI with 2 params.

This code was added to __init__ fairly recently exactly for this reason -
to make it a little simpler to work with Dispatch objects that support
multiple IDispatch based interfaces.

Mark.






More information about the Python-list mailing list