WindowsSignalHandlerRegistration.cs 693 B

123456789101112131415161718192021222324
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace ARMeilleure.Signal
  4. {
  5. class WindowsSignalHandlerRegistration
  6. {
  7. [DllImport("kernel32.dll")]
  8. private static extern IntPtr AddVectoredExceptionHandler(uint first, IntPtr handler);
  9. [DllImport("kernel32.dll")]
  10. private static extern ulong RemoveVectoredExceptionHandler(IntPtr handle);
  11. public static IntPtr RegisterExceptionHandler(IntPtr action)
  12. {
  13. return AddVectoredExceptionHandler(1, action);
  14. }
  15. public static bool RemoveExceptionHandler(IntPtr handle)
  16. {
  17. return RemoveVectoredExceptionHandler(handle) != 0;
  18. }
  19. }
  20. }