Announcement

Collapse
No announcement yet.

Problem with abnormal exits

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with abnormal exits

    I've found that sometimes when my application is closed on some
    of our customers computers, (like with Ctl-Alt-Del / End Task)
    it never sends the wm_destroy message to my main window callback.
    This causes problems because there are a number of procedures I
    call when the wm_destroy is received that need to be called at
    every exit. Anybody know of a failsafe way to run a procedure
    EVERY TIME when an exe file application exits?



    -------------
    Jim Seekamp
    Jim Seekamp

  • #2
    Jim --

    An "End Task" is virtually instantaneous, and it does not provide any warning whatsoever to any application. After all, the whole idea of an End Task is to tell an application "stop executing right now". The windows (and other objects) that are owned by the app are automatically cleaned up by Windows, not by the app's callback function. You can't even use the %DLL_PROCESS_DETACH section of a DLL's LibMain function, at least not reliably.

    There are ways to detect more conventional shutdowns, like Windows Shutdown and Windows Logoff, but not an End Task.

    As far as a workaround goes, I suppose you could launch a second (hidden) application to monitor the first app, and if your main app just "goes away" the second one could perform the cleanup. Unless of course the user does an End Task on the hidden app first... so the two apps would have to simultaneously monitor each other...?

    And remember, there is absolutely no way to guarantee the detection of the ultimate unexpected shutdown... the one that is usually caused by that little switch marked "Power On/Off". Even if some versions of Windows can theoretically warn you, the user could always just pull the power plug out of the wall socket.

    -- Eric

    ------------------
    Perfect Sync: Perfect Sync Development Tools
    Email: mailto:[email protected][email protected]</A>



    [This message has been edited by Eric Pearson (edited February 28, 2000).]
    "Not my circus, not my monkeys."

    Comment


    • #3
      Jim,

      I presume your talking 95/98. Excerpts from winhlp file:

      The WM_QUERYENDSESSION message is sent when the user chooses to end the Windows session or when an application calls the ExitWindows function. If any application returns zero, the Windows session is not ended. Windows stops sending WM_QUERYENDSESSION messages as soon as one application returns zero.

      After processing this message, Windows sends the WM_ENDSESSION message with the wParam parameter set to the results of the WM_QUERYENDSESSION message.

      WM_QUERYENDSESSION
      nSource = (UINT) wParam; // source of end-session request
      fLogOff = lParam // logoff flag


      Parameters

      nSource

      Reserved for future use.

      fLogOff

      Value of lParam. Indicates whether the user is logging off or shutting down the system. Supported values include: ENDSESSION_LOGOFF.



      Return Values

      If an application can terminate conveniently, it should return TRUE; otherwise, it should return FALSE.

      Remarks

      By default, the DefWindowProc function returns TRUE for this message.
      Windows NT: When an application returns TRUE for this message, it receives the WM_ENDSESSION message and it is terminated, regardless of how the other applications respond to the WM_QUERYENDSESSION message.
      Windows 95: After all applications return TRUE for this message, they receive the WM_ENDSESSION and they are terminated.

      See Also

      DefWindowProc, ExitWindows, WM_ENDSESSION

      Apparently WM_DESTROY never gets processed in this situation.

      Cecil

      ------------------

      Comment


      • #4
        Thanks for the responses Eric and Cecil.
        Helpful info.

        Best Regards

        Jim


        ------------------
        Jim Seekamp
        Jim Seekamp

        Comment


        • #5
          Just to be clear... The technique that Cecil described cannot detect an End Task operation.

          -- Eric

          ------------------
          Perfect Sync: Perfect Sync Development Tools
          Email: mailto:[email protected][email protected]</A>

          "Not my circus, not my monkeys."

          Comment


          • #6
            Not being that familiar with 95/98, what Eric said about end task is likely true, however in NT4, exiting, logging off, or ending a task through the task manager will trigger execution as you would expext.

            Hope this helps in some small way.

            Cecil

            ------------------

            Comment


            • #7
              Are you sure, Cecil? I just wrote a quicky API-style program that BEEPs whenever any callback is made, and it beeps like crazy when I run it on my NT4 machine, but no sound is made when I do an End Task on it.

              If WM_QUERYENDSESSION was sent for an End Task, it would be possible for an app to return TRUE and thereby refuse to End Task.

              -- Eric

              ------------------
              Perfect Sync: Perfect Sync Development Tools
              Email: mailto:[email protected][email protected]</A>



              [This message has been edited by Eric Pearson (edited February 29, 2000).]
              "Not my circus, not my monkeys."

              Comment


              • #8
                Eric,

                You are correct about not getting a wm_queryendsession for the end task function. I was speaking in general terms about NT4(sp6). You do however, get the wm_destroy message and that's where I normally check for file or sys settings. I was only saying that Jim's program should function as intended on NT.

                I opened my simple text editor and made a change, then clicked task manager to close the program. Up poped the request to save dialog box which is located in the wm_destroy trap. I totally agree with you that there is no fool proof way for Jim to do what he is asking. The user can still void any saving or cleanup functions by merely clicking on the end task button.

                Cheers,
                Cecil

                ------------------


                [This message has been edited by Cecil Williams (edited February 29, 2000).]

                Comment

                Working...
                X