I have a Browser Helper Object and want to do some operations on the DOM of a website. I am struggling on one strange thing right now, I hope somebody knows what is happening here. Let's assume I have the following code snippet somewhere in my Browser Helper Object and m_pBrowser holds the current IWebBrowser2:
if (m_pBrowser)
{
CComPtr<IDispatch> pDisp;
if (SUCCEEDED(m_pBrowser->get_Document(&pDisp)) && pDisp)
{
CComQIPtr<IHTMLDOMConstructor> pCtor = pDisp; // NULL
CComQIPtr<IDocumentSelector> pSel = pDisp;
CComQIPtr<IHTMLDOMNode2> pNode2 = pDisp; // NULL
CComQIPtr<IHTMLDOMNode> pNode = pDisp; // NULL
CComQIPtr<IHTMLDocument6> pDoc6 = pDisp;
CComQIPtr<IHTMLDocument2> pDoc2 = pDisp;
CComQIPtr<HTMLDocumentEvents3> pEvt3 = pDisp;
CComQIPtr<HTMLDocumentEvents2> pEvt2 = pDisp; // NULL
CComQIPtr<HTMLDocumentEvents> pEvt = pDisp; // NULL
CComQIPtr<DispHTMLDocument> pDispDoc = pDisp;
}
}
I was expecting to get an instance of the COM class HTMLDocument as a result of the get_Document call, which has the following IDL:
[
uuid(25336920-03F9-11CF-8FD0-00AA00686F13)
]
coclass HTMLDocument {
[default] dispinterface DispHTMLDocument;
[default, source] dispinterface HTMLDocumentEvents;
[source] dispinterface HTMLDocumentEvents2;
[source] dispinterface HTMLDocumentEvents3;
interface IHTMLDocument2;
interface IHTMLDocument3;
interface IHTMLDocument4;
interface IHTMLDocument5;
interface IHTMLDocument6;
interface IHTMLDOMNode;
interface IHTMLDOMNode2;
interface IDocumentSelector;
interface IHTMLDOMConstructor;
};
But for some reason some (not all) of my CComQIPtr assignments are NULL, although HTMLDocument implements all of those interfaces. I especially need to get a reference to the IHTMLDOMNode for the Document. Does anybody know why this is not working as intended?
PS: tested with Visual Studio 2010 on Windows XP with Internet Explorer 8.
Best Sebastian