前几天看uddf的时候,发现了如下的源程序:<br>From: Noel Rice <nrice@ix.netcom.com><br><br>A: Here is the 16 bit version:<br><br><br>--------------------------------------------------------------------------------<br><br>uses Wintypes,WinProcs,Toolhelp,Classes,Forms;<br><br>Function WinExecAndWait(Path : string; Visibility : word) : word;<br>var<br> InstanceID : THandle;<br> PathLen : integer;<br>begin<br> { inplace conversion of a String to a PChar }<br> PathLen := Length(Path);<br> Move(Path[1],Path[0],PathLen);<br> Path[PathLen] := #00;<br> { Try to run the application }<br> InstanceID := WinExec(@Path,Visibility);<br> if InstanceID < 32 then { a value less than 32 indicates an Exec error }<br> WinExecAndWait := InstanceID<br><br> else begin<br> Repeat<br> Application.ProcessMessages;<br> until Application.Terminated or (GetModuleUsage(InstanceID) = 0);<br> WinExecAndWait := 32;<br> end;<br>end;<br><br>--------------------------------------------------------------------------------<br>Here is the 32 bit version:<br><br><br>--------------------------------------------------------------------------------<br><br>function WinExecAndWait32(FileName:String; Visibility : integer):integer;<br>var<br> zAppName:array[0..512] of char;<br> zCurDir:array[0..255] of char;<br> WorkDir:String;<br> StartupInfo:TStartupInfo;<br> ProcessInfo:TProcessInformation;<br>begin<br> StrPCopy(zAppName,FileName);<br> GetDir(0,WorkDir);<br> StrPCopy(zCurDir,WorkDir);<br> FillChar(StartupInfo,Sizeof(StartupInfo),#0);<br> StartupInfo.cb := Sizeof(StartupInfo);<br><br> StartupInfo.dwFlags := STARTF_USESHOWWINDOW;<br> StartupInfo.wShowWindow := Visibility;<br> if not CreateProcess(nil,<br> zAppName, { pointer to command line string }<br> nil, { pointer to process security attributes }<br> nil, { pointer to thread security attributes }<br> false, { handle inheritance flag }<br> CREATE_NEW_CONSOLE or { creation flags }<br> NORMAL_PRIORITY_CLASS,<br> nil, { pointer to new environment block }<br> nil, { pointer to current directory name }<br> StartupInfo, { pointer to STARTUPINFO }<br> ProcessInfo) then Result := -1 { pointer to PROCESS_INF }<br><br> else begin<br> WaitforSingleObject(ProcessInfo.hProcess,INFINITE);<br> GetExitCodeProcess(ProcessInfo.hProcess,Result);<br> end;<br>end;<br>