DelphiFAQ Home Search:

Start a DOS program from Delphi 1 and wait for it to finish

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

The following Delphi1 procedure executes a DOS program and waits until it finished. Parameter HWindow is the window handle of the calling application, typically you would pass Application.MainForm.Handle there.

The key function is GetModuleUsage to determine whether the DOS module is still in memory - this function is not available in in Delphi 2/3.

procedure ExecAndWait(HWindow:HWnd; ExecStr: PChar; CmdShow: word);
var
  M        : TMsg;
  Erg      : word;
  ErgStr,
  MsgStr   : array[0..128] of char;
begin  
  Erg:=WinExec(ExecStr,CmdShow);  
  if Erg < 32 then 
  begin 
    str(erg, ergstr); 
    strcopy(msgstr,'Could not execute program. Error #: '); 
    strcat (msgstr, ergstr); 
    MessageBox(hwindow, ergstr, execstr, mb_ok or mb_iconstop); 
  end 
  else 
  begin { exec waits! } 
    ShowWindow(hwindow, sw_hide); 
    repeat 
      while PeekMessage(m,0,0,0,pm_remove) do 
      begin 
        if m.Message=wm_quit then 
        begin 
          PostQuitMessage(m.wparam); 
          exit; 
        end 
        else 
        begin 
          translatemessage(m); 
          dispatchmessage(m); 
        end; 
      end; 
    until GetModuleUsage(erg)=0;
    ShowWindow(hwindow, sw_shownormal); 
  end; 
end; 

Comments:

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: