I have to following code that is working without System.Reflection:
Using COMlib;
namespace test
{
class Program
{
private static void kxc_operationComplete(object result)
{
}
static void Main(string[] args)
{
COMclass kxc = new COMclass();
kxc.Init();
kxc.OperationComplete += kxc_operationComplete;
kxc.Operate();
}
}
}
I'm interested to obtain the result of the OperationComplete event. How can be achieved with System.Reflection???
Until now I have this code:
//getting active x type
var COMtype = Type.GetTypeFromCLSID(Guid.Parse(CLSID.objcode), true);
//create object
object COMobj = Activator.CreateInstance(COMtype);
//call init method
COMtype.InvokeMember(“Init”, BindingFlags.InvokeMethod, null, COMobj, null);
//query for event
EventInfo ei = COMtype.GetEvent(“OperationComplete”); //the eventinfo is null
//bind to my class method
MethodInfo method = Type.GetType("test.Program").GetMethod("kxc_operationComplete");
Delegate handler = Delegate.CreateDelegate(eventInfo.EventHandlerType, kxc, method);
//but is not working
Is this possible?
Thank you!
UPDATE1: I got a suggestion that I shoud use ComEventsHelper class, but I don't know how can it be inserted into my code.