Results 1 to 7 of 7

Thread: Terminate without return in Main()

  1. #1

    Thread Starter
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339

    Terminate without return in Main()

    is there a way to Terminate either a console app or a Win32 app before you hit your return statement in the main() or WinMain()??

    like in VB it was End, kills the thread at any time......
    or was it Exit in vb...its been awhile damnit..i'm pretty sure it was end.
    "From what was there, and was meant to be, but not of that was faded away." - - Steve Damm

    "The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm

    "When you do things right, people won't be sure if you did anything at all." - - God from Futurama

  2. #2
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403
    the best way is to end from main. Pass the request up via return values or something. I strongly recommend this course of action; it makes sure that everything that was created gets destroyed.

    However, there is also ExitProcess.
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  3. #3
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    Look into the TerminateProcess API

  4. #4
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771
    Another option is to throw an exception, and catch it at the level of the main function. This will ensure proper destruction of objects.

  5. #5
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Another way would be to encapsulate your entire program into a while loop. Even if it doesn't need to loop at all, putting in a simple break statement will break it from the loop and the program will close.

    Much more standard way of doing things. There is also exit() in the C library.

  6. #6
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Using break in a loop is a no no as far as structured programming practices go.
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  7. #7

    Thread Starter
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339
    Well I worked around the problem as it seemed no simple solution was at hand.

    As for not being able to capture a program error...

    I have used alot of c, but I have yet to read up on throw and catch.
    So I shall.

    Thanks guys.
    "From what was there, and was meant to be, but not of that was faded away." - - Steve Damm

    "The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm

    "When you do things right, people won't be sure if you did anything at all." - - God from Futurama

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