473,394 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

QueryInterface on IDispatch in Python ...

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
1 4490
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ian Adams | last post by:
How do I do this in Python? hres = pObj->QueryInterface(IID_MyIntf1, (void **) &piMyIntf1); piMyIntf1->QueryInterface(IID_MyIntf2, (void **) &piMyIntf2); piMyIntf2->SomeMthd(args); Also,...
3
by: Roger That | last post by:
Hi, I am trying to use the function "CreateStreamOnHGlobal" from python code (I need to pass an IStream object to MSXML, like I do in C++ code). I was able to retrieve a pointer on the IStream...
1
by: Dmitry Medvedev | last post by:
Hello, I need to write C# class, that would implement IDispatch interface to be used in ActiveScript. I can't use IReflect interface here due to design issues, I need to handle GetIDsOfNames...
4
by: Phil Coveney | last post by:
Hello, I am implementing a class in C# that wraps an automation server and am stuck on something basic. Using the following code fragment: using System; using System.Runtime.InteropServices;...
0
by: Jim Hubbard | last post by:
How would I implement the IDispatch interface to handle the following in VB.Net <BEGIN> Controlling Download and Execution The WebBrowser Control gives you control over what it downloads,...
1
by: fraca7 | last post by:
Hello. I got a little problem while using pythoncom to automate IE; for some reason, changing the 'selectedIndex' on an instance of IHTMLSelectElement doesn't fire the 'onchange' event (I guess...
3
by: ZhaoYingpu | last post by:
Hello,all I am using win32com to use com. and invoke a method as follows: void AddShapeInfo(LPCTSTR name, LONG type, IDispatch* pDisp); but i pass 0 or None to third parameter and get error info:...
0
by: Brad Johnson | last post by:
I have a C++ application that creates a collection of COM objects. I would like to give the Python interpreter access to these interfaces that were created in C++ land. Stated another way, how...
3
by: Huayang Xia | last post by:
I am trying to use ctypes to call dll functions. One of the functions requires argument "struct IDispatch* ". I do have a PyIDispatch object in python. How can I convert this "PyIDispatch object"...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.