I'm writing a console application Windows that creates some objects in the main thread and kicks those off into a loop, only exiting when the user uses the Ctrl-C interrupt.
Now, I've read a bit about how to write a proper interrupt handler in articles like this: http://msdn.microsoft.com/en-us/library/ms685049%28VS.85%29.aspx but I'm still confused about one thing. It seems like the interrupt handler leaves limited scope for local object cleanup. For instance, if I had a handler like so:
BOOL CtrlHandler ( DWORD fdwCtrlType )
... handle Ctrl-C
and my main looked something like this:
int main() {
DBClient db;
DataPuller p;
while (true) {
... do stuff until Ctrl-C comes in
}
Even if I catch the Ctrl-C, there seems to be no way to do a proper cleanup of variables db and p without declaring them global, which I typically stay away from.
Is there a better way to do this, or am I missing something obvious? Thanks.