Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- BOOL running;
- BOOL consoleHandler(DWORD signal);
- int main(int argc, char **argv) {
- running = TRUE;
- if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE) consoleHandler, TRUE)) {
- std::cerr << "Error: " << GetLastError() << std::endl;
- return -1;
- }
- while (running) {
- std::cout << "This is a test work-instruction" << std::endl;
- Sleep(5000);
- }
- std::cout << "This is a test cleanup-instruction" << std::endl;
- return 0;
- }
- BOOL consoleHandler(DWORD signal) {
- if (signal == CTRL_C_EVENT) {
- std::clog << "I'm in handler function" << std::endl;
- running = FALSE;
- }
- return TRUE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement