Jane Dallaway

Jane Dallaway

Jane Dallaway  //  Data loving developer/leader/product shaper, storyline curator/creator, life-long learner, photographer, dog owner, reader, crafter, gardener and occasional snowboarder

This blog contains all sorts of odds and ends, from event reviews, stuff about my storyline project, bits of craft, through thoughts on learning, to photography stuff, and general inspiration things. It's a bit all over the place with no real theme, but then so am I!

Email: jane @ dallaway.com
Also at:    

C# and handling a COM event

Another new thing to work out - how to handle events raised by COM DLLs. This page at msdn contained the start of the answer (or at least the code samples), but it took quite a bit of experimentation to make it work with my COM DLL (written in Delphi - not sure if that confuses matters at all).

To make it work I had to:
a) create a class level version of the COM component i.e. EventTest1.clsMainClass evt = new EventTest1.clsMainClass();
[Note: example is a VB test event that I've created just to check the logic]
b) set up the event handlers, I found that if I started off with typing the object name, i.e. evt, then on typing . the intellisense would offer me the events as well, and if I selected one of those and type += then the rest of the information was available through intellisense (got to live intellisense)
i.e.
evt.OnComplete += new EventTest1.__clsMain_OnCompleteEventHandler(OnComplete);
evt.OnStart += new EventTest1.__clsMain_OnStartEventHandler(OnStart);

c) create the event handler
i.e.
void OnStart(ref string text)
{
MessageBox.Show (text);
}

void OnComplete(ref string text)
{
MessageBox.Show (text);
}

And that is it, simple really...

0 comments

Leave a comment...