CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Trapping CTRL-C

  1. #1
    Join Date
    May 2001
    Posts
    153

    Question Trapping CTRL-C

    Hi Everyone,

    I am working on a command line application that runs in a console (the dos window). It starts with the typical int main(argc, argv), there are no dialogs or MFC employed. It uses a third party API to work with a PDM system (that works with a database in turn). The program initializes the PDM system when it starts, and at the end of the program, it terminates the PDM process.

    The issue is when CTRL-C is pressed, the program simply shuts down and the PDM system generates errors, since there is not a clean shutdown of the process.

    Is there a way I can trap the CTRL-C to be able to do the cleanup? Would this be through the use of Exception Handling? (I am not currently using any exception handling).

    Thanks for the anticipated help.

    Kamran

  2. #2
    Join Date
    May 2000
    Location
    Phoenix, AZ [USA]
    Posts
    1,347
    For WIN32, I believe that you can use SetConsoleCtrlHandler().
    Here is a link: http://msdn.microsoft.com/library/de...trlhandler.asp

    For unix systems, you have to catch the SIGINT signal.

    --Paul

  3. #3
    Join Date
    May 2001
    Posts
    153
    Thanks Paul, this was helpful.

    Kamran

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured