Link to home
Start Free TrialLog in
Avatar of bert1
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!
Avatar of jkr
jkr
Flag of Germany image

You'll have to install your own signal handling routines, e.g. by using



void    __cdecl     StopHdl         (   int nSig)
{
  // code goes here, will be executed when CTRL+C is pressed
}


    signal  (   SIGINT,     StopHdl);
    signal  (   SIGBREAK,   StopHdl);

Avatar of KangaRoo
KangaRoo

Depends on compiler. For Borland it is

  void ctrlbrk(int (*handler)(void));

include <dos.h> for this function.
A sorry, misread the question. Please disregard my previous comment.
Avatar of bert1

ASKER

Can you please specify a bit more .... I dont get it to work!

Thanks!
Hmm, there's hardly more to elaborate ;-)

What problems are you facing?
Avatar of bert1

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

Avatar of bert1

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?
ASKER CERTIFIED SOLUTION
Avatar of hsk0
hsk0

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial