Hi Chris. I tried your code, but it failed here

cb :=3D SizeOf(TStartupInfo);

Jeremy

-----Original Message-----
From: "Chris Milham" <[EMAIL PROTECTED]>
To: Multiple recipients of list delphi <[EMAIL PROTECTED]>
Date: Mon, 11 Nov 2002 15:13:44 +1300
Subject: RE: [DUG]:  Execute and wait

> Try this one. I have just wrapped a version of "WinExecAndWait32". This
> =
> one DEFINITELY waits correctly.
> HTH
> 
> Chris
> 
> procedure ExecuteProgram(sPath: string; bWait: Boolean);
>   function WinExecAndWait32(Path: PChar; Visibility: Word;
>     Timeout: DWORD): integer;
>   var
>     WaitResult: integer;
>     StartupInfo: TStartupInfo;
>     ProcessInfo: TProcessInformation;
>   begin
>     FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
>     with StartupInfo do
>     begin
>       cb :=3D SizeOf(TStartupInfo);
>       dwFlags :=3D STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
>     { you could pass sw_show or sw_hide as parameter: }
>       wShowWindow :=3D visibility;
>     end;
>     if CreateProcess(nil, path, nil, nil, False,
>       NORMAL_PRIORITY_CLASS, nil, nil,
>       StartupInfo, ProcessInfo) then
>     begin
>       WaitResult :=3D WaitForSingleObject(ProcessInfo.hProcess, =
> timeout);
>       { timeout is in miliseconds or INFINITE if
>       you want to wait forever }
>       result :=3D WaitResult;
>     end
>     else
>     { error occurs during CreateProcess see help for details }
>       result :=3D GetLastError;
>   end;
> begin
>   SetCurrentDir(ExtractFilePath(Application.ExeName)); {Set this so =
> relative paths will work}
>   if not FileExists(sPath) then begin
>     DlgError('Unable to run "' + sPath + '"'+NL+'The program cannot be
> =
> found.');
>   end else begin
>     if bWait then begin
>       WinExecAndWait32(PChar(sPath), SW_SHOW, INFINITE);
>     end else begin
>       WinExecAndWait32(PChar(sPath), SW_SHOW, 0);
>     end;
>   end;
> end;
> 
> 
> 
> > -----Original Message-----
> > From: vss [mailto:vss@;vss.co.nz]
> > Sent: Monday, 11 November 2002 3:08 p.m.
> > To: Multiple recipients of list delphi
> > Subject: [DUG]: Execute and wait
> >=20
> >=20
> > Hi All.
> > I have a bit of code that does an execute and waits for the app.
> to=20
> > close.
> > What I want to do is execute a game and know when its=20
> > finished, BUT when=20
> > I use my code, it starts to execute the app, but then it stops and=20
> > returns an error code of zero which means its finished...BUT it
> never=20
> > started.
> > This is teh code I use. anyone got anything better?
> >=20
> > Jeremy
> >=20
> >=20
> > function TfrmMain.WinExecAndWait32(Path: PChar; Visibility: Word):=20
> > integer;
> > var Msg: TMsg;
> >     lpExitCode: cardinal;
> >     StartupInfo: TStartupInfo;
> >     ProcessInfo: TProcessInformation;
> > begin
> >   FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
> >   with StartupInfo do
> >   begin
> >     cb :=3D SizeOf(TStartupInfo);
> >     dwFlags :=3D STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
> >     wShowWindow :=3D visibility; {you could pass sw_show or sw_hide
> as =
> 
> > parameter}
> >   end;
> >=20
> >   if CreateProcess(nil, path, nil, nil, False,
> NORMAL_PRIORITY_CLASS,=20
> > nil, nil, StartupInfo,
> >                    ProcessInfo) then
> >   begin
> >     repeat
> >       while PeekMessage(Msg, 0, 0, 0, pm_Remove) do
> >       begin
> >         if Msg.Message =3D wm_Quit then Halt(Msg.WParam);
> >         TranslateMessage(Msg);
> >         DispatchMessage(Msg);
> >       end;
> >       GetExitCodeProcess(ProcessInfo.hProcess,lpExitCode);
> >     until lpExitCode <> Still_Active;
> >=20
> >     with ProcessInfo do {not sure this is necessary but seen=20
> > in in some=20
> > code elsewhere}
> >     begin
> >       CloseHandle(hThread);
> >       CloseHandle(hProcess);
> >     end;
> >     Result :=3D 0; {success}
> >   end else Result :=3D GetLastError;
> > end;
> >=20
> > --------------------------------------------------------------
> > -------------
> >     New Zealand Delphi Users group - Delphi List -=20
> > [EMAIL PROTECTED]
> >                   Website: http://www.delphi.org.nz
> > To UnSub, send email to: [EMAIL PROTECTED]=20
> > with body of "unsubscribe delphi"
> > Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/
> >=20
> -----------------------------------------------------------------------
> ----
>     New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
>                   Website: http://www.delphi.org.nz
> To UnSub, send email to: [EMAIL PROTECTED] 
> with body of "unsubscribe delphi"
> Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/

Reply via email to