bert1
asked on
Start function when 'ctrl-c' are pressed
How do I start a function when I press 'ctrl-c' on the keyboard. Im using Borland C++ 5.02 (programing in windows).
Is it something in the DEFINE_RESPONSE_TABLE1 ??
Thanks!
Is it something in the DEFINE_RESPONSE_TABLE1 ??
Thanks!
Depends on compiler. For Borland it is
void ctrlbrk(int (*handler)(void));
include <dos.h> for this function.
void ctrlbrk(int (*handler)(void));
include <dos.h> for this function.
A sorry, misread the question. Please disregard my previous comment.
ASKER
Can you please specify a bit more .... I dont get it to work!
Thanks!
Thanks!
Hmm, there's hardly more to elaborate ;-)
What problems are you facing?
What problems are you facing?
ASKER
Where should I put
signal ( SIGINT, StopHdl);
signal ( SIGBREAK, StopHdl); ??
And what can I assign nSig to? How does the program 'know' that 'ctrl-c' ??
My program starts a function and I want to be able to cansel it with 'ctrl-c'.
Thanks!
signal ( SIGINT, StopHdl);
signal ( SIGBREAK, StopHdl); ??
And what can I assign nSig to? How does the program 'know' that 'ctrl-c' ??
My program starts a function and I want to be able to cansel it with 'ctrl-c'.
Thanks!
>>Where should I put
>>signal ( SIGINT, StopHdl);
>>signal ( SIGBREAK, StopHdl); ??
Put these statements into the startup code of your program (e.g. 'InitInstance()' if BC++ uses that or just in 'WinMain()')
You can safely ignore the 'nSig' argument...
The program 'knows' that it was CTRL+C as the handler is assigned to that...
>>signal ( SIGINT,
>>signal ( SIGBREAK,
Put these statements into the startup code of your program (e.g. 'InitInstance()' if BC++ uses that or just in 'WinMain()')
You can safely ignore the 'nSig' argument...
The program 'knows' that it was CTRL+C as the handler is assigned to that...
ASKER
My program does not respond to 'ctrl-c'. I have done exactly what you said. :-(
I there an other way to solve it on?
I there an other way to solve it on?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
void __cdecl StopHdl ( int nSig)
{
// code goes here, will be executed when CTRL+C is pressed
}
signal ( SIGINT, StopHdl);
signal ( SIGBREAK, StopHdl);