logo
logo
Sign in

Handling the OS shutdown event using WinAPI

avatar
Dennis Turpitka
Handling the OS shutdown event using WinAPI

This guide will cover certain ways to detect restart or shutdown of the PC, as well as other similar events, such as log off or sleep.

Our function analyzes input parameter data, decides which event has occurred and executes certain code as a response to this event.

In order to catch shutdown event in a console application, we should start by creating our own handler function:

BOOL WINAPI HandlerRoutine(_In_ DWORD dwCtrlType);

Next, register it as a handler for this console application by using the following API function:

BOOL WINAPI SetConsoleCtrlHandler(_In_opt_ PHANDLER_ROUTINE HandlerRoutine, _In_ BOOL Add);

collect
0
avatar
Dennis Turpitka
guide
Zupyak is the world’s largest content marketing community, with over 400 000 members and 3 million articles. Explore and get your content discovered.
Read more