Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Start function when 'ctrl-c' are pressed

Posted on 1999-07-20
9
Medium Priority
?
233 Views
Last Modified: 2010-04-02
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
Comment
Question by:bert1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 1200581
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
 
LVL 7

Expert Comment

by:KangaRoo
ID: 1200582
Depends on compiler. For Borland it is

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

include <dos.h> for this function.
0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 1200583
A sorry, misread the question. Please disregard my previous comment.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:bert1
ID: 1200584
Can you please specify a bit more .... I dont get it to work!

Thanks!
0
 
LVL 86

Expert Comment

by:jkr
ID: 1200585
Hmm, there's hardly more to elaborate ;-)

What problems are you facing?
0
 

Author Comment

by:bert1
ID: 1200586
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
 
LVL 86

Expert Comment

by:jkr
ID: 1200587
>>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
 

Author Comment

by:bert1
ID: 1200588
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
 

Accepted Solution

by:
hsk0 earned 30 total points
ID: 1200589
"programming in windows"
If that's Win32, there's an easy solution:

SetConsoleCtrlHandler()

Set the API reference for details.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question