我必须遵循没有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();
}
}
}
我有兴趣获取OperationComplete事件的结果。如何使用System.Reflection实现???
直到现在我有了这个代码:
//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
这可能吗?
谢谢!
UPDATE1:
我得到一个建议,我应该使用ComEventsHelper类,但是我不知道如何将其插入我的代码中。我必须遵循以下没有System.Reflection才能工作的代码:使用COMlib;名称空间测试{类程序{私有静态void kxc_operationComplete(对象结果)...
抱歉,我不能在评论中提出问题。您找到解决方案了吗?