I have implemented the Event Handling with Boost::Signal and Boost::Bind in my managed C++ file. Refered the Link:Boost::bind
Also I have created the function pointer in my native C++ file which is passed to my boost::Signal.Connect() as EventHandler in managed code. The code for function which is passed as function pointer in my Native C++
std::string NativeCplus::AddFunctionPointer( std::string message )
{
return message;
}
and above function passed as boost::function object in another function NameChangeEvent() as below:
void NativeCplus::NameChangeEvent()
{
UnmanagedNameEvent* unmanagedNameEvent=new UnmanagedNameEvent();
boost::function<std::string (std::string)> f;
f=std::bind1st(std::mem_fun(&AlgebraAPI::AddFunctionPointer),this);//FunctionPointer
std::string name="abcd";
unmanagedNameEvent->AddEvent(f,name);
}
In the above code ,I have taken the boost::function and the function pointer is converted to that boost::function (f).(AM I RIGHT IN SAYING THIS?).Then the line unmanagedNameEvent->AddEvent(f,name) where boost::function(f) is passed to AddEvent(f,name) and this AddEvent(f,name) is implemented in my managed C++ code file. Below is my managed C++ Code which is being referred in the native c++ project:
//In my c++/CLI Wrapper.cpp
declspec(dllexport) void UnmanagedNameEvent::AddEvent(boost::function<std::string (std::string)> f,std::string name)
{
UnmanagedNameEvent* unmanagedNameEvent=new UnmanagedNameEvent();
unmanagedNameEvent->signalEventMessage.connect(f);
//which should be like this.. unmanagedNameEvent->signalEventMessage.connect(bind(NativeCplus::f));
}
PROBLEM is I can't use the NativeCplus class to refer to its unmanaged function (i.e.f)as that will create a round dependency of dll file.Any workaround for this?All ears for any shorter solution!!
Here is a sample of what I understand you want:
Your C++/CLI "wrapper":
Market.h:
Market.cpp:
And your native app, test.cpp:
Results:
Hope this helps...