user3434681
user3434681

Reputation: 83

C++ Windows Program Detecting Program Exit | No GUI or console

In my C++ Windows Program without a console or GUI I wan't to detect if the task is being cancelled/stopped. How can I achieve this?

Thanks.

Upvotes: 2

Views: 1426

Answers (2)

Tyler
Tyler

Reputation: 1837

atexit() would be the C-portable way to do it.

If you want to use a Windows specific way to do it, see this: Win32 API analog of sending/catching SIGTERM

Upvotes: 3

mooware
mooware

Reputation: 1762

How does your "task" run and how is it stopped? If it's just killed/terminated from the outside, then you can't detect it inside that process.

If your program exits in a regular fashion (no kill, no quick exit), you can register a "cleanup" function with atexit(), which will be run during exit().

EDIT: Or since it's C++, you could use a global variable with a custom type and run your code inside the destructor, which is basically the same as atexit().

Upvotes: 5

Related Questions