Click to See Complete Forum and Search --> : Hooking into Internet Explorer


Argletoast
February 9th, 2005, 11:27 AM
I have been set with a task to write a simple internet content filter for internet explorer, something much like Net Nanny and other such programs.

I use the COM interfaces which Internet Explorer makes available, namely IWebBrowser2, and can successfully block and allow websites according to their URL.

My problem is that I would also like to give the option of disabling images from being displayed/downloaded.

After some research into the topic, I see that I must use an ICustomDoc interface, which is obtained by calling QueryInterface on a IHTMLDocument2 interface, requesting an IID_ICustomDoc.

When I do this QueryInterface always returns E_NOINTERFACE.


HRESULT IDispatch::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
LPDISPATCH lpDispatch;

switch(dispIdMember)
{
case DISPID_NAVIGATECOMPLETE2:
lpDispatch = pDispParams->rgvarg[1].pvarVal->pdispVal;
hResult = lpDispatch->QueryInterface(IID_IWebBrowser2, (void**)&Web);
hResult = Web->get_Document(&pHTMLDocument);
hResult = pHTMLDocument->QueryInterface(IID_ICustomDoc, (LPVOID*)&CustomDoc);
// hResult is always E_NOINTERFACE after this call.
break;
}
}


Can anyone suggest a solution here? See whats going wrong?

NoHero
February 9th, 2005, 11:41 AM
If I search MSDN for IID_ICustomDoc I get no results. But when I enter ICustomDoc I get this (http://msdn.microsoft.com/workshop/browser/hosting/reference/ifaces/icustomdoc/icustomdoc.asp).

hankdane
February 9th, 2005, 09:14 PM
As I recall, the place to use ICustomDoc is in your SetClientSite() method.

I can look it up tomorrow.

Argletoast
February 10th, 2005, 03:45 AM
Hi I just want to clarify what the problem is;

I am not using a WebBrowser control inside my own application, I am using COM to attach to all IE instances currently running and any which are spawned which I have accomplished and can already prevent users from navigating to blocked sites.

SetClientSite() is used for when you have embedded a WebBrowser control inside your application, which is not what I am doing.

hankdane
February 10th, 2005, 01:06 PM
I remembered wrong anyway. ICustomDoc is indeed the interface to query directly from MSHTML.

Scott Roberts sample shows the following:


CComPtr<IDispatch> spDoc;
m_spWebBrowser->get_Document(&spDoc);

if (spDoc)
{
CComQIPtr<ICustomDoc, &IID_ICustomDoc> spCustomDoc(spDoc);

if (spCustomDoc)
spCustomDoc->SetUIHandler(this);
}


In other words, he asks for ICustomDoc from the higher-level IDispatch interface, instead of the IHTMLDocument interface. From your sample, it's unclear which interface you are querying on, but from your variable name, it looks like an IHTMLDocument interface. Try querying on the IDispatch.

I have had this problem before; usually with MSHTML, you have to query on IDispatch to get the interface you want, even if the interface in question seems related to a more specific object. This, BTW, is acceptable by the COM contract.