Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8131575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:07:50+00:00 2026-06-06T09:07:50+00:00

I want to check in my application programmatically if user shutdown/restart/logoff the computer. I

  • 0

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++.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T09:07:51+00:00Added an answer on June 6, 2026 at 9:07 am

    As others have said, a BOOL is an int, not a bool. A bool has nominal values of true and false, 1 and 0. A BOOL uses FALSE == 0 and TRUE == !FALSE. Mostly of no matter here since they essentially work the same way.

    The BOOL comes from the old heritage of WinAPI when C didn’t have a built-in bool type.

    So, all you really need to do is change bool to BOOL in you handler:

    BOOL WINAPI HandlerRoutine(DWORD dwCtrlType)
    ^^^^
    {
       BOOL ret = false;    
       ^^^^
       if (dwCtrlType == CTRL_LOGOFF_EVENT || dwCtrlType == CTRL_SHUTDOWN_EVENT)
          //Graceful Quit
    
       return ret;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have functionality on my application that lets a user check off
On Android, I want to check programmatically if the InputMethod provided by my application
I have a Inno Setup project that I want to check if the application
I want to check if the window of an external application has the vertical
for some reason I want to check how the deadlock occurred in web application
I'm developing an application in which I want to check like to which power
I have an application that passes in java.util.Date. I want to check whether this
----EDIT---- I am making an jquery mobile application. Now I want to check which
I want to programmatically check if a site has feeds. How can I do
Hi I want to check JRE version before my application is installed in Mac

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.