Упрощенный неуправляемый код:
Код: Выделить всё
typedef std::function ProgressCallback;
class MeshGenerator{
public:
ProgressCallback progress;
///
/// set callback
///
///
inline void SetCallback(ProgressCallback _callback){ this-> progress =_callback; }
};
Код: Выделить всё
public delegate void CallbackDelegate(String^ cap, float data);
public ref class MeshWrapper
{
private:
MeshGenerator *gen;
public:
[MarshalAsAttribute(UnmanagedType::FunctionPtr)]
CallbackDelegate^ _Delegate;
inline MeshWrapper(){
this->gen = new MeshGenerator();
_Delegate = gcnew CallbackDelegate(this, &MeshWrapper::Progress);
auto ptr = Marshal::GetFunctionPointerForDelegate(_Delegate).ToPointer();
ProgressCallback *p = static_cast
(ptr);
this->gen->SetCallback(*p);
}
inline void Progress(String^ cap, float s){ System::Console::WriteLine(cap + s);}
};
Возможно, я делаю некоторые концептуальные ошибки.
Спасибо за помощь.
Подробнее здесь: https://stackoverflow.com/questions/784 ... d-delegate
Мобильная версия