Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

neo644

detect when an application closes

This topic is 5719 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
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().

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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)


  
#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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
ups, i was checking the windows CE doc, hehe
anyways, i tried the example code provided by msdn and it doesnt work
here is the link
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/creating_processes.asp

[edited by - neo644 on April 21, 2003 1:09:12 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!