AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi Probleme mit WaitForSingleObject
Thema durchsuchen
Ansicht
Themen-Optionen

Probleme mit WaitForSingleObject

Ein Thema von Doktor Ruff · begonnen am 21. Dez 2006 · letzter Beitrag vom 22. Dez 2006
Antwort Antwort
Doktor Ruff

Registriert seit: 10. Okt 2006
8 Beiträge
 
#1

Probleme mit WaitForSingleObject

  Alt 21. Dez 2006, 15:32
Ich rufe mit Hilfe von ShellExecuteEx den Standardbrowser auf und warte danach auf dessen Beendigung. Das ShellExecute funktioniert auch soweit nur leider liefert mir die Funktion WaitForSingleObject einen komischen Wert (8-stellige Zahl) und dieser ändert sich auch nicht wenn ich den Browser wieder schließe, sprich den Prozess beende. Irgendwo liegt in meinem Code also der Hund begraben oder ich hab da was falsch verstanden.

Delphi-Quellcode:
var
  SHELLINFO : TShellExecuteInfo;
begin
  with SHELLINFO do
  begin
    cbSize := SizeOf(SHELLINFO);
    fMask := SEE_MASK_NOCLOSEPROCESS;
    Wnd := 0;
    lpVerb := PChar('open');
    lpFile := PChar(startHTML);
    lpParameters := nil;
    lpDirectory := nil;
    nShow := SW_SHOWNORMAL;
// hInstApp := 0;
  end;
  try
    ShellExecuteEx(@SHELLINFO);
    repeat
      Application.ProcessMessages;
// showMessage(IntToStr(WaitForSingleObject(SHELLINFO.hProcess, 1000));
    until (WaitForSingleObject(SHELLINFO.hProcess, 1000) = WAIT_TIMEOUT);
    showMessage('Blob');
  except
    on E:Exception do showmessage(e.Message);
  end;
end;
  Mit Zitat antworten Zitat
Benutzerbild von RavenIV
RavenIV

Registriert seit: 12. Jan 2005
Ort: Waldshut-Tiengen
2.875 Beiträge
 
Delphi 2007 Enterprise
 
#2

Re: Probleme mit WaitForSingleObject

  Alt 21. Dez 2006, 15:46
aus der MSDN:
Code:
Return Value

If the function succeeds, the return value indicates the event that caused the function to return. It can be one of the following values.
Return code/value    Description
WAIT_ABANDONED
0x00000080L    The specified object is a mutex object that was not released by the thread that owned the mutex object before the owning thread terminated. Ownership of the mutex object is granted to the calling thread, and the mutex is set to nonsignaled.

If the mutex was protecting persistent state information, you should check it for consistency.
WAIT_OBJECT_0
0x00000000L    The state of the specified object is signaled.
WAIT_TIMEOUT
0x00000102L    The time-out interval elapsed, and the object's state is nonsignaled.

If the function fails, the return value is WAIT_FAILED ((DWORD)0xFFFFFFFF). To get extended error information, call GetLastError.
dies könnte doch der 8-Stellige Wert sein, oder?
am besten benutzt Du zum Abfragen des Ergebnisses die Konstanten und nicht den Wert.
Die Konstanten sind definiert in der Windows.pas.
Klaus E.
Linux - das längste Text-Adventure aller Zeiten...
Wer nie Linux mit dem vi konfiguriert hat, der hat am Leben vorbei geklickt.
  Mit Zitat antworten Zitat
Benutzerbild von thkerkmann
thkerkmann

Registriert seit: 7. Jan 2006
Ort: Pulheim Brauweiler
464 Beiträge
 
Delphi 2010 Professional
 
#3

Re: Probleme mit WaitForSingleObject

  Alt 21. Dez 2006, 16:05
Hi,

versuchs mal so:

Delphi-Quellcode:
function tForm1.WinExecAndWait32(const Path: string; Visibility: Word): Boolean;
var
  lpExitCode: Cardinal;
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
  bIsSetup: boolean;
  iCnt: integer;
  iFind: integer;
begin
  bIsSetup := pos('setup.exe', lowercase(path)) > 0;
  { clear StartupInfo }
  FillChar(StartupInfo, SizeOf(TStartupInfo), 0);

  { enter startup information }
  with StartupInfo do
  begin
    cb := SizeOf(TStartupInfo);
    dwFlags := STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
    wShowWindow := visibility; {you could pass sw_show or sw_hide as parameter}
  end;

  { create new process }
  if CreateProcess(nil, pChar(path), nil, nil, False, NORMAL_PRIORITY_CLASS,
    nil, nil,
    StartupInfo, ProcessInfo) then
  begin
    { sucess }
    WaitForInputIdle(ProcessInfo.hProcess, 3000);
    { wait until application finished }
    repeat { until lpExitCode <> Still_Active }
      sleep(0);
      application.processmessages;
      GetExitCodeProcess(ProcessInfo.hProcess, lpExitCode);
    until lpExitCode <> Still_Active;

    with ProcessInfo do
      {not sure this is necessary but seen in in some code elsewhere}
    begin
      CloseHandle(hThread);
      CloseHandle(hProcess);
    end; { with ProcessInfo do }

end;
Das verwende ich schon lange und es funktioniert sehr zuverlässig.

Gruss
Thomas Kerkmann
Ich hab noch einen Koffer in Borland.
http://thomaskerkmann.wordpress.com/
  Mit Zitat antworten Zitat
alzaimar
(Moderator)

Registriert seit: 6. Mai 2005
Ort: Berlin
4.956 Beiträge
 
Delphi 2007 Enterprise
 
#4

Re: Probleme mit WaitForSingleObject

  Alt 21. Dez 2006, 17:07
Und wenn du schon per WaitForSingleObject auf etwas wartest, dann besagt der Wert 'WAIT_TIMEOUT', das WFSO innerhalb der angegebenen Zeit keine Rückmeldung vom Objekt bekommen hat-sprich: Dat Teil is noch nich fettich. Du müsstest warten, bis 'WAIT_OBJECT0' zurückkommet (oder ist das WAIT_OBJECT_0 )
"Wenn ist das Nunstruck git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput!"
(Monty Python "Joke Warefare")
  Mit Zitat antworten Zitat
Doktor Ruff

Registriert seit: 10. Okt 2006
8 Beiträge
 
#5

Re: Probleme mit WaitForSingleObject

  Alt 22. Dez 2006, 08:17
Ich hab meinen Code mal so umgebaut, dass ich mit GetExitCodeProcess auf das Beenden warte, aber irgendwie springt er sofort aus der Schleife raus. Ich habe die Befürchtung, dass es an meinem ShellExecuteEx liegt. Damit führe ich ja lediglich eine Kommandozeile aus.

So sieht das jetzt genau aus:
Delphi-Quellcode:
var
  SHELLINFO : TShellExecuteInfo;
  lpExitCode : Cardinal;
begin
  // fillChar(SHELLINFO, SizeOf(SHELLINFO), #0);

  with SHELLINFO do
  begin
    cbSize := SizeOf(SHELLINFO);
    fMask := SEE_MASK_NOCLOSEPROCESS;
    Wnd := 0;
    lpVerb := nil;
    lpFile := PChar('explorer');
    lpParameters := PChar(startHTML);
    lpDirectory := nil;
    nShow := SW_SHOWNORMAL;
  end;
  try
    ShellExecuteEx(@SHELLINFO);

    WaitForInputIdle(SHELLINFO.hProcess, 3000);

    repeat
      Sleep(0);
      Application.ProcessMessages;
      showMessage(IntToStr(SHELLINFO.hProcess));
      GetExitCodeProcess(SHELLINFO.hProcess, lpExitCode);
    until (lpExitCode <> STILL_ACTIVE);
    showMessage('Blob');
  except
    on E:Exception do showmessage(e.Message);
  end;
end;
Kann ich denn auch mit CreateProcess den Standardbrowser aufrufen?
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 08:03 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz