c# - Binding an event to a COM Interface -


background: i'm using standard webbrowser control part of system.windows.forms wrapper on internet explorer com control, in order use functionality not exposed wrapper i'm using activexinstance property getter , casting underlying com type (or com interop class visual studio automatically creates when referencing com type ~ interop.shdocvw.dll).

now in order avoid shipping entire interop.shdocvw.dll i'm trying compile salient sections of code want achieve, i'm looking @ decompiled interop.shdocvw.dll , trying replicate sections of code need. odd thing code decompiled ilspy doesn't compile, these event accessors fail compile:

[defaultmember("name"), classinterface((short)0), comsourceinterfaces("shdocvw.dwebbrowserevents2\0shdocvw.dwebbrowserevents\0"), guid("8856f961-340a-11d0-a96b-00c04fd705a2"), typelibtype(34)] [comimport] public class webbrowserclass : iwebbrowser2, webbrowser {     [methodimpl(methodimploptions.internalcall)]     public extern webbrowserclass();      public virtual extern event dwebbrowserevents2_newwindow2eventhandler newwindow2     {         [methodimpl(methodimploptions.internalcall)]         add;         [methodimpl(methodimploptions.internalcall)]         remove;     }      [dispid(210)]     public virtual extern string locationname     {         [dispid(210)]         [methodimpl(methodimploptions.internalcall)]         [return: marshalas(unmanagedtype.bstr)]         get;     } } 

despite event accessor being marked extern compiler reports "an add or remove accessor must have body". if add empty body them comiler reports:

shdocvw.webbrowserclass.newwindow2.add' cannot extern , declare body

so correct way attach event com implementation?

what if left off accessor declarations?

public virtual extern event dwebbrowserevents2_newwindow2eventhandler newwindow2; 

Comments