Newer
Older
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <memory.h>
#include <windows.h>
#include "dap_common.h"
#include "sig_win32_handler.h"
#define LOG_TAG "sig_win32_handler"
BOOL WINAPI sig_exit_handler( DWORD fdwCtrlType )
{
HANDLE hConOut = GetStdHandle( STD_OUTPUT_HANDLE );
SetConsoleTextAttribute( hConOut, 12 );
switch (fdwCtrlType)
{
// Handle the CTRL-C signal.
case CTRL_C_EVENT:
printf("Ctrl-C event\n\n");
Beep(750, 300);
break;
// CTRL-CLOSE: confirm that the user wants to exit.
case CTRL_CLOSE_EVENT:
Beep(600, 200);
printf("Ctrl-Close event\n\n");
break;
// Pass other signals to the next handler.
case CTRL_BREAK_EVENT:
Beep(900, 200);
printf("Ctrl-Break event\n\n");
break;
case CTRL_LOGOFF_EVENT:
Beep(1000, 200);
printf("Ctrl-Logoff event\n\n");
break;
case CTRL_SHUTDOWN_EVENT:
Beep(750, 500);
printf("Ctrl-Shutdown event\n\n");
break;
}
SetConsoleTextAttribute( hConOut, 7 );
ExitProcess( 2 );
}
int sig_win32_handler_init( const char *pid_path ) {
if ( !SetConsoleCtrlHandler( sig_exit_handler, TRUE ) ) return 1;
return 0;
}
int sig_win32_handler_deinit() {
SetConsoleCtrlHandler( sig_exit_handler, FALSE );
return 0;
}