So, I have this legacy type app I am trying to understand and maintain and need some help. I have not dabbled much into Remoting but this solution appears to be using 3rd party COM components.
The documentation is reasonable but does not talk much about .NET and how to attach event handlers. Instead it documents (and is used in the solution) about how to create an instance of the object via Activator.CreateInstance.
so currently it is doing this:
mainObj = Activator.CreateInstance(Type.GetTypeFromProgID("xxxRemote.clsxxxJob"));
that's fine.
But I want to attach an event handler to listen to a specific event on that instantiated object created by the Activator.
The documentation gives me the events exposed but no examples on how to go about wiring them up when using this approach.
anyone have any ideas on how to wire up events when using COM like this?
it should be through normal reflection.
There's a guide in msdn like http://msdn.microsoft.com/en-us/library/ms228976(v=vs.110).aspx
The problem is that to define the methods that will be hooked to the events, you won't have the types defined and will have to do some IL emmiting black magic to build the methods in runtime. It's an interesting problem.
I'm sending an example of the "normal" way opening an ADO connection through COM (just to have something that will call an event handler). Then, I have another example of doing this, the hard way.
Sorry by the mess in the code, but it is just a sample.
}