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(IUnkno
{
HRESULT hr;
if(pUnkSite)
{
m_spClientSite=pUnkSite;
m_spClientSite->QueryInter
m_spSP->QueryService(IID_I
// Retrieve and store the IWebBrowser2 pointer
if (m_spWebBrowser2 == NULL)
{
.....
.....
}
}
........
........
}
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<CComSingl eThreadMod el>,
public IDispatchImpl<IEELightCont rol, &IID_IEELightControl, &LIBID_TEST_EE_IECONTROLLi b>,
public CComControl<CEELightContro l>,
public IPersistStreamInitImpl<CEE LightContr ol>,
public IOleControlImpl<CEELightCo ntrol>,
public IOleObjectImpl<CEELightCon trol>,
public IOleInPlaceActiveObjectImp l<CEELight Control>,
public IViewObjectExImpl<CEELight Control>,
public IOleInPlaceObjectWindowles sImpl<CEEL ightContro l>,
public CComCoClass<CEELightContro l, &CLSID_EELightControl>
{
public:
CEELightControl()
{
}
DECLARE_REGISTRY_RESOURCEI D(IDR_EELI GHTCONTROL )
DECLARE_PROTECT_FINAL_CONS TRUCT()
BEGIN_COM_MAP(CEELightCont rol)
COM_INTERFACE_ENTRY(IEELig htControl)
COM_INTERFACE_ENTRY(IDispa tch)
COM_INTERFACE_ENTRY(IViewO bjectEx)
COM_INTERFACE_ENTRY(IViewO bject2)
COM_INTERFACE_ENTRY(IViewO bject)
COM_INTERFACE_ENTRY(IOleIn PlaceObjec tWindowles s)
COM_INTERFACE_ENTRY(IOleIn PlaceObjec t)
COM_INTERFACE_ENTRY2(IOleW indow, IOleInPlaceObjectWindowles s)
COM_INTERFACE_ENTRY(IOleIn PlaceActiv eObject)
COM_INTERFACE_ENTRY(IOleCo ntrol)
COM_INTERFACE_ENTRY(IOleOb ject)
COM_INTERFACE_ENTRY(IPersi stStreamIn it)
COM_INTERFACE_ENTRY2(IPers ist, IPersistStreamInit)
END_COM_MAP()
BEGIN_PROP_MAP(CEELightCon trol)
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_StockColor Page)
END_PROP_MAP()
BEGIN_MSG_MAP(CEELightCont rol)
CHAIN_MSG_MAP(CComControl< CEELightCo ntrol>)
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(VIEWST ATUS_SOLID BKGND | VIEWSTATUS_OPAQUE)
// IEELightControl
public:
HRESULT OnDraw(ATL_DRAWINFO& di)
{
//...
}
STDMETHOD(SetClientSite)(I OleClientS ite *pClientSite)
{
if(pClientSite != NULL) {
HRESULT hRes;
hRes = pClientSite->QueryInterfac e(IID_ISer viceProvid er, (void **)&m_pIServiceProvider);
if(SUCCEEDED(hRes)) {
hRes = m_pIServiceProvider->Query Service(II D_IWebBrow serApp, IID_IWebBrowser2, (void **)&m_pIWebBrowser);
};
};
return IOleObject_SetClientSite(p ClientSite );
}
private:
CComPtr<IServiceProvider> m_pIServiceProvider;
CComPtr<IWebBrowser2> m_pIWebBrowser;
};
#endif //__EELIGHTCONTROL_H_
// 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<CComSingl
public IDispatchImpl<IEELightCont
public CComControl<CEELightContro
public IPersistStreamInitImpl<CEE
public IOleControlImpl<CEELightCo
public IOleObjectImpl<CEELightCon
public IOleInPlaceActiveObjectImp
public IViewObjectExImpl<CEELight
public IOleInPlaceObjectWindowles
public CComCoClass<CEELightContro
{
public:
CEELightControl()
{
}
DECLARE_REGISTRY_RESOURCEI
DECLARE_PROTECT_FINAL_CONS
BEGIN_COM_MAP(CEELightCont
COM_INTERFACE_ENTRY(IEELig
COM_INTERFACE_ENTRY(IDispa
COM_INTERFACE_ENTRY(IViewO
COM_INTERFACE_ENTRY(IViewO
COM_INTERFACE_ENTRY(IViewO
COM_INTERFACE_ENTRY(IOleIn
COM_INTERFACE_ENTRY(IOleIn
COM_INTERFACE_ENTRY2(IOleW
COM_INTERFACE_ENTRY(IOleIn
COM_INTERFACE_ENTRY(IOleCo
COM_INTERFACE_ENTRY(IOleOb
COM_INTERFACE_ENTRY(IPersi
COM_INTERFACE_ENTRY2(IPers
END_COM_MAP()
BEGIN_PROP_MAP(CEELightCon
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_StockColor
END_PROP_MAP()
BEGIN_MSG_MAP(CEELightCont
CHAIN_MSG_MAP(CComControl<
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(VIEWST
// IEELightControl
public:
HRESULT OnDraw(ATL_DRAWINFO& di)
{
//...
}
STDMETHOD(SetClientSite)(I
{
if(pClientSite != NULL) {
HRESULT hRes;
hRes = pClientSite->QueryInterfac
if(SUCCEEDED(hRes)) {
hRes = m_pIServiceProvider->Query
};
};
return IOleObject_SetClientSite(p
}
private:
CComPtr<IServiceProvider> m_pIServiceProvider;
CComPtr<IWebBrowser2> m_pIWebBrowser;
};
#endif //__EELIGHTCONTROL_H_
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
Which error?