(IE BHO) Get IWebBrowser2 from BeforeNavigate2 event

Dec 9, 2013 at 8:26am
I'm working on an IE BHO, in the BeforeNavigate2 event, how can I get the pointer to IWebBrowser2? here's my code:
1
2
3
4
5
6
7
STDMETHODIMP CEventSink::Invoke(DISPID dispIdMember, .....) {
    IWebBrowser2* pSite = 0;
    HRESULT hr;

if(dispIdMember == DISPID_BEFORENAVIGATE2) {

    hr = ((IDispatch*)pDispParams->rgvarg[0].pdispVal)->QueryInterface(IID_IWebBrowser2, (void**)&pSite);// This line Crashes 

the MSDN http://msdn.microsoft.com/en-us/library/aa768280%28VS.85%29.aspx
says the first parameter is
A pointer to the IDispatch interface for the WebBrowser object that represents the window or frame. This interface can be queried for the IWebBrowser2 interface.


What's wrong with my code ?

Thanks in advance.
Dec 14, 2013 at 4:56pm
You shouldn't need the IDispatch* cast as that's the type of pdispVal (casts should not be used unnecessarily.)

Is the vt (VARTYPE) member of rgvarg[0] set to VT_DISPATCH as you expect? (pdispVal is only valid if this is the case.)

What hr value is QueryInterface returning? Or is your code blowing up??

Andy
Last edited on Dec 14, 2013 at 5:14pm
Dec 15, 2013 at 5:10am
Thanks, it turns out that the parameters are in the reverse order, so rgvarg[6] is the correct arg.
Topic archived. No new replies allowed.