QueryInterface on IDispatch in Python ...

P

Peter Sparago

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.
 
R

Roger Upole

You should be able to use Dispatch to get the desired interface,
something like this:
win32com.client.Dispatch(element, None,
IID('{3050F1FF-98B5-11CF-BB82-00AA00BDCE0B}')
hth
Roger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top