title: Implement IDispatch::Invoke to be called by a WebBrowser control
body: <p>I'm trying to do what they explain on <a href="http://msdn.microsoft.com/en-us/library/aa770041%28VS.85%29.aspx#Controlling_Download_and_Execution">this</a> article in the <code>Controlling Download and Execution</code> section. I understand the <code>Web Browser Control</code> in that context is not .NET's <code>WebBrowser</code>.</p>
  
  <p>What I'm trying to do is to gain control over what the <code>WebBrowser</code> control downloads. I've been searching for this a lot and always en up in the <code>csEXWB</code>, which has a huge code that I just cannot decipher. </p>
  
  <p>What I've done so far is inherit .NET's <code>WebBrowser</code>, make my inherited class com visible by using the <code>[ComVisible(true)]</code> attribute, add this method to my class (taken from csEXWB):</p>
  
  <pre><code>    [DispId(HTMLDispIDs.DISPID_AMBIENT_DLCONTROL)]
      public int Idispatch_AmbiantDlControl_Invoke_Handler()
      {
          return (int)m_DLCtlFlags;
      }
  </code></pre>
  
  <p>And then call this line of code, where <code>Browser</code> is an instance of my derived class:</p>
  
  <pre><code>IfacesEnumsStructsClasses.IOleControl oleControl = Browser.ActiveXInstance as IfacesEnumsStructsClasses.IOleControl;
  oleControl.OnAmbientPropertyChange(IfacesEnumsStructsClasses.HTMLDispIDs.DISPID_AMBIENT_DLCONTROL);
  </code></pre>
  
  <p>So what I'm hoping is that the <code>oleControl</code> will call my <code>Idispatch_AmbiantDlControl_Invoke_Handler</code> method, which it doesn't. I don't know how, and this is probably what my code is missing, is the <code>oleControl</code> supposed to know on which object to call my <code>Idispatch_AmbiantDlControl_Invoke_Handler</code> method. </p>
  
  <p>What the article I linked above says is <code>it will call your IDispatch::Invoke</code>. What does it mean by <code>your</code>. How do I tell <code>oleControl</code> which object is my <code>IDispatch</code>. Hope I'm making any sense.</p>