Solved

OLE Automation and Event Sinks

Posted on 1998-01-15
3
1,115 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
dialer.exe 4 58
Build VS2015 project in bat command 3 80
Thin secure Windows 10 5 76
Problem to open Excel file 15 99
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…

867 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

18 Experts available now in Live!

Get 1:1 Help Now