Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi sporadische EOleException Fehler in quasi nonvcl (https://www.delphipraxis.net/196851-sporadische-eoleexception-fehler-quasi-nonvcl.html)

jus 25. Jun 2018 14:48

sporadische EOleException Fehler in quasi nonvcl
 
Liste der Anhänge anzeigen (Anzahl: 1)
Hallo,

ich habe mir vor einiger Zeit ein kleines Programm gebastelt, dass auf Klick einen Verzeichniswechel beim Windows Explorer erzwingt. Dazu frage ich im Programm ab, ob ein Verzeichnis Parameter mitgegben wurde oder nicht. Wenn ja wird umgehend die Verzeichniswechselroutine für Windows Explorer ausgeführt, sonst kommt stattdessen eine GUI.
Leider funktioniert die Routine nach einiger Zeit auf manchen Rechner nicht mehr. Es kommt dann folgende Fehlermeldung:
Code:
---------------------------
Anwendungsfehler
---------------------------
Exception Exception EOleExceptionException EOleExceptionException EOleException in Modul Project1.exe bei 000887CE.
Unbekannter Fehler.
---------------------------
OK  
---------------------------
Wenn ich den Rechner neustarte, dann funktioniert das wieder, bis nach paar Stunden es wieder nicht mehr geht. :-(

Ich habe das komplette Testprojekt angehängt. Anbei der wichtigste Part:
Delphi-Quellcode:
program Project1;

uses
  Forms,
  Windows,
  SysUtils,
  SHDocVw,
  ActiveX,
  Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

procedure SwitchExplorerDirectory;
var
  ShellWindows: IShellWindows;
  i: Integer;
  ClName: array[0..64]of Char;
  Pfad: AnsiString;
  wnd: hwnd;
  WndIface: IDispatch;
  WebBrowserApp: IWebBrowserApp;

begin
  ShellWindows := CoShellWindows.Create;
  if ShellWindows = nil then
  begin
    OutputDebugString(PChar('Fehler: "ShellWin = nil"'));
    exit;
  end;

  for i := 0 to ShellWindows.Count-1 do
  begin
    OutputDebugString(PChar(IntToStr(i)));
    WndIface := ShellWindows.Item(i);
    if Assigned(WndIface) then
    begin
      if Succeeded(WndIface.QueryInterface(IID_IWebBrowserApp, WebBrowserApp)) then
      begin
        OutputDebugString(PChar('WebBrowserApp.hwnd('+IntToStr(WebBrowserApp.hwnd)+')')); // <------HIER kommt der Fehler!!!!
      end
      else OutputDebugString(PChar(IntToStr(i)+': has no IID_IWebBrowserApp interface!'));
    end
    else OutputDebugString(PChar(IntToStr(i)+': "WndIface" not assigned!'));
  end;
end;

begin
 if ParamCount>0 then
  begin
    if not (SUCCEEDED(CoInitializeEx(NIL, COINIT_APARTMENTTHREADED or COINIT_DISABLE_OLE1DDE))) then
    begin
      OutputDebugString(PChar('Fehler: "CoInitializeEx" konnte nicht initialisiert werden!'));
      halt;
    end;

    SwitchExplorerDirectory;

    CoUninitialize;
  end
  else
  begin
    Application.Initialize;
    Application.MainFormOnTaskbar := True;
    Application.CreateForm(TForm1, Form1);
    Application.Run;
  end;
end.
Genaugenommen wird ein Exception ausgelöst, wenn man das Handle vom Explorer Fenster (WebBrowserApp.hwnd) abfragen möchte.

Ich bin irgendwie am Verzweifeln, warum es nach einiger Zeit nicht mehr funktioniert. Hat jemand so Idee woran es liegen könnte? :gruebel:

lg,
jus


Alle Zeitangaben in WEZ +1. Es ist jetzt 08:25 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