Board index » delphi » Waiting for WinExec to complete??

Waiting for WinExec to complete??

I have the impression that WinExec (and ShellExecute) are called in
parallell. When calling programs that generate files to be used by the
calling program the files are only halfway created when I begin to read
from them :-(. Is there a way to get WinExec to hold back the program
(a SYNC parameter?) or a utility to loop until execution is completed?
The problem might also have to do with cashed data not being accessed
properly...

Any help will be greatly appreciated!

Sincerely,
Marc de Oliveira

 

Re:Waiting for WinExec to complete??


Quote
In article <310EB4DC.4...@novo.dk>, Marc <M...@novo.dk> wrote:
>I have the impression that WinExec (and ShellExecute) are called in
>parallell. When calling programs that generate files to be used by the
>calling program the files are only halfway created when I begin to read
>from them :-(. Is there a way to get WinExec to hold back the program
>(a SYNC parameter?) or a utility to loop until execution is completed?
>The problem might also have to do with cashed data not being accessed
>properly...

>Any help will be greatly appreciated!

>Sincerely,
>Marc de Oliveira

Use these functions together, they have worked great for me.
Ron Zika
rz...@icon-stl.net

function WinExecAndWait(Path: Pchar): word; {App launcher}
var
InstanceID: Thandle;
begin
InstanceID := WinExec(Path, SW_SHOWNORMAL);
if InstanceID < 32 then
   WinExecAndWait := InstanceID
else begin
     repeat
       DoEvents;
     until GetModuleUsage(InstanceID) = 0;
     WinExecAndWait := 32;
     end;
end;

Procedure DoEvents; {poor mans Application.Processmessages :) }
var
Msg : TMsg;
begin
  while PeekMessage(Msg,0,0,0,PM_REMOVE) do begin
      if (Msg.Message = $0012) then begin
         exit;
      end;
      TranslateMessage(Msg);
      DispatchMessage(Msg);
  end;
end;

Re:Waiting for WinExec to complete??


In article <310EB4DC.4...@novo.dk>, Marc <M...@novo.dk> writes

Quote
>I have the impression that WinExec (and ShellExecute) are called in
>parallell. When calling programs that generate files to be used by the
>calling program the files are only halfway created when I begin to read
>from them :-(. Is there a way to get WinExec to hold back the program
>(a SYNC parameter?) or a utility to loop until execution is completed?
>The problem might also have to do with cashed data not being accessed
>properly...

>Any help will be greatly appreciated!

>Sincerely,
>Marc de Oliveira

Using the handle returned by WinExec or ShellExecute do

repeat
  Application.ProcessMessages
until GetModuleUsage(handle) = 0;
--
Julian Moss                                      J M Technical Services
{*word*19}ermouth, Cumbria, UK                 Technical Writing and Software
(+44) 1900 826514                              jm...@jmtech.demon.co.uk

Other Threads