Solved

Blocking on WinExec in Delphi 1.0

Posted on 1997-10-29
6
1,063 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 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