diff options
Diffstat (limited to 'ARMeilleure/Signal/WindowsSignalHandlerRegistration.cs')
-rw-r--r-- | ARMeilleure/Signal/WindowsSignalHandlerRegistration.cs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/ARMeilleure/Signal/WindowsSignalHandlerRegistration.cs b/ARMeilleure/Signal/WindowsSignalHandlerRegistration.cs index 959d1c47..513829a6 100644 --- a/ARMeilleure/Signal/WindowsSignalHandlerRegistration.cs +++ b/ARMeilleure/Signal/WindowsSignalHandlerRegistration.cs @@ -1,9 +1,10 @@ using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ARMeilleure.Signal { - class WindowsSignalHandlerRegistration + unsafe class WindowsSignalHandlerRegistration { [DllImport("kernel32.dll")] private static extern IntPtr AddVectoredExceptionHandler(uint first, IntPtr handler); @@ -11,6 +12,14 @@ namespace ARMeilleure.Signal [DllImport("kernel32.dll")] private static extern ulong RemoveVectoredExceptionHandler(IntPtr handle); + [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Ansi)] + static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)] string lpFileName); + + [DllImport("kernel32.dll", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)] + private static extern IntPtr GetProcAddress(IntPtr hModule, string procName); + + private static IntPtr _getCurrentThreadIdPtr; + public static IntPtr RegisterExceptionHandler(IntPtr action) { return AddVectoredExceptionHandler(1, action); @@ -20,5 +29,17 @@ namespace ARMeilleure.Signal { return RemoveVectoredExceptionHandler(handle) != 0; } + + public static IntPtr GetCurrentThreadIdFunc() + { + if (_getCurrentThreadIdPtr == IntPtr.Zero) + { + IntPtr handle = LoadLibrary("kernel32.dll"); + + _getCurrentThreadIdPtr = GetProcAddress(handle, "GetCurrentThreadId"); + } + + return _getCurrentThreadIdPtr; + } } } |