![]() |
function WinExecAndWait32
Hallo Leute!
Ich bekomme eine Fehler: [Error] Main.pas(57): Types of actual and formal var parameters must be identical was mach ich falsch?
Code:
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); <------------------------Fehler 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; Peter Kiers |
Re: function WinExecAndWait32
Hallo,
dein Result ist ein Integer- Typ der auch negativ sein kann und die Funktion GetExitCodeProcess() erwartet als 2. Parameter den Typ cardinal. Wenn Result unbedingt -1 sein soll könnte man es auch so machen:
Delphi-Quellcode:
Ansonsten muss deine Funktion eben eine Wert vom Typ Cardinal zurückgeben, der kann dann aber nicht negativ sein.
function WinExecAndWait32(FileName: string; Visibility: integer): Int64;
var zAppName: array[0..512] of char; zCurDir : array[0..255] of char; WorkDir : string; StartupInfo: TStartupInfo; ProcessInfo: TProcessInformation; ExitCode: cardinal; 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, ExitCode); Result:= ExitCode; end; end; |
Re: function WinExecAndWait32
Danke viel mals.
Peter Kiers |
Re: function WinExecAndWait32
Ich habe das Beispiel von bitsetter übernommen und die übergebene .exe wird soweit auch korrekt ausgeführt.
Nur, wie kann ich das Resultat (Den Rückgabewert oder ERRORLEVEL) der .exe auslesen? Ich dachte eigentlich, das dies durch
Delphi-Quellcode:
Als Ergebnis der function zurückgemeldet wird, aber bei mir erhalte ich immer 0.
Result:= ExitCode;
Danke schon mal für die Hilfe :thumb: |
Re: function WinExecAndWait32
In der Delphi Hilfe unter dem Wort HALT (Procedure) steht
Zitat:
Oder vlt tue ich gerade etwas falsch aber ich hab nochmal gegoogelt und fand Oder du meinst das, das kann auf die beendigung warten Zitat:
|
Re: function WinExecAndWait32
Hallo und besten Dank für die schnelle Antwort.
"Halt" bezieht sich auf meine eigene Applikation. Dies würde also einen Exitcode bei der Beendigung meiner Applikation erzeugen. Was ich benötige ist die Möglichkeit, eine fremde .exe zu starten und deren Exitcode zu erhalten resp. auszuwerten. Hat sonstwer weitere Informationen? |
Re: function WinExecAndWait32
Zitat:
Falls die fremde exe von dir ist und in Delphi geschrieben wurde, so kannst du den Rückgabewert über...
Delphi-Quellcode:
zuweisen.
Exitcode:=1;
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 13:33 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz