Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>After some research, I learned that these COM connection points (event handlers) are specified with <code>DispId(0)</code>. Callback functions are represented by instances of classes like:</p> <pre><code>// These attributes may be optional, depending on the project configuration. [ComVisible(true)] [ClassInterface(ClassInterfaceType.AutoDispatch)] public class EventListener { [DispId(0)] // The "target" parameter is an implementation detail. public void NameDoesNotMatter(object target, IDOMEvent evt) { ... } } </code></pre> <p>Since <code>DispId(0)</code> specifies the default method to invoke, the actual name of the method doesn't matter. However, the method parameters certainly do matter. For example, <code>IHTMLElement.onclick</code> must be assigned a callback with no arguments, while <code>IHTMLElement2.attachEvent</code> takes a callback with one parameter of type <code>IHTMLEventObj</code> (or <code>IHTMLEventObj2</code>, ..., <code>6</code> , or even just <code>object</code>).</p> <p>In summary, COM <code>IDispatch</code> callbacks can be implemented in C# using a COM-visible class with a method that accepts the correct arguments and is annotated with <code>[DispId(0)]</code>.</p> <hr> <p>Despite all of this, solutions that avoid the W3C DOM Events API may be more appropriate, as IE9 DOM objects do not support this method when the browser is using a lower document mode for compatibility. For example, an extension that uses <code>addEventListener</code> will fail on a page like Bing, which is rendered in IE7 mode.</p> <p>It also doesn't seem possible to set the document mode used by an <code>IWebBrowser2</code> instance aside from manually doing it through the F12 developer tools.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload