Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Exit Code Level 2

Exit Code Level 2

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
14 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Mark Salsbery

    Llasus wrote:

    But I've noticed though that on an application it always returns the same exit code.

    Is it your application or 3rd party? If it's yours, you should have control over what's returned :) Mark

    Mark Salsbery Microsoft MVP - Visual C++ :java:

    L Offline
    L Offline
    Llasus
    wrote on last edited by
    #5

    Nope, I've created them. How do I control the value it returns?

    M 1 Reply Last reply
    0
    • L Llasus

      Nope, I've created them. How do I control the value it returns?

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #6

      It depends on what type of application and whether or not it uses the CRT and/or MFC or other libraries. Could be main(), WinMain(), CWinApp::ExitInstance(), the exit code in a WM_QUIT message, etc.  Somewhere, the app is exiting :) Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      L 1 Reply Last reply
      0
      • M Mark Salsbery

        It depends on what type of application and whether or not it uses the CRT and/or MFC or other libraries. Could be main(), WinMain(), CWinApp::ExitInstance(), the exit code in a WM_QUIT message, etc.  Somewhere, the app is exiting :) Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        L Offline
        L Offline
        Llasus
        wrote on last edited by
        #7

        I see, I'll continue researching on MSDN docs about exit codes and see how it changes depending on my application. If you have links about exit codes though please give it to me. Again, thank you very much for your help!!! :-D

        M 1 Reply Last reply
        0
        • L Llasus

          I see, I'll continue researching on MSDN docs about exit codes and see how it changes depending on my application. If you have links about exit codes though please give it to me. Again, thank you very much for your help!!! :-D

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #8

          These are probably the most common places a return value is returned from... main: Program Startup[^]   (Applies to all C/C++ apps) WinMain Function[^]         (Applies to Win32 apps) CWinApp::ExitInstance[^]  (Applies to MFC apps) CWinApp::Run[^]             (Applies to MFC apps - if you've overriden Run(), the returned value can override ExitInstance() return value) PostQuitMessage Function[^] (Applies to all Windows applications) Note that many of these propogate up the list depending on the type of application. For example, in an MFC app, MFC has its own WinMain() and it's all handled by the CRT main() so you only have to worry about the return value from ExitInstance() or in rare circumstances, Run(). Mark

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          L 1 Reply Last reply
          0
          • M Mark Salsbery

            These are probably the most common places a return value is returned from... main: Program Startup[^]   (Applies to all C/C++ apps) WinMain Function[^]         (Applies to Win32 apps) CWinApp::ExitInstance[^]  (Applies to MFC apps) CWinApp::Run[^]             (Applies to MFC apps - if you've overriden Run(), the returned value can override ExitInstance() return value) PostQuitMessage Function[^] (Applies to all Windows applications) Note that many of these propogate up the list depending on the type of application. For example, in an MFC app, MFC has its own WinMain() and it's all handled by the CRT main() so you only have to worry about the return value from ExitInstance() or in rare circumstances, Run(). Mark

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            L Offline
            L Offline
            Llasus
            wrote on last edited by
            #9

            Hi Mark. Thanks for your continuous help. I did some experiment and it actually worked by returning exit code 0. Though what I did may not be the right step. Since I don't really edit the ExitInstance() (as I have never used it before) I tried to check on my OnClose() function. By switching the original CDialog::OnClose() with PostQuitMessage(0), it actually returned the proper exit code of 0. But it may not be right since I forced it to return 0. Could you please check on this one? void CApplicationDlg::OnClose() { SomeClass.CleanUp(); CWnd* ThisDlg; ThisDlg= GetDlgItem(IDC_LEFTPICBOX); ThisDlg->ReleaseDC(&GlobalLeftPicDC); GlobalLeftPicDC.DeleteDC(); ThisDlg= GetDlgItem(IDC_RIGHTPICBOX); ThisDlg->ReleaseDC(&GlobalRightPicDC); GlobalRightPicDC.DeleteDC(); CDialog::OnClose(); //Switch this with PostQuitMessage(0); } I may be somehow going away from my problem here but I just want to prove that exit codes doesn't really have an effect on my program. Again, thank you for your help!

            1 Reply Last reply
            0
            • L Llasus

              Hi there. I created an application that on ending it displays: Program '[2788] Application.exe: Native' has exited with Code 2 (0x2). Now, from my research it said that the successful exit code should be 0. Has anyone had their programs exit with Code 2? Just want to ask so that I would have some clue on where to start finding the cause of this, if this does affect the application in the first place. thank you!

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #10

              Llasus wrote:

              Program '[2788] Application.exe: Native' has exited with Code 2 (0x2).

              If it's a dialog-based application, are you dismissing the dialog via OK or Cancel?


              "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              L 2 Replies Last reply
              0
              • D David Crow

                Llasus wrote:

                Program '[2788] Application.exe: Native' has exited with Code 2 (0x2).

                If it's a dialog-based application, are you dismissing the dialog via OK or Cancel?


                "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                L Offline
                L Offline
                Llasus
                wrote on last edited by
                #11

                No, I actually removed those two buttons that come as default when creating a new dialog.

                1 Reply Last reply
                0
                • D David Crow

                  Llasus wrote:

                  Program '[2788] Application.exe: Native' has exited with Code 2 (0x2).

                  If it's a dialog-based application, are you dismissing the dialog via OK or Cancel?


                  "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  L Offline
                  L Offline
                  Llasus
                  wrote on last edited by
                  #12

                  How does the dismissal of the dialog by OK or Cancel relate to the Exit Code 2?

                  D 1 Reply Last reply
                  0
                  • L Llasus

                    How does the dismissal of the dialog by OK or Cancel relate to the Exit Code 2?

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #13

                    It relates to it 100%. Try it and see.


                    "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                    L 1 Reply Last reply
                    0
                    • D David Crow

                      It relates to it 100%. Try it and see.


                      "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                      L Offline
                      L Offline
                      Llasus
                      wrote on last edited by
                      #14

                      Yes you are right! Exit code of 0 is done when the OK or Cancel button is pushed. And Exit code 2 is when close button or alt-F4 is done. Thank you very much for your help! :D

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups