QueryInterface on IDispatch in Python ...

Peter Sparago psparago at yahoo.com
Mon Oct 25 01:38:50 CEST 2004


I am working with the MSHTML editor control. I used
win32com.client.gencache.EnsureModule on the MSHTML type library to
generate the necessary IDispatch support for all the various
interfaces used by MSHTML.

I have just implemented some of the necessary custom COM
interfaces/gateways to allow me to take control of MSHTML's
right-click menu.

One of the callbacks that MSHTML makes (and I've implemented) is
'ShowContextMenu' (on the IDocHostUIHandler interface). One of the
arguments passed to ShowContextMenu is a generic IDispatch reference
to the current HTML Element - ultimately this is an IHTMLElement
interface reference.

Python understands that this reference passed to 'ShowContextMenu' is
an IDispatch interface but when I do a QueryInterface on this object
to get the IHTMLElement interface (like so:)

element = dispElement.QueryInterface(IID('{3050F1FF-98B5-11CF-BB82-00AA00BDCE0B}'))

I get the following error:

exceptions.TypeError: {There is no interface object registered that
supports this IID}

What am I doing wrong? IHTMLElement *is* defined in the module .py
file that was generated by EnsureModule from the type library,
IHTMLElement is derived from IDispatch. Shouldn't I be able to make
late-bound calls on the generic IDispatch reference?

Any help would be greatly appreciated.



More information about the Python-list mailing list