Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

waitforsingleobject.....

Posted on 1997-11-15
6
Medium Priority
?
387 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 760 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

Industry Leaders: 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!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

610 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