Saturday 15 February 2014

c++ cli - Pass unmanaged member function pointer to be used by wrapper to connect it to the signal in c++/cli -


I've compiled event handling in Boost :: Signal and Boost :: My managed C ++ file. Link sent to:

In addition to that I have created the function pointer in my original C ++ file which is my boost:: signaling Is given as an event-holder in the managed code. The code for the function that has been passed as function pointer in my original C ++

  std :: string NativeCplus :: AddFunctionPointer (std :: string message) {return message; }   

and was passed as promoting the above function: In the function object, below another function as NameChangeEvent ():

  void NativeCplus :: NameChangeEvent () {UnmanagedNameEvent * UnmanagedNameEvent = New UnmanagedNameEvent (); Promotion :: Function & lt; Std :: string (std :: string) & gt; F; F = std :: bind1st (std :: mem_fun (& amp; AlgebraAPI :: AddFunctionPointer), this); // FunctionPointer std :: string name = "abcd"; UnmanagedNameEvent-> AddEvent (f, name); }   

In the above code, I have taken the Promotion :: Function and the Function Pointer has been converted to that Promotion :: Function (F). (I'm saying this is correct?) Then AddEvent (f, name) and have been passed to Boost :: Function (F) . AddEvent (f, name) has been implemented in my managed C ++ code file. Below is my managed C ++ code which is being referred to native C ++ project:

// my C ++ / CLI wrapper.cpp

  declspec (Dllexport) void UnmanagedNameEvent: AddEvent (boost :: function & lt; std :: string (std :: string) & gt; f, std :: string name) {UnmanagedNameEvent * unmanagedNameEvent = new UnmanagedNameEvent (); UnmanagedNameEvent-> SignalEventMessage.connect (f); // which should be in this way .. unmanagedNameEvent-> Signal event messages. Connect (Bind (Netvipplus :: F)); }   

The problem is that I can not use the resident cupus class to refer to my unmanaged function (ief) because it will create a full dependency of the del file. Solution? Any small solution !!

Here's a sample of what I think:

Your < Strong> C ++ / CLI "wrapper":

Market.h:

  #include & lt; Boost / function.hpp & gt; #include & lt; Boost / signals2.hpp & gt; Class __DoubleSPC (Dilexport) Market {Private: Promotion :: Signal 2 :: Signal & Lt; Zero (double)> SignalEvent; Public: Add zero Handler (boost :: function & lt; zero (double)> handler); Public: Move zero (double value); };   

market.cpp:

  #include "market.h" # include & lt; Boost / function.hpp & gt; Zero Market :: AddHandler (boost :: function & lt; zero (double)> handler) {signalEvent.connect (handler); } Zero market :: move (double value) {signalEvent (value); }   

and your Native app , test.cpp: #include & lt; Iostream & gt; # Include & lt; Boost / function.hpp & gt; # Include & lt; Boost / bind.hpp & gt; #include "Market.h" class investor {public: zero move_handler (double value) {std :: cout & lt; & Lt; (Price & gt; = 0? "Hey! I'm the best!": "Watt! I'm losing my shirt!") & Lt; & Lt; Std :: endl; }}; Int main () {Investor investor; Market market; Promote: The function & lt; Zero (double)> Move = boost :: tie (and investor :: move_handler, and investor, _1); Market.AddHandler (move); Market.Move (0.10); Market.Move (-0.10); }

Result:

  Hey! I'm the best! Watt! I'm losing my shirt!   

Hope this helps ...

No comments:

Post a Comment