-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSafeNativeMethods.cs
More file actions
37 lines (29 loc) · 1.04 KB
/
SafeNativeMethods.cs
File metadata and controls
37 lines (29 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#region using
using System.Runtime.InteropServices;
using System.Security;
#endregion
namespace SpamAssassinService
{
[SuppressUnmanagedCodeSecurity]
internal static class SafeNativeMethods
{
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool AttachConsole(uint dwProcessId);
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool FreeConsole();
[DllImport("Kernel32")]
internal static extern bool SetConsoleCtrlHandler(HandlerRoutine Handler, bool Add);
[DllImport("kernel32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool GenerateConsoleCtrlEvent(CtrlTypes dwCtrlEvent, uint dwProcessGroupId);
internal delegate bool HandlerRoutine(CtrlTypes CtrlType);
public enum CtrlTypes
{
CTRL_C_EVENT = 0,
CTRL_BREAK_EVENT = 1,
CTRL_CLOSE_EVENT = 2,
CTRL_LOGOFF_EVENT = 5,
CTRL_SHUTDOWN_EVENT = 6,
}
}
}