Win32 API analog of sending/catching SIGTERM Win32 API analog of sending/catching SIGTERM windows windows

Win32 API analog of sending/catching SIGTERM


MSDNs Unix Code Migration Guide has a chapter about Win32 code conversion and signal handling.
Although Microsoft has decided to archive this brilliant guide, it is very useful.

Three methods are described:
Native signals
Event objects
Messages


You get a WM_QUIT message on your first created thread.

When you don't handle that, your process is forcibly shutdown.

So just implement a message queue in your first thread, which looks for the WM_QUIT message


May be Windows Power Management from MSDN would be helpful. But it deals with system events rather than per process.

For a process, you would be able to detect termination with WM_CLOSE. You would need to handle windows messages. If it's a console application you would need to install a control handler; take a look at SetConsoleCtrlHandler on MSDN