I'm having trouble using _set_purecall_handler with P/Invoke in C#.
Basically, this works:
(C++)
_set_purecall_handler(MyPureCallHandler);
void MyPureCallHandler(void)
{
// gets called
}
But this doesn’t:
(C#)
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void PureCallHandler();
[DllImport("msvcr100.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr _set_purecall_handler([MarshalAs(UnmanagedType.FunctionPtr)] PureCallHandler handler);
_set_purecall_handler(MyPureCallHandler);
private void MyPureCallHandler()
{
// *** doesn’t get called ***
}
I’m not sure if my P/Invoke method signature is correct, but it doesn't throw any errors when I call the function (it just doesn't fire the callback on a pure virtual call error).
Background
We have a number of apps (C++, C++/CLI and C#) that use a single C# library for catching exceptions. This registers various handlers (AppDomain.CurrentDomain.UnhandledException, SetUnhandledExceptionFilter, etc) and catches most exceptions.
However, it doesn't catch pure virtual call errors and so we need to register the above function.