如何在Windows CE控制台应用程序中处理Ctrl + C?
我需要在关闭我的应用程序之前进行一些清理,但 SetConsoleCtrlHandler
似乎不适用于Windows CE控制台应用程序。
I need to make some clean up before closing my application, but SetConsoleCtrlHandler
doesn't seem to be available for Windows CE console applications.
在Windows CE 6中是否有其他方法来处理 Ctrl + C
?
Is there any alternative method for handling Ctrl+C
in Windows CE 6?
根据Microsoft的文档,在Windows CE 3.0及以上版本中,使用 IOCTL_CONSOLE_SETCONTROLCHANDLER 调用的
DeviceIoControl
/ code>控制代码将在Windows CE上安装一个Ctrl + C处理程序。我还没有尝试过自己,但这样的应该工作:
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
其中 consoleHandler
当然是您的Ctrl + C处理程序。
where consoleHandler
is of course your Ctrl+C handler.
文件:
- DeviceIoControl (CE 7)
- IOCTL_CONSOLE_SETCONTROLCHANDLER (CE .NET)
所需标题:
-
Console.h
-
winbase.h
(通常通过windows.h包含)。
Console.h
-
winbase.h
(usually included through windows.h).