I want to check in my application programmatically if user shutdown/restart/logoff the computer.
I tried to implement the below code and it giving the compilation error
error: invalid conversion from 'bool (*)(DWORD)' to 'BOOL (*)(DWORD)'
error: initializing argument 1 of 'BOOL SetConsoleCtrlHandler(BOOL (*)(DWORD), BOOL)'
void TestApp:: OnQuit()
{
SetConsoleCtrlHandler(HandlerRoutine, TRUE);
}
//Windows Call Back function implementation
bool WINAPI HandlerRoutine(DWORD dwCtrlType)
{
bool ret = false;
if (dwCtrlType == CTRL_LOGOFF_EVENT || dwCtrlType == CTRL_SHUTDOWN_EVENT)
//Graceful Quit
return ret;
}
My devlopement environment is QT Creator QT SDK and C++.
As others have said, a
BOOLis anint, not abool. Aboolhas nominal values oftrueandfalse,1and0. ABOOLusesFALSE == 0andTRUE == !FALSE. Mostly of no matter here since they essentially work the same way.The
BOOLcomes from the old heritage of WinAPI whenCdidn’t have a built-inbooltype.So, all you really need to do is change
booltoBOOLin you handler: