Results 1 to 8 of 8

Thread: But what if we programmed it in "B"?

  1. #1

    Thread Starter
    Lively Member Zero's Avatar
    Join Date
    Feb 2000
    Posts
    101

    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

  2. #2
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    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
    Baaaaaaaaah

  3. #3
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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."

  4. #4

    Thread Starter
    Lively Member Zero's Avatar
    Join Date
    Feb 2000
    Posts
    101

    ...

    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

  5. #5
    jim mcnamara
    Guest
    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

  6. #6
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    What's 'the image'?
    Harry.

    "From one thing, know ten thousand things."

  7. #7
    Zaei
    Guest
    Probably he means the program image in memory.

    Z.

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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
  •  



Click Here to Expand Forum to Full Width