[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 234
  • Last Modified:

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!
0
bert1
Asked:
bert1
  • 3
  • 3
  • 2
  • +1
1 Solution
 
jkrCommented:
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);

0
 
KangaRooCommented:
Depends on compiler. For Borland it is

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

include <dos.h> for this function.
0
 
KangaRooCommented:
A sorry, misread the question. Please disregard my previous comment.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

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

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

What problems are you facing?
0
 
bert1Author Commented:
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!
0
 
jkrCommented:
>>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...

0
 
bert1Author Commented:
My program does not respond to 'ctrl-c'. I have done exactly what you said. :-(

I there an other way to solve it on?
0
 
hsk0Commented:
"programming in windows"
If that's Win32, there's an easy solution:

SetConsoleCtrlHandler()

Set the API reference for details.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now