Link to home
Start Free TrialLog in
Avatar of pfhjfr0
pfhjfr0

asked on

OLE Automation and Event Sinks

For reference, here is my environment:

Pentium Pro 200, 64 MB RAM
Windows NT 4.0 Service Pack 3
Internet Explorer 4.0

I have a question about using Event Sinks with the IWebBrowserApp OLE Automation object.

I insert the IWebBrowserApp() object by adding it from the SHDOCVW.DLL in the ClassWizard.  I have the Internet Explorer browser starting just fine, however now I want to trap some of it's events from DWebBrowserEvents (such as NavigateComplete()).

Since I added this as an OLE Automation object, not a control, I am a little unsure how to create the Event Sink.

What I did, following an example, was to create a new class to contain the Event Sink called CWebBrowserEventSink which was derived from CCmdTarget.  I then changed this new class's GUID to match the DWebBrowserEvents UUID that I found using the OLE viewer utility, as per the example.  Once this was done, I proceeded to use ClassWizard to add NavigateComplete as a method on the Automation tab for the CWebBrowserEventSink class.  I added the method with the same syntax as is shown in DWebBrowserEvents.  I then put a small AfxMessageBox() in the NavigateComplete() to verify whether it gets called.

Once this was completed, I went back to my Document class which was the class responsible for starting the IWebBrowserApp, which was a member, using CreateDispatch.  As per the example, I added a new function ConnectWindowEvents() that appears as follows:

NOTE: For sake of space, all debugging code and error checking removed.  All functions have been verified to return success (S_OK), and pointers to be non-null.

BOOL CWwwmonDoc::ConnectWindowEvents() {
IDispatch*                                 pDisp; IConnectionPointContainer* pConnPtCont;

m_pConnPt = NULL;

pDisp = m_pBrowser->m_lpDispatch;      

pDisp->QueryInterface( IID_IConnectionPointContainer,  
(void**)&pConnPtCont );

pConnPtCont->FindConnectionPoint( IID_IWebBrowserEventSink,
&m_pConnPt );

m_pConnPt->Advise(m_Sink.GetInterface( &IID_IUnknown ),
&m_dCookie );

pConnPtCont->Release();

return TRUE;
}


In the code above, m_pBrowser is my IWebBrowserApp object, and m_Sink is my CWebBrowserEventSink object.  IID_IWebBrowserEventSink is the CLSID created in the CWebBrowserEventSink class (which was the same as DWebBrowserEvents).

According to the example that I am following this should have been enough for my Event Sink class to start receiving the NavigateComplete() events during testing.  However, although no errors are encountered on any of the above functions, the AfxMessageBox() in the NavigateComplete() is never displayed.

Does someone have an inkling of what the problem might be, or where would be a good place to start looking?

Thanks,

J. Frank Reeves
John_Reeves@Compuware.com
ASKER CERTIFIED SOLUTION
Avatar of galkin
galkin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
galkin:
Would you please tell me where CONNPTS Microsoft sample is? Thank you.
Avatar of galkin
galkin

http://support.microsoft.com/download/support/mslfiles/Connpts.exe
Look also at Microsoft KB Q152087 "SAMPLE: CONNPTS.EXE Implements Connection Points in MFC Apps" at http://support.microsoft.com/support/kb/articles/q152/0/87.asp