Solved

OLE Automation and Event Sinks

Posted on 1998-01-15
3
1,108 Views
Last Modified: 2013-11-25
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
Comment
Question by:pfhjfr0
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
galkin earned 150 total points
ID: 1314192
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
 
LVL 23

Expert Comment

by:chensu
ID: 1314193
galkin:
Would you please tell me where CONNPTS Microsoft sample is? Thank you.
0
 
LVL 7

Expert Comment

by:galkin
ID: 1314194
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now