![]() |
WaitForSingleObject Problem
Delphi-Quellcode:
versuche auf die Fertigstellung des Programms zu warten (Console) klappt aber leider nicht
var
I: Integer; iFHandle,Process : THandle; begin iFHandle:=FileCreate(GetTempDir+'\Convert.exe'); //Holt die Exe aus nem Byte Array um nicht in den Ressourcen aufzutauchen if iFHandle<>INVALID_HANDLE_VALUE then begin if FileWrite(iFHandle,Converter,SizeOf(Converter))=SizeOf(Converter) then FileClose(iFHandle); end; // if iFHandle Err := ShellExecute(Process, 'Open', PChar('"'+GetTempDir+'\Convert.exe"'), Pchar('"'+AFileName+'"'), Pchar(ExtractFilePath(Application.Exename) ), SW_Hide); if Err > 32 then Begin if WaitForSingleObject(Process, 1000) = WAIT_OBJECT_0 then //An dieser stelle hängts // Sleep(1000); //Meine alte Lösung die auch funktioniert (könnte aber auf langsamen Rechnern Probleme machen) try Sl.Clear; Sl.LoadFromFile(AFileName); |
Re: WaitForSingleObject Problem
der 1. Parameter von shelexecute gibt nicht das Handle zu dem neuen Prozess zurück!!!
vgl PSDK du musst mit CreateProcess arbeiten. in den PROCESS_INFORMATION findest du hProcess. |
Re: WaitForSingleObject Problem
Oder mit ShellExecuteEx und dem Member hProcess von ShellExecuteInfo.
|
Re: WaitForSingleObject Problem
Benutze
![]() [edit] Kein roter Kasten... [edit] |
Re: WaitForSingleObject Problem
habs so hinbekommen
Delphi-Quellcode:
Aufruf
function TForm1.Execute: Boolean;
var SHELLINFO : TShellExecuteInfo; lpExitCode : Cardinal; begin Result := False; fillChar(SHELLINFO, SizeOf(SHELLINFO), #0); with SHELLINFO do begin cbSize := SizeOf(SHELLINFO); fMask := 64; Wnd := 0; lpVerb := nil; lpFile := PChar('"'+GetTempDir+'\Convert.exe"'); lpParameters := PChar('"'+AFileName+'"'); lpDirectory := PChar(ExtractFilePath(Application.Exename)); nShow := SW_HIDE; end; try ShellExecuteEx(@SHELLINFO); if WaitForSingleObject(SHELLINFO.hProcess, 1000) = 0 then repeat Application.ProcessMessages; GetExitCodeProcess(SHELLINFO.hProcess, lpExitCode); until (lpExitCode <> STILL_ACTIVE); Result := True; except on E:Exception do showmessage(e.Message); end; end;
Delphi-Quellcode:
var
I: Integer; iFHandle,Process : THandle; begin iFHandle:=FileCreate(GetTempDir+'\Convert.exe'); if iFHandle<>INVALID_HANDLE_VALUE then begin if FileWrite(iFHandle,Converter,SizeOf(Converter))=SizeOf(Converter) then FileClose(iFHandle); end; // if iFHandle if Execute then Begin try Sl.Clear; Sl.LoadFromFile(AFileName); Danke |
Alle Zeitangaben in WEZ +1. Es ist jetzt 21:54 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