Search code examples
c++c++-cli

How can I connect a C# delegate to a boost::signal


I've try to connect in this way

TextStore

typedef boost::signals2::signal<VOID(TextStore*, RECT*)> signal_GetCompExt;
signal_GetCompExt       m_sigGetCompExt;

Signal Handler

delegate VOID GetCompsitionExtDelegate(TextStore* textStore, RECT* rect);
VOID onGetCompsitionExt(TextStore* textStore, RECT* rect);

Connect Signal

using namespace System::Runtime::InteropServices;
    m_TextStore->m_sigGetCompExt.connect(reinterpret_cast<TextStore::signal_GetCompExt::slot_type*>(Marshal::GetFunctionPointerForDelegate(gcnew GetCompsitionExtDelegate(this, &AppWrapper::onGetCompsitionExt)).ToPointer()));

but it tells me

C2064   term does not evaluate to a function taking 2 arguments

https://github.com/Windmill-City/libtf/blob/master/libtfWrapper/AppWrapper.cpp

Set Boost Root before build

Path:TextServiceFramework\libtf\PropertySheet.props

BoostVersion boost_1_74_0


Solution

  • typedef void (*GetCompExtCallback)(TextStore* ts, RECT* rect);
    m_TextStore->m_sigGetCompExt.connect(reinterpret_cast<GetCompExtCallback>(Marshal::GetFunctionPointerForDelegate(gcnew GetCompsitionExtDelegate(this, &AppWrapper::onGetCompsitionExt)).ToPointer()));