Solved

Blocking on WinExec in Delphi 1.0

Posted on 1997-10-29
6
1,058 Views
Last Modified: 2012-05-04
Is there a way to spawn a process in Delphi 1.0 and wait for it to run to completion?  WinExec() continues without waiting for the process to complete.
0
Comment
Question by:mozack
  • 3
  • 2
6 Comments
 

Accepted Solution

by:
98113772 earned 100 total points
ID: 1349131
Hi,

Try this one:

Function WinExecAndWait(Path : string; Visibility : word) : word;
var
  InstanceID : THandle;
  PathLen : integer;
begin
  { inplace conversion of a String to a PChar }
  PathLen := Length(Path);
  Move(Path[1],Path[0],PathLen);
  Path[PathLen] := #0;
  { Try to run the application }
  InstanceID := WinExec(@Path,Visibility);
  if InstanceID < 32 then { a value less than 32 indicates an Exec error }
     WinExecAndWait := InstanceID
  else
  begin
    Repeat
      Application.ProcessMessages;
    until Application.Terminated or (GetModuleUsage(InstanceID) = 0);
    WinExecAndWait := 32;
  end;
end;


<--- Cut --->

Greatings from Denmark
Claus Ziegler
0
 

Author Comment

by:mozack
ID: 1349132
No. ProcessMessages gives the control back to windows. The code
is fine.
0
 

Expert Comment

by:krisz
ID: 1349133
Hi,

No draining of the CPU is done. My answer is right. the "ProcessMessages" gives control back to windows.

Greatings from Denmark
Claus Ziegler
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Expert Comment

by:98113772
ID: 1349134
I'm running this process on Windows NT, I don't know if this has anything to do with performance, but when I run:

Repeat
   Application.ProcessMessages;
Until Application.Terminated;

Some 97% of the CPU gets used.  When I start up other processes, the other processes have to fight for CPU usage with this process.
0
 

Author Comment

by:mozack
ID: 1349135
Yes, but it only uses the 97% when noone else needs it. As you can see, it will get lower and lower when you starts more processes up.

Greatings from Denmark
Claus Ziegler
0
 

Expert Comment

by:98113772
ID: 1349136
Exactly, whereas a real Sleep() would not use any CPU at all.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now