window crashing

This is a discussion on window crashing within the Windows Programming forums, part of the Platform Specific Boards category; I have a program (let's call it "A") which sometimes crashes. I've created a program that always checks to see ...

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    98

    window crashing

    I have a program (let's call it "A") which sometimes crashes.
    I've created a program that always checks to see if "A" exists, and if it isn't it will relaunch it (so when "A" crashes it will open again).
    the problem is that it will open it again everytime i close it, so is there a way to check if the program crashed or have been normally closed?

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    If, when you close the process normally, you return zero to the OS, then your watchdog process can check the exit code. If it is zero, it was a normal exit, so don't restart it, otherwise it was a crash and get it going again. Use GetExitCodeProcess() to get the exit status.

    Another way would be to send a message from the watched task to the watchdog if a normal exit was requested.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User
    Join Date
    Apr 2005
    Posts
    98
    but how do i get handle (to use in GetExitCodeProcess() ) for another window?

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> for another window?

    The HANDLE required is the Process handle, not a window handle. The process handle you need is returned in the PROCESS_INFORMATION structure returned by CreateProcess().
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  5. #5
    Registered User
    Join Date
    Apr 2005
    Posts
    98
    oh, so i have to start the program by the watchdog right?

  6. #6
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    If you have a window handle, you can use GetWindowThreadProcessId to get a process ID. With this, you can use OpenProcess (use PROCESS_QUERY_INFORMATION | SYNCHRONIZE for desired access) to obtain a process handle. You can check if a process has terminated with the WaitForSingleObject function (a process handle is signalled only when the process has terminated).

  7. #7
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> oh, so i have to start the program by the watchdog right?

    I had assumed you were doing so. You can get the process handle other ways. Use EnumProcesses() for example to list all processes, once you find the one you are looking for, you could use OpenProcess() to get the handle.

    Lots of ways forward really.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  8. #8
    Registered User
    Join Date
    Apr 2005
    Posts
    98
    i'll just open the process from the watchdog.
    thakns for all the help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 10:06 AM
  3. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  4. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 09:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21