Thursday, 12 September 2013

Catch COM events?

Catch COM events?

Trying to wire up a COM library that we use to talk to things in .NET. In
VB6, the same thing could of been done by just doing
private withevents _monitor as new Application
and then I could just do
monitor_onPrintText(byval msg as string, byval draw as boolean)
and it would work, whenever something was printed on the monitor side, it
would fire the event and send us stuff back. However, in C#, I'm able to
execute the commands, but I don't get the normal things back like I do in
VB6. I'm just curious as to what I'm doing wrong, as everything I've read
says
_monitor.onPrintText += onPrintText;
should work, but I'm not able to get the event to fire.
I've tried this codeproject project, and MSDN, and a bunch of other
resources out there, but I can't get this damn thing to work! Here is the
basics of the code, I've added all three "interfaces" created by importing
the com object, and I've tried all kinds of different combinations. My
"startup" script should return a true, and fire the onPrintText event a
few times with some messages along the way (or at least thats what it's
doing in VB6...)
using System;
using monitorLib;
public class MyClass
{
private Application _monitor;
public MyClass()
{
_monitor = new Application;
_monitor.onPrintText += onPrintText;
_monitor.evaluate("run(\"startup\");");
}
public dynamic Evaluate(string pScript)
{
return _monitor.evaluate(pScript);
}
public void PrintText(string p_text, bool p_drawNow)
{
debug.print(p_text);
}
}

No comments:

Post a Comment