mailto:in...@ligonet.ch
The initialisation code for lpstartupinfo can be replace with a 'ZeroMemory'
call (I think)
var lpProcessInformation: TProcessInformation;
lpStartupInfo : TStartupInfo;
r:integer;
with lpStartupInfo do
begin
cb:=0;
lpReserved:=nil;
lpDesktop:=nil;
lpTitle:=nil;
dwX:=0;
dwY:=0;
dwXSize:=0;
dwYSize:=0;
dwXCountChars:=0;
dwYCountChars:=0;
dwFillAttribute:=0;
dwFlags:=STARTF_USESHOWWINDOW;
wShowWindow:=SW_NORMAL;
cbReserved2:=0;
lpReserved2:=nil;;
hStdInput:=0;
hStdOutput:=0;
hStdError:=0;
end;
if
CreateProcess('aprogram.exe','',nil,nil,false,0,nil,nil,lpStartupInfo,lpProcessInformation)
then
repeat
GetExitCodeProcess(lpProcessInformation.hprocess,r);
application.processmessages;
until Application.Terminated or (r <> STILL_ACTIVE);
Use ExitProcess to terminate a process and use the GetExitCodeProcess function
to retrieve the process's exit value
>Does anybody know how to use ExitProcess function?
Yes, but why do you want to use it? In Delphi, you can just call
Halt(ExitCode);
for the same effect. ExitCode can be any integer value. But, it's
usually not a good idea to terminate your program this way, unless
you're sure that all necessary cleanup operations have been performed.
-Steve
>var lpProcessInformation: TProcessInformation;
> lpStartupInfo : TStartupInfo;
> r:integer;
[SNIP]
> GetExitCodeProcess(lpProcessInformation.hprocess,r);
I get an error at this point.
(85) "Types of actual and formal var parameters must be identical".
Ideas?
Kim Robert Blix
>> GetExitCodeProcess(lpProcessInformation.hprocess,r);
>I get an error at this point.
>
>(85) "Types of actual and formal var parameters must be identical".
allow me to rephrase that. I do get the error, but it compiles ok when I
change "r" to doubleword rather than use integer. BUT, it still hangs when
the program I execute generate a second window. There has got to be away
around this problem.. I've been searching ofr solutions but so far -nothing-
has
worked, and Im getting a little depressed here :)
Take care,
Kim Robert Blix
Actually I used that code an it works, on NT4. Pay attention on the parameters
for CreateProcess, it may be some difference in the specifications of
application name and parameters.
When you say it hangs what do u mean, you don't have acces to the second window
at all? I ask you that because u cannot have acces to the main program until u
close the second window.
See U :)
Bogdan