Solved

OLE Automation and Event Sinks

Posted on 1998-01-15
3
1,129 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
In this post we will learn different types of Android Layout and some basics of an Android App.
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…

734 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