title: (IE BHO) Get IWebBrowser2 from BeforeNavigate2 event
body: <p>I'm working on an IE BHO, in the BeforeNavigate2 event, how can I get the pointer to IWebBrowser2?  here's my code:</p>
  
  <pre><code>STDMETHODIMP CEventSink::Invoke(DISPID dispIdMember, .....) {
      IWebBrowser2* pSite = 0;
      HRESULT hr;
  
  if(dispIdMember == DISPID_BEFORENAVIGATE2) {
  
      hr = ((IDispatch*)pDispParams-&gt;rgvarg[0].pdispVal)-&gt;QueryInterface(IID_IWebBrowser2, (void**)&amp;pSite);// This line Crashes
  </code></pre>
  
  <p>and the type of param[0] isn't VT_DISPATCH:</p>
  
  <pre><code>if(pDispParams-&gt;rgvarg[0].vt == VT_DISPATCH) {
      msgbox("yes VT_DISPATCH");
  } else {
      msgbox("no.."); // it goes here
  }
  </code></pre>
  
  <p>the <a href="http://msdn.microsoft.com/en-us/library/aa768280%28VS.85%29.aspx" rel="nofollow">MSDN (BeforeNavigate2)</a> says the first parameter is</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>What's wrong with my code ?</p>
  
  <p>Thanks in advance.</p>