Handling COM event from C#?

  • Thread starter Thread starter Grant Schenck
  • Start date Start date
G

Grant Schenck

I have a COM object which throws a simple event.

The event signature is:

void EventReady();

I see that Intellisense shows the events.

I assume I need to code up a member function with the same signature, i.e.:

void MyEventReady()
{
}

This shows code from my simple test program. I'm using my COM object and
can create it and then call it's initialize method. However, I can't figure
out the syntax to wire in my event so that it will be called.

My code is basicly this:
-------------------------------------------------
using STCONTROLLib;
....

namespace STCtlTest
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.ComponentModel.Container components = null;

private Ctl STCtl;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
STCtl = new CtlClass();
STCtl.Initialize("200");

!!! What do I need to code here to hook up my event?
 
Figured it out if anyone is interested:
----------------------------------
void MyEventReady()
{
System.Console.Error.WriteLine("--- EventReady ---");
object objEvent = STCtl.GetNextEvent();
}

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
STCtl = new CtlClass();
STCtl.Initialize("200");

STCtl.EventReady += new _ICtlEvents_EventReadyEventHandler(MyEventReady);
...
 
Back
Top