SetConsoleCtrlHandler routine issue

后端 未结 5 880
逝去的感伤
逝去的感伤 2021-02-18 21:43

I\'m writting a console application in C++.

I use SetConsoleCtrlHandler to trap close and CTRL+C button. This allows for all my threads to stop and exit properly.

<
5条回答
  •  庸人自扰
    2021-02-18 22:10

    You're making this more complicated than it needs to be. I don't know exactly why your app is closing, but SetConsoleCtrlHandler(NULL, TRUE) should do what you want:

    http://msdn.microsoft.com/en-us/library/ms686016(VS.85).aspx

    If the HandlerRoutine parameter is NULL, a TRUE value causes the calling process to ignore CTRL+C input, and a FALSE value restores normal processing of CTRL+C input.

提交回复
热议问题