Finally, a good friend (Nanda) was able to help with this, and got the code below WORKING! This is how to get IWebBrowser2
from IHTMLDocument2
. Pasting code below for anyone who may need this. I had a very tough week wrestling with this, don't want anyone else to go through the same. :-)
CComQIPtr<IOleObject> spOleObject; // IOleObject
CComQIPtr<IOleClientSite> spOleClientSite; // IOleClientSite
CComQIPtr<IServiceProvider> spServiceProvider; // IServiceProvider
...
... // Code here as per How to get IHTMLDocument2 from a HWND[^]
...
HRESULT hRes = spHTMLDoc2->QueryInterface(IID_IOleObject, reinterpret_cast<void **>(&spOleObject));
if (SUCCEEDED(hRes))
{
hRes = spOleObject->GetClientSite(&spOleClientSite);
if(SUCCEEDED(hRes))
{
hRes = spOleClientSite->QueryInterface(IID_IServiceProvider, reinterpret_cast<void **>(&spServiceProvider));
if(SUCCEEDED(hRes))
{
hRes = spServiceProvider->QueryService(SID_SWebBrowserApp,IID_IWebBrowser2, reinterpret_cast<void **>(&spWebBrowser));
}
if(SUCCEEDED(hRes))
{
BSTR oURL;
oURL = SysAllocString(L"http://www.google.com");
VARIANT var;
var.vt = VT_EMPTY;
spWebBrowser->Navigate((BSTR)oURL, &var, &var, &var, &var);
SysFreeString(oURL);
}
}
}
Thanks a ton Nanda! :cool:
* Blood donation is the superior'est form of donation, it can save lives. Celebrate special occasions, like your birthdays, by donating blood. *