We have a C++/CLI class, let us call it class A, from which we would like to register a non-static callback (“MyNonStaticCallback”) into an unmanaged C++ class (class B).
e.g.
void MyNonStaticCallback(void* ...)
{
// Raise a C# event from this code
}
// Register callback into class B
myClassBInstance->RegisterCallback(..., &MyNonStaticCallback, ...);
The reason why we want a non-static callback is because we want to raise a C# event from this callback function.
I understand it ain’t possible to pass an instance’s data member as a function pointer. What would be the best way to proceed here ?
Thanks and Best Regards,
Romain
Use Marshal.GetFunctionPointerForDelegate Method to get function pointer passed to unmanaged code. Replace void* with IntPtr in MyNonStaticCallback, which matches unmanaged void*. Create delegate instance by general C++/CLI rules.