[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1158
  • Last Modified:

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
0
pfhjfr0
Asked:
pfhjfr0
  • 2
1 Solution
 
galkinCommented:
I woud suggest you having a look at CONNPTS Microsoft sample. It demonstates cretaing event sink and handling event fired from another process but you can use its code without any changes in the same process. I suppose your problem is you should use MFC OLE macro DISP_FUNCTION or DISP_FUNCTION_ID between BEGIN_DISPATCH_MAP and END_DISPATCH_MAP in your event sink class to to map event handlers to events. If you are using first macro it automatically calculates event ID based on offset from begining of dispatch map so be sure the order of these macros in dispatch map corresponds to the events IDs order. If you use the second macro you can specify event ID.
0
 
chensuCommented:
galkin:
Would you please tell me where CONNPTS Microsoft sample is? Thank you.
0
 
galkinCommented:
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

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now