Link to home
Start Free TrialLog in
Avatar of reddyrajareddy
reddyrajareddy

asked on

How can we get IWebBrowser2 interface pointer of a ShowModalDialog?


Internet Explorer is loading my activeX and calling SetSite() for popups opened by ShowModalDialog. When I query for IWebBrowser2 interface pointer I am getting error.

I tried to get IHTMLDocuent interface pointer by using Microsoft Active Accessibilty Technique.
(http://support.microsoft.com/default.aspx?kbid=249232). Problem is, IE is creating Internet Explorer_Server window after returning form SetSite method().

So please let me know how can I get IWebBrowser2 (or IHTMLDocument2) interface pointer. This is the sample code what I wrote to get interface pointer.


 CComQIPtr<IOleClientSite, &IID_IOleClientSite> m_spClientSite;
 CComPtr<IWebBrowser2> m_spWebBrowser2;
 CComPtr<IServiceProvider> m_spSP;


STDMETHODIMP CMyTestObj::SetSite(IUnknown *pUnkSite)
{
 HRESULT hr;
 if(pUnkSite)
 {
  m_spClientSite=pUnkSite;
  m_spClientSite->QueryInterface(IID_IServiceProvider,(void **)&m_spSP);
  m_spSP->QueryService(IID_IWebBrowserApp, IID_IWebBrowser2,(void **)&m_spWebBrowser2);
   
  // Retrieve and store the IWebBrowser2 pointer
  if (m_spWebBrowser2 == NULL)
  {
   .....
   .....
  }
 }

 ........
 ........
}


Avatar of jkr
jkr
Flag of Germany image

>>When I query for IWebBrowser2 interface pointer I am getting error.

Which error?
Avatar of reddyrajareddy
reddyrajareddy

ASKER


E_NOINTERFACE
"The service exists, but the interface requested does not exist on that service."
This is code I have used literally & it worked (IWebBrowser2 interface pointer was not NULL) when ActiveX control is created on html page in IE.

// EELightControl.h : Declaration of the CEELightControl

#ifndef __EELIGHTCONTROL_H_
#define __EELIGHTCONTROL_H_

#include "resource.h"       // main symbols
#include <atlctl.h>


/////////////////////////////////////////////////////////////////////////////
// CEELightControl
class ATL_NO_VTABLE CEELightControl :
      public CComObjectRootEx<CComSingleThreadModel>,
      public IDispatchImpl<IEELightControl, &IID_IEELightControl, &LIBID_TEST_EE_IECONTROLLib>,
      public CComControl<CEELightControl>,
      public IPersistStreamInitImpl<CEELightControl>,
      public IOleControlImpl<CEELightControl>,
      public IOleObjectImpl<CEELightControl>,
      public IOleInPlaceActiveObjectImpl<CEELightControl>,
      public IViewObjectExImpl<CEELightControl>,
      public IOleInPlaceObjectWindowlessImpl<CEELightControl>,
      public CComCoClass<CEELightControl, &CLSID_EELightControl>
{
public:
      CEELightControl()
      {
      }

DECLARE_REGISTRY_RESOURCEID(IDR_EELIGHTCONTROL)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CEELightControl)
      COM_INTERFACE_ENTRY(IEELightControl)
      COM_INTERFACE_ENTRY(IDispatch)
      COM_INTERFACE_ENTRY(IViewObjectEx)
      COM_INTERFACE_ENTRY(IViewObject2)
      COM_INTERFACE_ENTRY(IViewObject)
      COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless)
      COM_INTERFACE_ENTRY(IOleInPlaceObject)
      COM_INTERFACE_ENTRY2(IOleWindow, IOleInPlaceObjectWindowless)
      COM_INTERFACE_ENTRY(IOleInPlaceActiveObject)
      COM_INTERFACE_ENTRY(IOleControl)
      COM_INTERFACE_ENTRY(IOleObject)
      COM_INTERFACE_ENTRY(IPersistStreamInit)
      COM_INTERFACE_ENTRY2(IPersist, IPersistStreamInit)
END_COM_MAP()

BEGIN_PROP_MAP(CEELightControl)
      PROP_DATA_ENTRY("_cx", m_sizeExtent.cx, VT_UI4)
      PROP_DATA_ENTRY("_cy", m_sizeExtent.cy, VT_UI4)
      // Example entries
      // PROP_ENTRY("Property Description", dispid, clsid)
      // PROP_PAGE(CLSID_StockColorPage)
END_PROP_MAP()

BEGIN_MSG_MAP(CEELightControl)
      CHAIN_MSG_MAP(CComControl<CEELightControl>)
      DEFAULT_REFLECTION_HANDLER()
END_MSG_MAP()
// Handler prototypes:
//  LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
//  LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
//  LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);



// IViewObjectEx
      DECLARE_VIEW_STATUS(VIEWSTATUS_SOLIDBKGND | VIEWSTATUS_OPAQUE)

// IEELightControl
public:

      HRESULT OnDraw(ATL_DRAWINFO& di)
      {
//...
      }

      STDMETHOD(SetClientSite)(IOleClientSite *pClientSite)
      {
            if(pClientSite != NULL) {
                  HRESULT hRes;

                  hRes = pClientSite->QueryInterface(IID_IServiceProvider, (void **)&m_pIServiceProvider);

                  if(SUCCEEDED(hRes)) {
                        hRes = m_pIServiceProvider->QueryService(IID_IWebBrowserApp, IID_IWebBrowser2, (void **)&m_pIWebBrowser);
                  };
            };

            return IOleObject_SetClientSite(pClientSite);
      }
private:
      CComPtr<IServiceProvider> m_pIServiceProvider;
      CComPtr<IWebBrowser2> m_pIWebBrowser;
};

#endif //__EELIGHTCONTROL_H_

I tested above code. Let me explain the result.

I kept the object tag in a .html page with appropriate clsid. When I open the page in main browser, I could get IWebBrowser2 interface pointer.

If I open the page with ShowModalDialog( ), QueryService is returning E_NOINTERFACE.

Are you sure that you are getting IWebBrowser2 interface pointer in ShowModalDialog case?
ASKER CERTIFIED SOLUTION
Avatar of Dariusz Dziara
Dariusz Dziara
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

Hi mrblue,

Thanks for your reply.

I cound't test the code in your last post. I think you are getting an interface pointer that provides access to the scripting object. I will try to access the document object model by using scripting object.

But I solved the problem by using an other way.

I kept an Iframe in the HTML loaded by ShowModalDialog. The src of Iframe is another html page which has only <object> tab. Now I am able to retrive IWebBrowser2 interface pointer.