Hi all :)

There are also a couple problems with calling GetExitCodeProcess in a loop. The first, it eats 100% CPU. The second, if the invoked process happens to return STILL_ACTIVE on exit, your app will never leave the loop.
Posted on 2006-01-09 09:58:15 by QvasiModo
The 100% CPU usage can be taken care of by insert Sleep(something-not-0), but that's a workaround rather than a fix (read: it's a hack), and introduces latency that WaitForSingleObject doesn't have. For a simple "spawn app and wait until it terminates", there really isn't any reason not to use WFSO, and handles should be closed as well.
Posted on 2006-01-09 10:43:34 by f0dder
Posted on 2006-01-11 22:05:05 by XCHG
.386
.model flat,stdcall
option casemap:none
include windows.inc
include kernel32.inc
include user32.inc
includelib kernel32.lib
includelib user32.lib
.data
szNotepadPath db "C:\WINNT\notepad.exe",0
szMsg db "Notepad has been shut down!",0
szErrorText db "Failed to start a process!",0
.data?
sui STARTUPINFO  <>
pi PROCESS_INFORMATION <>
.code

start:
assume edi:PTR STARTUPINFO
mov edi,offset sui
xor ebx,ebx
mov .cb,sizeof STARTUPINFO
mov .dwFlags,STARTF_USESHOWWINDOW
mov .wShowWindow,SW_SHOWNORMAL
assume edi:NOTHING
invoke CreateProcess,offset szNotepadPath,ebx,ebx,ebx,ebx,NORMAL_PRIORITY_CLASS,ebx,ebx,offset sui,offset pi
mov edi,offset szErrorText
test eax,eax
jz @@msg
mov edi,offset szMsg
invoke WaitForSingleObject,pi.hProcess,INFINITE
@@msg:
invoke MessageBox,ebx,edi,ebx,MB_ICONINFORMATION
invoke ExitProcess,ebx
end start
Posted on 2006-01-12 03:08:51 by k3Eahn