Hey pals,
I would like to know how to convert the following code:
__hook(&CSource::MyEvent, pSource, &CReceiver::MyMethod);
To the new managed c++/cli syntax.
Very thanks!
Printable View
Hey pals,
I would like to know how to convert the following code:
__hook(&CSource::MyEvent, pSource, &CReceiver::MyMethod);
To the new managed c++/cli syntax.
Very thanks!
Create new C++/CLI Windows Forms application, add new button to the form and double-click on this button. Windows Form Designer adds this code to Form1.h:
button1 is event source instance.Code:this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
...
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
...
}
Click is event
"this" is event receiver instance
button1_Click is receiver method used as event handler.
Every .NET event has a type, which is defined by some delegate. You can define your own delegate or use existing one, like EventHandler. EventHandler defines the following type: Void (Object^, EventArgs^). Click event has EventHandler type. Event handler function should have the same type.
Thanks for your reply.
But I don“t know how to convert the hook keyword into "+=".
This is too much abstract. Show event definition you want to handle.
I want to handle this event:
delegate void del_Event_Connect(UserConnect^ sender);
event del_Event_Connect^ Event_Connect;
And the hook for it:
__hook(&CSource::Event_Connect, pSource, &CReceiver::MyMethod);
Replace EventSourceInstance and EventReceiverInstance with references to required classes. For example, if subscription is done from Form1, EventReceiverInstance should be "this".Code:EventSourceInstance->Event_Connect += gcnew del_Event_Connect(EventReceiverInstance, &MACHINE_SERVER::Form1::MachineLnk_Connect);
Form1:
void MachineLnk_Connect(UserConnect^ sender)
{
...
}
Now it works!
Very thanks Alex!
hi,
Replace EventSourceInstance and EventReceiverInstance with references to required classes. For example, if subscription is done from Form1, EventReceiverInstance should be "this
regards,
phe9oxis,
http://www.guidebuddha.com