I am very new to C++ and have recently started a project for which I need to access a device, collect certain data and forward it to a datastream on a local network.
While my application does all the things require it lacks on function: When I close the window, in which the application is running it does not stop the hardware-device. The result is, that I have to do a hardware reset every time I am finished with the program. This is not only inconvienient but impossible for the programms intended usage.
I basically just want to set a callback for a function, that is executed, when the program is closed (either by clicking the x, pressing Alt-F4 etc.)
Is this possible? I the possibility to create a handler for such events:
BOOL WINAPI ConsoleHandler(DWORD dwCtrlEvent)
{
switch (dwCtrlEvent)
{
case CTRL_CLOSE_EVENT:
// something
case CTRL_SHUTDOWN_EVENT:
// the same?
default:
return FALSE;
}
}
If this is a correct approach I am wondering how to use this handler? Do I need to create such a handler in my program and the update is constantly?
I am grateful for any help Jonas
Proper RAII usage would help you in this case.
This basically says to wrap resource ownership inside of objects. You can then create an object on program start and clean any resources up on program end:
dm
will be initialized on program start-up, before entry tomain()
and will be released on program end.