Hi all,
I'm not sure whether I should have posted it here. But couldn't find a forum where COM problems were discussed in such detail. I am programming in plain-C in VC++ 6.0 IDE. I'm trying to write a C program which will capture the BeforeNavigate2 event of an existing Internet Explorer. I'm just 5 days old to COM and after much of searching on the Web I came up with code which can connect to running instance of an IE (the code was all published on the Web; understanding it and making it compatible to C main() function style took the time).
My problem is how do I get the event BeforeNavigate2 captured by my application. My code till now is something like this
IWebBrowser2 * pWebBrowser = NULL;

hr = spDisp.QueryInterface (IID_IWebBrowser2, & pWebBrowser);

if (pWebBrowser != NULL)
IDispatch* pHtmlDocDispatch = NULL;
IHTMLDocument2 * pHtmlDoc = NULL;
hr = pWebBrowser->get_Document (&pHtmlDocDispatch);

if (SUCCEEDED (hr) && (pHtmlDocDispatch != NULL))
hr = pHtmlDocDispatch->QueryInterface(IID_IHTMLDocument2,(void**)&pHtmlDoc);
if (SUCCEEDED (hr) && (pHtmlDoc != NULL))

if (SUCCEEDED(spSHWinds->QueryInterface(IID_IConnectionPointContainer,(LPVOID*)&pConnPtCont)))
ASSERT(pConnPtCont != NULL);
DWORD dwCookie = 0;
IUnknown* lpUnkn;
if (SUCCEEDED(pConnPtCont->FindConnectionPoint(__uuidof(SHDocVw::DShellWindowsEvents), &pConnPt)))
ASSERT(pConnPt != NULL);
pConnPt->[color=red]Advise(GetIDispatch[/color](FALSE), &dwCookie);
printf("Connection point container failed.\n");

The problem is with the Advise method. I get an error "Undeclared Identifier" with the GetIDispatch.
Any links or lead on this will be helpful as well.
Thanks all.
Posted on 2005-01-24 00:57:47 by rjv_rnjn
I'm not fully sure, but you use "GetIDispatch(FALSE)" as the parameter for Advise, you should have here an own implementation of an IAdvise object / interface.

Just setup an empty IAdvise object and check out, which methods will be called by the OS, and fill them with some content, or checkout the ASM tutorials, there will we probably a sample implementation of such an interface.
Posted on 2005-01-31 04:54:44 by beaster
beaster is right, the first parameter to Advise must be a COM object that *your* application is to implement. It need not support IAdvise, though, the QueryInterface method of this interface should accept IUnknown, IDispatch and DShellWindowsEvents (shouldnt it be DWebBrowserEvents?). All events will be reported to the Invoke method of this interface.
Posted on 2005-01-31 10:55:05 by japheth
Thanks guys for your tips. I'll try to implement that. My initial concern was how to override the Invoke function of the DWebBrowserEvents. Got to know that it can be done through structures in C by making a structure with vtable entries as its members and then storing the address of my implemented function in those vtable members.

Will post the solution once I'm through with it.
Thanks again.
Posted on 2005-02-01 23:06:23 by rjv_rnjn