By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,987 Members | 1,607 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,987 IT Pros & Developers. It's quick & easy.

AddEventHandler c++/cli question

P: 1
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
Aug 10 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.