MsgWaitForMultipleObjects返回拒绝访问

时间:2011-06-14 19:23:25

标签: delphi winapi wait

我有跟随函数创建一个过程:

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;

我有这种等待应用程序终止的方法:

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.MsgWaitForMultipleObjects(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;

问题是wait函数总是返回带有WAIT_FAILED消息的Access denied。我究竟做错了什么?这段代码是Delphi 2010,我调用的应用程序是一个java应用程序。

1 个答案:

答案 0 :(得分:3)

没关系。这是我的错。功能:

function .CreateProcess(aAppletPath: string; var aError : string; aProcessInfo: TProcessInformation): Boolean;

应该是:

function .CreateProcess(aAppletPath: string; var aError : string; var {should be var!!} aProcessInfo: TProcessInformation): Boolean;

道歉。