|
-
Sep 4th, 2001, 10:22 AM
#1
Thread Starter
Lively Member
But what if we programmed it in "B"?
Greetings. I am in the process of learning to use Visual C++. As such, over a period of a few days, I will be asking some very stupid questions in the hopes that someone will answer them. As a reward for helping me, you all will get a free copy of my mostly useless program, when it is finished.
Right, then.
First off, how do you end a C++ program? Is there some command that works like End does in VB? I know you can pull a Return 0; in your main function, but I want to be able to end my program from a subroutine elsewhere.
Second, what happens to a C++ (windows) program when it loses the focus? Does it keep chugging away if it's in a loop or does it slow down like VB does?
~Zero the Inestimable
-
Sep 4th, 2001, 10:37 AM
#2
PowerPoster
You use the command "exit(0)" or "exit(1)"
Everybody will be happy to answer your questions. And you need to first learn the actuall C++ language before programming in windows
-
Sep 4th, 2001, 10:48 AM
#3
Frenzied Member
You can use the exit() function like Abdul says, but it's not a very clean way to finish things. It's much better to return error codes from all your functions and step back from each function in turn when an error occurs or you just want to close it down.
With Windows apps, once you've done some setting up of message handling stuff, you can usually close things down fairly gracefully by posting a message to your main window telling it to quit.
Harry.
"From one thing, know ten thousand things."
-
Sep 4th, 2001, 11:08 AM
#4
Thread Starter
Lively Member
...
I took a (mostly) worthless course on C++ once. It was all console cin cout stuff. I know how the basics work, I just don't know how all of the interesting quirks work.
Thank you, though.
~Zero the Inestimable
-
Sep 4th, 2001, 11:11 AM
#5
You can also define routines to rundown your image - ie., stuff you call at image exit. These are also invoked with exit().
You use atexit( function_pointer); to declare these exit handlers in standard C.
C++ also uses atexit() plus some others like _cexit(); use this to cleanup without actually exiting the image.
go here:
http://search.microsoft.com/us/dev/d...i=49&i=50&i=51
-
Sep 4th, 2001, 11:23 AM
#6
Frenzied Member
Harry.
"From one thing, know ten thousand things."
-
Sep 4th, 2001, 01:42 PM
#7
Probably he means the program image in memory.
Z.
-
Sep 4th, 2001, 04:10 PM
#8
Monday Morning Lunatic
To end a C++ program under windows you call the ExitProcess function. However, you should return from main() or WinMain() which returns control to the runtime library's startup function (mainCRTStartup / WinMainCRTStartup) which tidies up, then calls ExitProcess. Those two CRT functions don't explicitly exit because there's no longer a stack to tidy.
Just thought I'd add that to confuse everyone
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|