-
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?
-
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.
-
but how do i get handle (to use in GetExitCodeProcess() ) for another window?
-
>>> 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().
-
oh, so i have to start the program by the watchdog right?
-
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).
-
>>> 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.
-
i'll just open the process from the watchdog.
thakns for all the help