Einzelnen Beitrag anzeigen

wschrabi

Registriert seit: 16. Jan 2005
450 Beiträge
 
#1

E2033 Die Typen der tatsächlichen und formalen Var-Parameter müssen übereinstimmen

  Alt Gestern, 10:22
Hallo,
Ich Bekomme

[dcc64 Fehler] MainUnitv2k.pas(25328): E2033 Die Typen der tatsächlichen und formalen Var-Parameter müssen übereinstimmen

  Result := CreatePipe(ReadPipe, WritePipe, @SecurityAttr, 0); Ich weiß nicht Weiter.
Hier mein Code.
Wäre um jede HIlfe Dankbar.
WS


Delphi-Quellcode:
function CreateInheritablePipe(var ReadPipe, WritePipe: THandle): Boolean;
var
  SecurityAttr: TSecurityAttributes;
begin
  FillChar(SecurityAttr, SizeOf(TSecurityAttributes), 0);
  SecurityAttr.nLength := SizeOf(TSecurityAttributes);
  SecurityAttr.bInheritHandle := True;
  SecurityAttr.lpSecurityDescriptor := nil;

  Result := CreatePipe(ReadPipe, WritePipe, @SecurityAttr, 0);
end;

function Tform1.fnExecuteWSLCommand(const Command: string): string;
var
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
  SecurityAttr: TSecurityAttributes;
  myReadPipe, myWritePipe: THandle;
  Buffer: array[0..255] of AnsiChar;
  BytesRead: DWORD;
  Output: TStringList;
begin
  Result := '';
  FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
  FillChar(ProcessInfo, SizeOf(TProcessInformation), 0);
  FillChar(SecurityAttr, SizeOf(TSecurityAttributes), 0);

   SecurityAttr.nLength := SizeOf(TSecurityAttributes);
   SecurityAttr.bInheritHandle := True;
   SecurityAttr.lpSecurityDescriptor := nil;

  (*
  SecurityAttr.nLength := SizeOf(TSecurityAttributes);
  SecurityAttr.bInheritHandle := True;
  *)

  // Create pipes for capturing output
   if not CreateInheritablePipe(myReadPipe, myWritePipe) then
        RaiseLastOSError;

  try
    StartupInfo.cb := SizeOf(TStartupInfo);
    StartupInfo.dwFlags := STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW;
    StartupInfo.hStdOutput := MyWritePipe;
    StartupInfo.hStdError := MyWritePipe;
    StartupInfo.wShowWindow := SW_HIDE;

    // Prepare the WSL command
    if not CreateProcess(
      nil,
      PChar('C:\Windows\System32\wsl.exe ' + Command),
      nil,
      nil,
      True,
      CREATE_NO_WINDOW,
      nil,
      nil,
      StartupInfo,
      ProcessInfo) then
    begin
      RaiseLastOSError;
    end;

    CloseHandle(MyWritePipe); // Close the write end of the pipe

    Output := TStringList.Create;
    try
      repeat
        BytesRead := 0;
        if ReadFile(MyReadPipe, Buffer, SizeOf(Buffer) - 1, BytesRead, nil) and (BytesRead > 0) then
        begin
          Buffer[BytesRead] := #0; // Null-terminate the buffer
          Output.Add(string(Buffer));
        end;
      until BytesRead = 0;

      Result := Output.Text; // Combine all output lines into a single string
    finally
      Output.Free;
    end;

    // Wait for the process to finish and clean up
    WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
    CloseHandle(ProcessInfo.hProcess);
    CloseHandle(ProcessInfo.hThread);
    
  finally
    CloseHandle(MyReadPipe); // Close the read end of the pipe
  end;
end;
  Mit Zitat antworten Zitat