I have the follow function that creates a process:
function .CreateProcess(aAppletPath: string; var aError : string; aProcessInfo: TProcessInformation): Boolean;
var
StartInfo: TStartupInfo;
begin
FillChar(StartInfo, SizeOf(TStartupInfo),#0);
FillChar(aProcessInfo, SizeOf(TProcessInformation),#0);
StartInfo.cb := SizeOf(TStartupInfo);
if False then begin
StartInfo.dwFlags := STARTF_USESHOWWINDOW;
StartInfo.wShowWindow := SW_HIDE;
end;
if Windows.CreateProcess(nil, PChar(aAppletPath), nil, nil, False, CREATE_NEW_PROCESS_GROUP + NORMAL_PRIORITY_CLASS, nil, nil, StartInfo, aProcessInfo) then begin
Result := True;
WaitForInputIdle(aProcessInfo.hProcess, oTimeOutSecs * 1000);
end
else begin
Result := False;
end;
end;
And I have this method that waits the app terminates:
function WaitForProcessTerminate(aHandle: THandle) : Boolean;
var
vResult : LongWord;
Msg: TMsg;
PHandles: Pointer;
begin
vResult := 0;
PHandles := @aHandle;
PeekMessage(Msg, 0, 0, 0, PM_NOREMOVE);
while True do begin
vResult := Windows.MsgWaitForMultipleOb开发者_StackOverflow社区jects(1, PHandles^, False, oTimeOutSecs * 1000, QS_ALLINPUT);
if vResult = WAIT_OBJECT_0 + 1 then begin
if PeekMessage(Msg, 0, 0, 0, PM_REMOVE) then begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end
else begin
Break;
end;
end;
case vResult of
WAIT_ABANDONED: Result := False;
WAIT_OBJECT_0: Result := True;
WAIT_TIMEOUT: Result := False;
else begin
Result := False;
end;
end;
if not Result then begin
ShowMessage(SystemErrorMessage);
end;
end;
The problem is that the wait function is always returning WAIT_FAILED
with the Access denied
message. What am I doing wrong? This code is Delphi 2010 and the app i am calling is a java app.
Nevermind guys. It was my mistake. The function:
function .CreateProcess(aAppletPath: string; var aError : string; aProcessInfo: TProcessInformation): Boolean;
should be:
function .CreateProcess(aAppletPath: string; var aError : string; var {should be var!!} aProcessInfo: TProcessInformation): Boolean;
My apologies.
精彩评论