一段超简单但费解的代码,摘自msdn!!
BOOL CtrlHandler(DWORD fdwCtrlType)
{
switch (fdwCtrlType)
{
// Handle the CTRL+C signal.
case CTRL_C_EVENT:
Beep(1000, 1000);
return TRUE;
// CTRL+CLOSE: confirm that the user wants to exit.
case CTRL_CLOSE_EVENT:
return TRUE;
// Pass other signals to the next handler.
case CTRL_BREAK_EVENT:
case CTRL_LOGOFF_EVENT:
case CTRL_SHUTDOWN_EVENT:
default:
return FALSE;
}
}
void main(void)
{
BOOL fSuccess;
fSuccess = SetConsoleCtrlHandler(
(PHANDLER_ROUTINE) CtrlHandler, // handler function
TRUE); // add to list
if (! fSuccess)
MyErrorExit("Could not set control handler");
}
这个在控制台应该能够监测到ctrl+c和关闭消息,但是我这里怎么都失效了,系统根本没有调用回调函数!!
这是为何??盼高手明示,在线等待,马上揭帖!!!