Click to See Complete Forum and Search --> : Trapping CTRL-C


kaftab
November 27th, 2002, 07:29 AM
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

PaulWendt
November 27th, 2002, 08:25 AM
For WIN32, I believe that you can use SetConsoleCtrlHandler().
Here is a link: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/setconsolectrlhandler.asp

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

--Paul

kaftab
November 27th, 2002, 09:41 AM
Thanks Paul, this was helpful.

Kamran