Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to Handle Logoff event for console based application

How to Handle Logoff event for console based application

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vermaashish_mca
    wrote on last edited by
    #1

    Hi I have created a console application (.exe), and we have used SetConsoleCtrlHandler for signal handling i.e. "CTRL + C" and Log Off and Shutdown Events. We are properly able to handle the "CTRL+C" event but Logoff and Shut down events cannot be handled properly. Following content is mentioned at MSDN: ======================================================== The system generates CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT, and CTRL_SHUTDOWN_EVENT signals when the user closes the console, logs off, or shuts down the system so that the process has an opportunity to clean up before termination. Console functions, or any C run-time functions that call console functions, may not work reliably during processing of any of the three signals mentioned previously. The reason is that some or all of the internal console cleanup routines may have been called before executing the process signal handler. ======================================================== Please suggest how we can properly handle Logoff and shutdown event by our console application. Or please suggest any other technique (if available) for handling the logoff and shutdown event by the console based application. Thank You

    Ashish Kumar verma Software Engineer(VC++)

    L 1 Reply Last reply
    0
    • V vermaashish_mca

      Hi I have created a console application (.exe), and we have used SetConsoleCtrlHandler for signal handling i.e. "CTRL + C" and Log Off and Shutdown Events. We are properly able to handle the "CTRL+C" event but Logoff and Shut down events cannot be handled properly. Following content is mentioned at MSDN: ======================================================== The system generates CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT, and CTRL_SHUTDOWN_EVENT signals when the user closes the console, logs off, or shuts down the system so that the process has an opportunity to clean up before termination. Console functions, or any C run-time functions that call console functions, may not work reliably during processing of any of the three signals mentioned previously. The reason is that some or all of the internal console cleanup routines may have been called before executing the process signal handler. ======================================================== Please suggest how we can properly handle Logoff and shutdown event by our console application. Or please suggest any other technique (if available) for handling the logoff and shutdown event by the console based application. Thank You

      Ashish Kumar verma Software Engineer(VC++)

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You need to show the code where you test for these conditions; maybe you are doing something wrong.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups