I need to make some clean up before closing my application, but SetConsoleCtrlHandler
doesn't seem to be available for Windows CE console applications.
Is there any alternative method for handling Ctrl+C
in Windows CE 6?
I need to make some clean up before closing my application, but SetConsoleCtrlHandler
doesn't seem to be available for Windows CE console applications.
Is there any alternative method for handling Ctrl+C
in Windows CE 6?
According to Microsoft's documentation, on Windows CE 3.0 and up, the DeviceIoControl
function called with the IOCTL_CONSOLE_SETCONTROLCHANDLER
control code will install a Ctrl+C handler on Windows CE. I haven't tried it out myself yet, but something like this "should" work:
DWORD ignore;
DeviceIoControl(
_fileno(stdout), // handle to the console
IOCTL_CONSOLE_SETCONTROLCHANDLER, // Tell Win CE to set the console Ctrl+C handler
(LPVOID)consoleHandler, // pointer to the signal handler
sizeof(consoleHandler), // size of the pointer
NULL, // output buffer not needed
0, // zero output buffer size
&ignore, // no data will be put into the output buffer so we don't need its size
NULL); // not an asynchronous operation - don't need to provide async info
where consoleHandler
is of course your Ctrl+C handler.
Docs:
Headers needed:
Console.h
winbase.h
(usually included through windows.h).I got this working on Windows Embedded Compact 7. The Ctrl+C and the "window closed" events are both catched.
Notice that IOCTL_CONSOLE_SETCONTROLCHANDLER has been deprecated and DeviceIoControl() fails when it is given that IOCTL code.