Two COM Questions: QueryInterface, and Callback Inheritance

Mark Hammond MarkH at ActiveState.com
Tue Jul 25 20:38:17 EDT 2000


> QUESTION ONE:
> How to QueryInterface for a new dispatch interface?

You just perform the QI - but on the "_oleobj_" object.  ie:

> >>>    import win32com.client
> >>>    d = Dispatch("MyCoolThing.App")
> >>>    s = d.GetOtherThing()

You need to do something like:
>>> s = d.GetOtherThing()
>>> other_s = s._oleobj_.QueryInterface("{new_iid}")
>>> s = Dispatch(other_s) # Turn it back into a useful object.

> QUESTION TWO:
> How to subclass a class based on Dispatch?  Can it work at all?

You don't want to "subclass" - you want to implement an interface.

Basically, you want to create a COM server object, but _not_ have it
registered.

I'm afraid I dont have the time to answer this in detail - you can either
try and big up old posts of mine (but Deja sucks these days), or buy my
book, or beg someone with my book to outline the steps and provide some
code...

http://starship.python.net/crew/mhammond/ppw32 is where you can find the
book samples - code that demonstrates this is buried somewhere in there in
the "Advanced COM" chapter.

Mark.






More information about the Python-list mailing list