internal ExceptionHandler(ShutdownOnException shutdown, bool disabled = false) { shutdown_ = shutdown; if (disabled) { filter_ = new Win32Api.UnhandledExceptionFilter_Delegate(ExceptionHandler.EmptyUnhandledExceptionFilter); } oldFilter_ = Win32Api.SetUnhandledExceptionFilter(filter_); }
internal static Win32Api.UnhandledExceptionFilter_Delegate SetUnhandledExceptionFilter_Hooked( Win32Api.UnhandledExceptionFilter_Delegate lpTopLevelExceptionFilter) { return(new HookContext <Win32Api.UnhandledExceptionFilter_Delegate>( func => { string message = "Native call is not supported for SetUnhandledExceptionFilter."; Debug.Assert(false, message); throw new Exception(message); }, helper => { // Ignoring the value set by user and always installing our handler Win32Api.SetUnhandledExceptionFilter(filter_); // We could return any value, because we don't give control // to application's unhandled exception filter so it won't call it. return filter_; }, errorCode => filter_, HookLogging.DefaultLogging, "[lpFilter]: {0}.", (long)Marshal.GetFunctionPointerForDelegate(lpTopLevelExceptionFilter)).Call()); }