By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,315 Members | 1,672 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,315 IT Pros & Developers. It's quick & easy.

QueryInterface on IDispatch in Python ...

P: n/a
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.
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

"Peter Sparago" <ps******@yahoo.com> wrote in message
news:58**************************@posting.google.c om...
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.

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.