I'm having trouble using _ set_purecall_handler with P / Invoke in C #.
Basically, this works:
(C ++)
_set_purecall_handler(MyPureCallHandler);
void MyPureCallHandler(void)
{
}
But it does not:
(WITH#)
[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()
{
}
I am not sure that my signature on the P / Invoke method is correct, but it does not cause any errors when calling the function (it just does not start the callback when the virtual call fails).
Background
We have several applications (C ++, C ++ / CLI, and C #) that use the same C # library to detect exceptions. This logs various handlers (AppDomain.CurrentDomain.UnhandledException, SetUnhandledExceptionFilter, etc.) and catches most exceptions.
However, it does not recognize pure virtual call errors, so we need to register the above function.