g_hRun : HWND;
lpExitCode : LPDWORD;
GetExitCodeProcess(g_hRun, lpExitCode);
[Error] total.pas(220): Types of actual and formal var parameters must be identical

解决方案 »

  1.   

    如下:
    function GetExitCodeProcess(hProcess: THandle; var lpExitCode: DWORD): BOOL; stdcall;function GetExitCodeProcess; external 'kernel32.dll' name 'GetExitCodeProcess';其实这些都声明在 Windows 单元中了,我也只是 Copy 而已 :)
      

  2.   

    hproc: THandle;
    dExitCode : DWORD;
    GetExitCodeProcess(hproc, dExitCode);
      

  3.   

    哦,对了,怎么得不到进程的返回值??? 返回是0,GETLASTERROR 返回也是0进程是用SHELLEXECUTE函数创建的
      

  4.   

    那是因为对方程序设置的退出码是 0 ,一般 0 ,表示正常退出,退出码是由对方程序设置的,不是操作系统。
    GETLASTERROR=0 表示没有发生错误 
      

  5.   

    后来发现好像不能得到进程句柄,
    g_hRun := ShellExecute(
             Application.MainForm.Handle,
        nil,
                'gl.exe',
                PChar(g_sUserAndPwd),
                nil,
                SW_MAXIMIZE);
    得到的句柄好像无效。
      

  6.   

    ShellExecute Return Values:
    If the function succeeds, the return value is the instance handle of the application that was run, or the handle of a dynamic data exchange (DDE) server application.GetExitCodeProcess hProcess
    Identifies the process. 
    Windows NT: The handle must have PROCESS_QUERY_INFORMATION access. For more information, see Process Objects你传入 GetExitCodeProcess 的 hProcess 参数不对在这种情况下我是用 CreateProcess 代替 ShellExecute 的。
      

  7.   

    看来要你的分也不容易呀(开个玩笑) :)var
      suInfo: TStartupInfo;
      procInfo: TProcessInformation;
      xCode: DWORD;
      errMsg, cmd: string;
    begin
      FillChar(suInfo, Sizeof(TStartupInfo), #0);
      with suInfo do begin
        dwFlags := STARTF_USESHOWWINDOW;
        wShowWindow := SW_Hide;
        lpReserved := nil;
        lpDesktop := nil;
        lpTitle := nil;
        cbReserved2 := 0;
        lpReserved2 := nil;
        cb := sizeof(TStartupInfo);
      end;
      cmd := 'c:\windows\command\cmd.exe';
      if CreateProcess(nil, pchar(cmd), nil, nil, False,
            CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASs, nil, nil,
            suInfo, procInfo) then begin
      if GetExitCodeProcess(procInfo.hProcess, xCode) then begin
        if xCode<>0 then begin
          Application.MessageBox(pchar(' 呀哈!!') ,'出错',MB_ICONSTOP);
        else
          errMsg := '  GetExitCodeProcess failed.'+#13#10+'错误:'+SysErrorMessage(GetLastError)
      end
      else
        errMsg := '  建立进程失败。'+#13#10+'错误:'+SysErrorMessage(GetLastError);