CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2005
    Posts
    2

    Hooking into Internet Explorer

    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.

    Code:
    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?

  2. #2
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: Hooking into Internet Explorer

    If I search MSDN for IID_ICustomDoc I get no results. But when I enter ICustomDoc I get this.
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  3. #3
    Join Date
    Feb 2003
    Location
    California
    Posts
    334

    Re: Hooking into Internet Explorer

    As I recall, the place to use ICustomDoc is in your SetClientSite() method.

    I can look it up tomorrow.
    Henri Hein
    Principal Engineer, Propel
    Do not credit Propel with my views or opinions.

  4. #4
    Join Date
    Feb 2005
    Posts
    2

    Re: Hooking into Internet Explorer

    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.

  5. #5
    Join Date
    Feb 2003
    Location
    California
    Posts
    334

    Re: Hooking into Internet Explorer

    I remembered wrong anyway. ICustomDoc is indeed the interface to query directly from MSHTML.

    Scott Roberts sample shows the following:

    Code:
      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.
    Henri Hein
    Principal Engineer, Propel
    Do not credit Propel with my views or opinions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured