EDN Admin
Well-known member
Hi i am trying to embed browser object inside a window using OLE automation in simple C++
without atl/mfc frameworks.
<pre>class AContainer : public CBaseComObject, public IOleClientSite, public IOleInPlaceFrame, public IOleInPlaceSite, public IOleControlSite
{
};
[/code]
I have declared all the methods of these interfaces and implemented addref release and queryinterface. Right now I have defined other interfaces also but they return E_NOTIMPL. I will implement them when required.
Now when I try to display a simple browser web page inside this container IOleObject:
oVerb method returns E_FAIL instead of S_OK. Can anyone tell me what is the problem with my code. Thanks in advance.
<div style="color:Black;background-color:White; <pre>
AContainer *obj = <span style="color:Blue; new AContainer();
LPCLASSFACTORY pClassFactory;
IOleObject *browserObject;
IWebBrowser2 *webBrowser2;
RECT rect;
pClassFactory = 0;
<span style="color:Blue; if (OleInitialize(NULL) == S_OK)
{
<span style="color:Blue; if (!CoGetClassObject(CLSID_WebBrowser, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, NULL, IID_IClassFactory, (<span style="color:Blue; void **)&pClassFactory) && pClassFactory)
{
<span style="color:Blue; if (!pClassFactory->CreateInstance(0, IID_IOleObject, (<span style="color:Blue; void**)&browserObject))
{
pClassFactory->Release();
<span style="color:Blue; if (!browserObject->SetClientSite(<span style="color:Blue; static_cast<IOleClientSite*>(obj)))
{
browserObject->SetHostNames(L<span style="color:#A31515; "MyName", 0);
HRESULT a = OleSetContainedObject((<span style="color:Blue; struct IUnknown *)browserObject, TRUE); <span style="color:Green; // this returns S_OK
rect.top = 500;
rect.left = 700;
rect.right = 1000;
rect.bottom = 700;
<span style="color:Green; //the handle of the window "hwnd" is passed to my function.The window is already created and visible.
HRESULT b = browserObject->DoVerb(OLEIVERB_SHOW, NULL, <span style="color:Blue; static_cast<IOleClientSite*>(obj), 0, hwnd, &rect); <span style="color:Green; // this returns E_FAIL !!!!!!!!!!
HRESULT c = browserObject->QueryInterface(IID_IWebBrowser2, (<span style="color:Blue; void**)&webBrowser2); <span style="color:Green; // this returns S_OK
..................................................................................
..................................................................................
..................................................................................
}
}
}
[/code]
<hr class="sig OM
View the full article
without atl/mfc frameworks.
<pre>class AContainer : public CBaseComObject, public IOleClientSite, public IOleInPlaceFrame, public IOleInPlaceSite, public IOleControlSite
{
};
[/code]
I have declared all the methods of these interfaces and implemented addref release and queryinterface. Right now I have defined other interfaces also but they return E_NOTIMPL. I will implement them when required.
Now when I try to display a simple browser web page inside this container IOleObject:

<div style="color:Black;background-color:White; <pre>
AContainer *obj = <span style="color:Blue; new AContainer();
LPCLASSFACTORY pClassFactory;
IOleObject *browserObject;
IWebBrowser2 *webBrowser2;
RECT rect;
pClassFactory = 0;
<span style="color:Blue; if (OleInitialize(NULL) == S_OK)
{
<span style="color:Blue; if (!CoGetClassObject(CLSID_WebBrowser, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, NULL, IID_IClassFactory, (<span style="color:Blue; void **)&pClassFactory) && pClassFactory)
{
<span style="color:Blue; if (!pClassFactory->CreateInstance(0, IID_IOleObject, (<span style="color:Blue; void**)&browserObject))
{
pClassFactory->Release();
<span style="color:Blue; if (!browserObject->SetClientSite(<span style="color:Blue; static_cast<IOleClientSite*>(obj)))
{
browserObject->SetHostNames(L<span style="color:#A31515; "MyName", 0);
HRESULT a = OleSetContainedObject((<span style="color:Blue; struct IUnknown *)browserObject, TRUE); <span style="color:Green; // this returns S_OK
rect.top = 500;
rect.left = 700;
rect.right = 1000;
rect.bottom = 700;
<span style="color:Green; //the handle of the window "hwnd" is passed to my function.The window is already created and visible.
HRESULT b = browserObject->DoVerb(OLEIVERB_SHOW, NULL, <span style="color:Blue; static_cast<IOleClientSite*>(obj), 0, hwnd, &rect); <span style="color:Green; // this returns E_FAIL !!!!!!!!!!
HRESULT c = browserObject->QueryInterface(IID_IWebBrowser2, (<span style="color:Blue; void**)&webBrowser2); <span style="color:Green; // this returns S_OK
..................................................................................
..................................................................................
..................................................................................
}
}
}
[/code]
<hr class="sig OM
View the full article