Advertisement
Guest User

Untitled

a guest
Aug 17th, 2013
666
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3.  
  4. BOOL running;
  5.  
  6. BOOL consoleHandler(DWORD signal);
  7.  
  8.  
  9. int main(int argc, char **argv) {
  10.  
  11.     running = TRUE;
  12.     if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE) consoleHandler, TRUE)) {
  13.  
  14.             std::cerr << "Error: " << GetLastError() << std::endl;
  15.             return -1;
  16.     }
  17.  
  18.     while (running) {
  19.  
  20.            std::cout << "This is a test work-instruction" << std::endl;
  21.            Sleep(5000);
  22.     }
  23.  
  24.     std::cout << "This is a test cleanup-instruction" << std::endl;
  25.  
  26.     return 0;
  27. }
  28.  
  29. BOOL consoleHandler(DWORD signal) {
  30.  
  31.     if (signal == CTRL_C_EVENT) {
  32.  
  33.         std::clog << "I'm in handler function" << std::endl;
  34.         running = FALSE;
  35.     }
  36.     return TRUE;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement