Saturday, 15 March 2014

How to register for a c# event in unmanaged code using c++/cli -



How to register for a c# event in unmanaged code using c++/cli -

i have event fired c# component , c++ component needs register event , grab event. using c++/cli mediator access other functions of component.though there code available other way round not much other way round.

if have c# class

class="lang-csharp prettyprint-override">public class foo { public event eventhandler myevent; protected virtual void onmyevent(eventargs e) { eventhandler handler = myevent; if (handler != null) { handler(this, e); } } }

and c++/cli class

class="lang-cpp prettyprint-override">public ref struct bar { public: void handler(system::object^ sender, system::eventargs^ e) { } }

then should able add together event listener follows

class="lang-cpp prettyprint-override">foo^ foo = gcnew foo; bar^ bar = gcnew bar; foo->myevent += gcnew eventhandler(bar, &bar::handler);

(untested)

c# c++ c++-cli

No comments:

Post a Comment