Reputation: 181
I´m making a program that must save its files without user interaction when the computer is being turned off. I tried, but I cannot understand how to do it, because most of the info I found is for C#. I found the SystemEvents::SessionEnding
event using the below code for C++, but I don´t know how to implement this in dev-c++:
public:
event SessionEndingEventHandler^ SessionEnding {
static void add(SessionEndingEventHandler^ value);
static void remove(SessionEndingEventHandler^ value);
}
}
Upvotes: 0
Views: 520
Reputation: 595329
The code you showed is not C++. It is C++/CLI, aka C++ w/ .NET managed extensions. It only works in Visual Studio.
The plain C/C++ way to do what you are looking for is to:
use a window procedure in a GUI project to handle WM_QUERYENDSESSION
and WM_ENDSESSION
window messages.
use SetConsoleCtrlHandler()
in a console project to handle CTRL_LOGOFF_EVENT
and CTRL_SHUTDOWN_EVENT
notifications.
use RegisterServiceCtrlHandlerEx()
in a service project to handle SERVICE_CONTROL_PRESHUTDOWN
and SERVICE_CONTROL_SHUTDOWN
notifications.
Refer to MSDN for details:
Upvotes: 4