Solved

waitforsingleobject.....

Posted on 1997-11-15
6
367 Views
Last Modified: 2013-04-01
Hi!

I have a small problem. I use the API waitforsingleobject.
I makeing a program that runs MS Publisher 97 Setup prog. with some switches (/qt (means quietmode)). But wenn I start the program and press the button that starts the installtionprog. And the program is started. But it hangs wenn it should look for installed objects....

Anyone know what the problem is? It's Delphi or Publisher that bugs, or?

I use Delphi 2.0.....

TimeMan
0
Comment
Question by:TimeMan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 1

Expert Comment

by:jackb022197
ID: 1350540
Have you checked whether or not the installation program also locks up when you run it seperately, and not from within your D2 application??
If it also locks up when you run it seperately, then it is not your delphi application...

0
 

Author Comment

by:TimeMan
ID: 1350541
Hi!

I have test that. It is not locking...

//TimeMan
0
 

Expert Comment

by:jgalang
ID: 1350542
Send me a snippet of your code and I'll tell you whats wrong with it.

Things to check:
1. Is your WaitForSingleObject set to time-out or not?
2. Are you using the CreateProcess to execute your program (and detecting if its done with WaitForSingleObject?)

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:TimeMan
ID: 1350543
Hi!

Here it comes

TimeMan


function WinExecAndWait32(FileName:String; Visibility : integer):integer;
var
   zAppName: array[0..512] of char;
   zCurDir: array[0..255] of char;
   WorkDir: string;
   StartupInfo: TStartupInfo;
   ProcessInfo: TProcessInformation;
begin
   StrPCopy(zAppName,FileName);
   GetDir(0,WorkDir);
   StrPCopy(zCurDir,WorkDir);
   FillChar(StartupInfo,Sizeof(StartupInfo),#0);
   StartupInfo.cb := Sizeof(StartupInfo);
   StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
   StartupInfo.wShowWindow := Visibility;
   if not CreateProcess(nil,
      zAppName,    { pointer to command line string }
      nil,         { pointer to process security attributes }
      nil,         { pointer to thread security attributes }
      false,       { handle inheritance flag }
      CREATE_NEW_CONSOLE or  { creation flags }
      NORMAL_PRIORITY_CLASS,
      nil,         { pointer to new environment block }
      nil,         { pointer to current directory name }
      StartupInfo, { pointer to STARTUPINFO }
      ProcessInfo) then Result := -1 { pointer to PROCESS_INF }
   else
   begin
      WaitforSingleObject(ProcessInfo.hProcess, INFINITE);
      GetExitCodeProcess(ProcessInfo.hProcess, Result);
   end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
WinExecAndWait32 ('c:\temp\pub\setup.exe /qt',0);
form2.show;
end;
0
 

Accepted Solution

by:
jgalang earned 190 total points
ID: 1350544
Your app was doing okay, but it wasnt proceessing any messages (keyboard, screen refresh, etc) and the setup program was probably taking too long, so it seemed like your program was locked up (it is! but the setup program, running quietly wasnt)

your app locked up because of the following line:

>> WaitForSingleObject( ProcessInfo.hProcess, INFINITE );

I modified a portion of your code to make it a little bit more user friendly.

First, I added a local variable in your WinExecAndWait32 method

>>
>> var                     // additional variables
>>   dwWait : DWORD;       //
>>

Second, I modified the portion where you WaitForSingleObject so that app messages are processed while the object is signaled
(1000 means, it processes app messages every 1 second)

>>
>> repeat
>>   dwwait := WaitForSingleObject( ProcessInfo.hProcess, 1000 );
>>   GetExitCodeProcess(ProcessInfo.hProcess, Result);
>>   Application.ProcessMessages;
>> until dwwait <> WAIT_TIMEOUT;
>>

And last, If you don't want the user to be able to do anything else while your setup program is running (or to prevent them from doing anything stupid) you'll need to have something like this when invoking the WinExecAndWait32 method

>>
>> procedure TForm1.BitBtn1Click(Sender: TObject)
>> const
>>   bInWait: boolean = False;
>> var
>>   Result : Integer;
>> begin
>>   //  don't launch MYPROGRAM.EXE if we are already
>>   //  waiting for MYPROGRAM.EXE to  finish
>>   if bInWait then Exit;
>>   // notify ourself that we have launched MYPROGRAM.EXE
>>   bInWait := True;
>>   try
>>     // launch MYPROGRAM.EXE
>>     Result := WinExecAndWait32( 'C:\MYPROGRAM.EXE', 0 );
>>   finally
>>     case Result of
>>     // check Result for errors
>>     end;      
>>     // notify ourself that we're done messing around
>>     // with MYPROGRAM.EXE
>>     bInWait := False;
>>   end;
>> end;
>>

I tested the above modification and it worked perfectly, running different setup programs, as well as some time-critical apps I've written.

I hope this got to you in time to be useful.

TTYL.

jgalang
0
 

Author Comment

by:TimeMan
ID: 1350545
Hi!

I havent test it yet...but it seems to work better than mine...


//TimeMan
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Firemonkey android show image from resource ? 1 58
Tvertscrollbox like a whatsapp layout 5 53
Firemonkey BASS_Init into a thread 17 57
Broadcast a message using ICS 2 28
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

730 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