Click to See Complete Forum and Search --> : Make my code wait or loop until another program closes


aewarnick
June 22nd, 2005, 01:55 PM
I am using ShellExecute to open a text file in notepad. I need to wait until notepad is close to continue with the execution of my program.

What do you think is the best way to do that?

NoHero
June 22nd, 2005, 02:20 PM
Use ShellExecuteEx (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shellexecuteex.asp) to retrieve the HINSTANCE of the application and use Wait functions on it such as WaitForSingleObject(). Just wait INFINITE and the function will only return if the application was closed.

aewarnick
June 22nd, 2005, 02:32 PM
MS says the HINSTANCE set is not really an HINSTANCE, it's error handling.

Andreas Masur
June 22nd, 2005, 02:47 PM
Use ShellExecuteEx (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shellexecuteex.asp) to retrieve the HINSTANCE of the application and use Wait functions on it such as WaitForSingleObject(). Just wait INFINITE and the function will only return if the application was closed.
Well...you would not use the 'hInstApp' member of the "SHELLEXECUTEINFO' structure but rather the 'hProcess ' one... ;)

However, this still depends on several options you can set within the 'SHELLEXECUTEINFO' structure and thus, isn't reliable.

Andreas Masur
June 22nd, 2005, 02:49 PM
What do you think is the best way to do that?

How can I start a process? (http://www.codeguru.com/forum/showthread.php?t=302501)
How can I wait until a process ends? (http://www.codeguru.com/forum/showthread.php?t=312451)

aewarnick
June 22nd, 2005, 05:17 PM
Thanks, I had it working but it looks like CreateProcess is much more reliable.