DelphiFAQ Home Search:
General :: Windows :: Programming :: Windows with Delphi :: Windows API
Windows programming with Delphi

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Only the 40 most recently viewed articles are shown.
You can see the full list here.

Featured Article

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

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; 
 

Generated 0:02:01 on Sep 29, 2020