-I want to raise an event whenever method showmessage is called.I want to catch it in C#
code.
-I have written the event for it.
-Is it correct what i have done in Initialize function to associate the delegate with
the function showmessage
-how to use this event in c#
C++/CLI
delegate void progressmsgdisplay(System::String ^ message);
progressmsgdisplay ^ progressMsgNotify;
void Mclass::ShowMessage(System::String ^ message)
{
MessageBox(NULL, m_msg, m_box, NULL);
notify(message);
}
event progressmsgdisplay ^ notify
{
void add(progressmsgdisplay ^ d)
{
progressMsgNotify += d;
}
void remove(progressmsgdisplay ^ d)
{
progressMsgNotify -= d;
}
void raise(System::String ^ msg)
{
progressmsgdisplay ^ tmp = progressMsgNotify;
if (tmp)
{
tmp->Invoke(msg);
}
}
}
//void Mclass::Initialize(System::String ^ strProgressMsg)
//{
// progressMsgNotify=gcnew progressmsgdisplay(this,&Mclass::ShowMessage);
//}
-Mclass is the name of the class in which all of the above is declared and defined
C#
void display(string progressnotification)
{
Console.Out.WriteLine(progressnotification);
}
void initialize()
{
first = new Mclass();
first.notify()+=display;
}
this did the trick
Why can’t you just use EventHandler class in c++/cli and subscribe it in C#
I haven’t tried this yet. But I guess its worth a try.