Hi everybody,

I have this procedure for launching an application and wait
for it to finish, but I get an error:

[Error] Main.pas(57): Types of actual and formal var parameters must be identical

What do I do wrong? Who can help me?

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 { pointer to PROCESS_INF } 
    Result := -1 
  else 
    begin 
      WaitforSingleObject(ProcessInfo.hProcess, INFINITE); 
      GetExitCodeProcess(ProcessInfo.hProcess, Result);   <-----Error 
    end; 
end;
 
procedure TForm1.Button1Click(Sender: TObject); 
var 
  sBatchFileName: String; 
begin 
  sBatchFileName := 'c:\SAY.bat'; 
  if FileExists(SBatchFileName) then 
  begin 
    WinExecAndWait32(sBatchFileName, SW_HIDE); 
  end; 
end;

Greetings,

Peter Kiers

Hi everybody,

I have this procedure for launching an application and wait
for it to finish, but I get an error:

[Error] Main.pas(57): Types of actual and formal var parameters must be identical

What do I do wrong? Who can help me?

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); 
  ...
    begin 
      WaitforSingleObject(ProcessInfo.hProcess, INFINITE); 
      GetExitCodeProcess(ProcessInfo.hProcess, Result);   <-----Error 
    end; 
end;
 
...

Just look at this from help:
BOOL GetExitCodeProcess(
HANDLE hProcess, // handle to the process
LPDWORD lpExitCode // address to receive termination status
);

Did you perceived? Your funtion result is declared Integer, but GetExitCodeProcess expected by a DWORD param (in the true, LPDWORD). So, just change return type from Integer to Longword.

bye.

Just extending my last post...
The observation in jwenting's post #4 is true. In this case, we have only to put "@" char before variable:
GetExitCodeProcess(ProcessInfo.hProcess, @Result);But, my answer was based in Delphi 7, where function's declaration (in Windows.pas unit) the parameter is declarede like Var reference to DWord - not PDWord:

function GetExitCodeProcess(hProcess: THandle; var lpExitCode: DWORD): BOOL; stdcall;

Bye

This article has been dead for over six months. Start a new discussion instead.