How can I control closing a console in Windows CE?

I have a Win32 C ++ console application running in Window CE 6.0 that contains a number of continuously running threads. Sometimes you need to stop the application, and I would like this to happen in a controlled way. One way to do this is to simply control the console window, and if it closes, stop the process. Unfortunately, SetConsoleCtrlHandler is not part of the Win32 api for Windows CE 6.0. Does anyone know how I can detect that the console is closing in a Win32 C ++ program running in CE?

Thanks,

+4
source share
2 answers

You can watch Ctrl-C by calling DeviceIoControl with IOCTL_CONSOLE_SETCONTROLCHANDLER . Use _fileno (stdout) for the hDevice parameter.

I don’t think there is a way to get notified for any other β€œclosed” mechanism.

0
source

I got this work on Windows Embedded Compact 7. Final events Ctrl + C and "windows closed."

  • Create a Win32 event.
  • Pass this DeviceIoControl () event with IOCTL_CONSOLE_SETCONTROLCEVENT and pass a console handle (e.g. _fileno (stdout)). This event will be signaled when you enter Ctrl + C or close the console window.
  • Create a thread that waits for the Win32 event to signal, and when it becomes such, it calls your handler Ctrl + C or performs your cleanup and probably exits the program.

Note that IOCTL_CONSOLE_SETCONTROLCHANDLER is deprecated, and DeviceIoControl () fails if it is given this IOCTL code.

0
source

Source: https://habr.com/ru/post/1387590/


All Articles