Search code examples
mshtmliwebbrowser2quit

IWebBrowser2 Quit method fails with a E_FAIL result


I am hosting the web browser control in my own window. Here are the pertinent steps:

CoGetClassObject(CLSID_WebBrowser, 
                 CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, 
                 NULL, IID_IClassFactory, (void **)&pClassFactory);

pClassFactory->CreateInstance(0, IID_IOleObject, (void **)&pObject);

pClassFactory->Release(); 

pObject->SetClientSite((IOleClientSite *)impl)
OleSetContainedObject((struct IUnknown *)pObject, true)
pObject->DoVerb(OLEIVERB_SHOW, NULL, (IOleClientSite *)impl, 0, hHpsWnd, &rect);

pWB->put_Visible(VARIANT_FALSE);

hr=pWB->Quit();

At the last statement above the hr return value is E_FAIL. The end result of this failure in my code is leaking of a bunch of resources. What am I doing incorrectly?


Solution

  • Reading the documenation here it states the WebBrowser object (i.e. CLSID_WebBrowser) returns an error from the Quit method because it does not make sense in context. The Quit method will quit the out of process version of IE which also uses the same interface to communicate.

    Only thing I can suggest is double check you are releasing all COM object relating to the browser.