Using MSHTML in Python

Bill Bell bill-bell at bill-bell.hamilton.on.ca
Wed Sep 5 12:00:04 EDT 2001


I'm trying to do the equivalent of the MS 'walkall' example, in 
Python. Which would explain why I would use a statement like the 
following:

MSHTMLIDispatch, MSHTMLIOleObject, MSHTMLIOleControl = 
CoCreateInstanceEx ( 'htmlfile', None, pythoncom . 
CLSCTX_INPROC_SERVER,  None, ( pythoncom . IID_IDispatch, 
axcontrol . IID_IOleObject, axcontrol . IID_IOleControl, ) )

This works, at least in the sense that Python does not complain. (I 
haven't proceeded far enough to verify that MSHTML can 
successfully query my host for the parameters within it must work.)

For those unfamiliar with the CoClass represented by 'htmlfile', it 
offers several Interfaces, including 'IHTMLDocument2'.

However, when I enter the following statement:

MSHTMLIDispatch.QueryInterface ( '{332C4425-26CB-11D0-B483-
00C04FD90119}' )

Python complains, "TypeError: There is no interface object 
registered that supports this IID."

Notes: 

1. In fact, 'IHTMLDocument2' is the '(default)' for the key 
HKEY_CLASSES_ROOT\Interface\{332C4425-26CB-11D0-B483-
00C04FD90119}.

2. CoCreateInstance( CLSID_HTMLDocument, NULL, 
CLSCTX_INPROC_SERVER, IID_IHTMLDocument2, 
(LPVOID*)&g_pApp -> m_pMSHTML ))) from 'walkall' uses these 
constants for the IDs and yields something useful.

Two items I'd appreciate comment about (or, IOW, please ease my 
torment):

1. How to retrieve an artbitrary interface supported by a CoClass 
given some one of the elements in the tuple returned by 
CoCreateInstanceEx.

2. Why doesn't QI cut it for me in this case?

Thanks very much! Ou merci beaucoups!

Bill

Bill Bell, Software Developer




More information about the Python-list mailing list