(IE BHO) Get IWebBrowser2 from BeforeNavigate2 event

1.1k views Asked by At

I'm working on an IE BHO, in the BeforeNavigate2 event, how can I get the pointer to IWebBrowser2? here's my code:

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

and the type of param[0] isn't VT_DISPATCH:

if(pDispParams->rgvarg[0].vt == VT_DISPATCH) {
    msgbox("yes VT_DISPATCH");
} else {
    msgbox("no.."); // it goes here
}

the MSDN (BeforeNavigate2) 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.

1

There are 1 answers

0
manuell On BEST ANSWER

In Invoke implementation, the arguments are in reverse order.

Use rgvarg[6] for the "first" arguments, and use rgvarg[0] for the last one (the seventh)