detect when an application closes
i have program A which launches program B. now, how can i detect within program A, when program B closes?
all the checking should be made inside program A since program B can be word, or internet explorer or any other app not made by myself.
If you are using the Win32API function CreateProcess() to spawn program B you can use the handle returned by the function in one of the structures that you pass to it. It gets signalled when the process terminates so you can WaitForSingleObject().
If your process didn''t start the other process via CreateProcess, then you could try locating the window of the process via calls to FindWindow and FindWindowEx, and keep calling FindWindow/FindWindowEx until the handle to the window you''re tracking is no longer found. Your process could check it every 100ms or whatever.
ok, thanks!
though it doesnt work for me..
i''ve tried this (assuming arg_prog.exe is in the same directory as the other prog)
but when i try to run it, i get an access violation error... O.o
according to msdn library this is ok.. but, dunno
though it doesnt work for me..
i''ve tried this (assuming arg_prog.exe is in the same directory as the other prog)
#include <stdio.h>#include <conio.h>#include <windows.h>int main(int argc, char* argv[]){ PROCESS_INFORMATION info; if( !CreateProcess( "arg_prog.exe", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &info ) ) { printf("Error creating new process. Error: %s", GetLastError() ); while( !kbhit() ) { } } return 0;}
but when i try to run it, i get an access violation error... O.o
according to msdn library this is ok.. but, dunno
I don''t think you can pass NULL for the second last argument, the STARTUPINFO structure. MSDN specifies that many of the arguments can be NULL but not that one.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement