[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 486
  • Last Modified:

Adding C# handler to COM Event (VB6)

Hi everyone,

In my C# project I have a reference to a COM DLL (com interop). From that library I am using an object that has an event which I am trying associate a C# handler to.

Typically in C#, I believe a class would have a delegate you could use to associate method to event but this COM object was intended for VB6.

How do I declare a function (in C#) to handle this object's event?

Thanks in advance.
0
djshorty
Asked:
djshorty
1 Solution
 
athapaCommented:
Add a reference to that COM object and use the object browser to find out the even signature. Then create a function which matches that signature. You can then add a new event sink which points to this new function.

AT
0
 
Daniel Van Der WerkenIndependent ConsultantCommented:
It's simpler than that.  The Runtime Callable Wrapper let's you access the COM events directly.  Just create an Event of that type and use it.  For example:

For example, my C# user control hosts the COM object from ShDocVw.DLL known as the Web Browser Control (IWebBrowser2).  Here's the declaration of the event NavigateComplet2:

this.wbControl.NavigateComplete2 += new AxSHDocVw.DWebBrowserEvents2_NavigateComplete2EventHandler(this.wbControl_NavigateComplete2);

Later, the event function is defined:

private void wbControl_NavigateComplete2(object sender, AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e)

Note, this was all done for me.  All I had to do was double-click on the event in the event properties for the control in the Visual Studio IDE.
0
 
djshortyAuthor Commented:
Thank you Dan7el.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now