Windows System Programming : Exception Handling - Example: A Console Control Handler
Published 1 min readBy Programming4us Editorial Team
Program 1 loops forever, calling the self-explanatory Beep function every 5 seconds. The user can terminate the program with a Ctrl-C or by closing the console. The handler routine will put out a message, wait 10 seconds, and, it would appear, return TRUE, terminating the program. The main program, however, detects the exitFlag flag and stops the process. This illustrates the concurrent operation of the handler routine; note that the timing of the signal determines the extent of the signal handler’s output.
Program 1. Ctrlc: Signal Handling Program
Note the use of WINAPI; this macro is for user functions passed as arguments to Windows functions to assure the proper calling conventions. It is defined in the Platform SDK header file windef.h.
There’s very little to show with this program, as we can’t show the sound effects. Nonetheless, Run 4-5 shows the command window where I typed Ctrl-C after about 11 seconds.