Archie14
August 10th, 2007, 05:38 PM
I have C++ code that has to use external assembly. This assembly is a component and it has one event delegate. Let's say this component has following code:
namespace MyNamespace.MyModel
{
public partial class ModelGUI: UserControl
{
public delegate void TestDelegate(int intval, String strval);
public ModelGUI() {...}
public event TestDelegate OnTestDelegate;
...
}
I need to be able to handle events raised from ModelGUI in my C++ class.
My C++ class cannot reference the assembly in the code, so it loads it dynamicaly and uses Reflection to get to the methods. Here is what I do:
System::Windows::Forms::Control ^ control; // points to the instance of ModelGUI
System::Type^ type = control->GetType();
System::Reflection::EventInfo^ eInfo = type->GetEvent("OnTestDelegate");
Here is where my problems start:
eInfo->AddEventHandler(control, <eventhandler>);
The problem is that I cannot figure out how to propertly define event handler in my class and use it to add to event delegate in the external assemby. Note that I cannot directly import the assembly so MyNamespace.MyModel is not visible to my C++ code.
Any help is greatly apreciated
namespace MyNamespace.MyModel
{
public partial class ModelGUI: UserControl
{
public delegate void TestDelegate(int intval, String strval);
public ModelGUI() {...}
public event TestDelegate OnTestDelegate;
...
}
I need to be able to handle events raised from ModelGUI in my C++ class.
My C++ class cannot reference the assembly in the code, so it loads it dynamicaly and uses Reflection to get to the methods. Here is what I do:
System::Windows::Forms::Control ^ control; // points to the instance of ModelGUI
System::Type^ type = control->GetType();
System::Reflection::EventInfo^ eInfo = type->GetEvent("OnTestDelegate");
Here is where my problems start:
eInfo->AddEventHandler(control, <eventhandler>);
The problem is that I cannot figure out how to propertly define event handler in my class and use it to add to event delegate in the external assemby. Note that I cannot directly import the assembly so MyNamespace.MyModel is not visible to my C++ code.
Any help is greatly apreciated