C# and COM Events
-
Hello all I have a project where I from C# code need to use a COM object and consume events. My COM object can send events by the use of Connectable Objects. In the good old days when C++ and COM were used, I used the IConnectionPoint and Advice. But, is there in .NET a way to consume COM events? I guess it will be in the System.Runtime.InteropServices.
-
Hello all I have a project where I from C# code need to use a COM object and consume events. My COM object can send events by the use of Connectable Objects. In the good old days when C++ and COM were used, I used the IConnectionPoint and Advice. But, is there in .NET a way to consume COM events? I guess it will be in the System.Runtime.InteropServices.
For an early-bound library, you should be able to add event handlers in the same way as any other .NET class. For a late-bound library, you'll want to use the System.Runtime.InteropServices.ComTypes.IConnectionPoint interface[^], which should be familiar to you from C++. :) IIRC, the event sink parameter to the
Advise
method needs to bepublic
,[ComVisible(true)]
, and[ClassInterface(ClassInterfaceType.None)]
.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer