Setting Up Event Sinks (Windows Embedded CE 6.0)
1/6/2010
After you create the Web browser object as described in Creating a Browser Window, you must register your event sinks. To do this, retrieve a connection point container, on an IConnectionPointContainer interface, for the Web browser object, IWebBrowser2. Use the FindConnectionPoint method on IConnectionPointContainer to retrieve the connection point for the DWebBrowserEvents2 interface. Then, call Advise on the IConnectionPoint interface to register the client's event sink with the connection point. When browser events are fired through Invoke, the registered event sink is called.
The following code example show a method that is defined in the browser class, RegisterBrowserEventSink that establishes a connection between the connection point of the IWebBrowser2 object and the event sink to call.
HRESULT CBrowser::RegisterBrowserEventSink()
{
HRESULT hr = S_FALSE;
IConnectionPointContainer *pCPCont = NULL;
DWebBrowserEvents2 *pEvents = NULL;
if (!_pWB2)
goto Cleanup;
// Get the connection point container for the browser object.
hr = _pWB2->QueryInterface(IID_IConnectionPointContainer, (LPVOID *)&pCPCont);
if (FAILED(hr))
{
hr = S_FALSE;
goto Cleanup;
}
// Look for DWebBrowserEvents2 connection point.
hr = pCPCont->FindConnectionPoint(DIID_DWebBrowserEvents2, &_pCP);
if (FAILED(hr))
{
_pCP = NULL;
goto Cleanup;
}
// Get a DWebBrowserEvents2 pointer from the browser.
hr = QueryInterface(DIID_DWebBrowserEvents2, (LPVOID *)(&pEvents));
if (FAILED(hr))
goto Cleanup;
// Add your event sink to the connectionpoint.
hr = _pCP->Advise(pEvents, &(_dwEventCookie));
if (FAILED(hr))
goto Cleanup;
Cleanup:
if (pCPCont)
pCPCont->Release();
if (pEvents)
pEvents->Release();
return hr;
}
See Also
Concepts
Creating an Internet Browser
Navigating to a Specified URL