Sign in to follow this  
EnigmaticCoder

Command Line Programs & atexit

Recommended Posts

I'm creating a windows console program that needs to call a cleanUp function when the program is closed. What I want to know is: Is my atexit(cleanUp); function called even if the user closes the command line window using the 'X' button at the top right of the window, or is it only called when the program completes its cycle with the command line window still open? Is there any simple way to test this (perhaps a message box)? [Edited by - anothrguitarist on August 1, 2007 2:56:10 PM]

Share this post


Link to post
Share on other sites
the easiest test would be to write to a file ... if the files there, it did it.

But I can tell you it won't ... (but always test things like this that are important).

A program that has a main() (not a WinMain()) and does not register a window class, does not have a message pump, nor does it recieve windows messages (there is nowhere to get them). Killing the command prompt should be similar to stopping the process of the app ... it simply ceases to be given any resources by windows, which then reclaims it).

Share this post


Link to post
Share on other sites
yeah. strictly speaking, a command line app is not meant to be double-clicked. It's meant to be used by a person familiar with navigating and using the command-line. As such, a user would know that killing the window would terminate their process, so they would leave the window open until the program returned them to the command line.

Don't worry about leaked resources and whatnot. Windows should get everything back for itself when it destroys the process memory space.

-me

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this