Autor Beitrag
kachel81
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 63



BeitragVerfasst: Mo 18.10.04 15:14 
Hallo Leute,

folgendes zu meinem Problem:

Aus meiner Hauptanwendung heraus wird dynamisch eine DLL geladen, die ein Formular enthält. Wenn innerhalb des "DLL-Formulars" eine beliebige Exception auftritt und der Anwender irgendwann das DLL-Fomular schließt steigt die CPU-Auslastung der Hauptanwendung auf 100%.

Auffällig ist wie gesagt, daß dieser zustand nur dann auftritt, wenn innerhalb der DLL ein Fehler auftritt. Die Fehler werden innerhalb der DLL mit try..except..end; behandelt.

Per Debugger konnte ich feststellen, daß er sich bei der FreeLibrary-Methode "aufhängt".

Habt Ihr irgendwelche Ideen? Anbei noch die wichtigsten Snippets.

Aufruf aus Hauptanwendung
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
function Schnittstellen_Call_Execute(DLL: string; var Schnittstellen_Rec: TSchnittstellen_Rec): string;
var
  h: THandle;
  f_MitParam: Tf_MitParam;
begin
  // die DLL dynamisch laden
  h := LoadLibrary(PChar(DLL));

  // feststellen, ob das Laden erfolgreich war
  if h <> 0 then
  begin
    try
      // die Adresse der Execute-Methode holen
      @f_MitParam := GetProcAddress(h, PChar('Execute'));

      // feststellen, ob die Methode gefunden wurde
      if @f_MitParam <> nil then
      begin
        // ausfuehren
        f_MitParam(Schnittstellen_Rec);
        Application.ProcessMessages;
      end;
    finally
      // die DLL entladen
      FreeLibrary(h);
      BringWindowToTop(Application.MainForm.Handle);
    end;
  end;
end;


Tf_MitParam

ausblenden Delphi-Quelltext
1:
2:
type
  Tf_MitParam = procedure (var Schnittstellen_Rec: TSchnittstellen_Rec);


Init-Prozedur aus DLL

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure Execute(var Schnittstellen_Rec: TSchnittstellen_Rec);
var
  memHandle: THandle;
begin
  fmMyForm       := nil;
  memHandle      := Application.Handle;
  try
    Application.Handle := TApplication(Schnittstellen_Rec.Application).Handle;
    fmMyForm := TfmMyForm.Create(Schnittstellen_Rec.Application);
    fmMyForm.Schnittstellen_Rec := Schnittstellen_Rec;
    fmMyForm.ShowModal;
  finally
    if fmMyForm <> nil then
      fmMyForm.Release;
    Application.Handle := memHandle;
  end;
end;
kachel81 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 63



BeitragVerfasst: Do 21.10.04 13:04 
Wenn ich das FreeLibrary() weglasse tritt das Verhalten nicht auf. Die DLL wird dann beim Beenden der Hauptanwendung automatisch entladen. Hat jemand gegen diese Technik was einzuwenden?
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Do 21.10.04 18:49 
Ja, ich, wegen Speicherverschwendung :D

Fang lieber die Exception in der DLL ab ...

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Do 21.10.04 19:34 
Gibt schon genug Programme, die Speicherlecks verursachen.
AndyB
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1173
Erhaltene Danke: 14


RAD Studio XE2
BeitragVerfasst: Do 21.10.04 21:35 
Zitat:
ausblenden Delphi-Quelltext
1:
2:
   if fmMyForm <> nil then
      fmMyForm.Release;

Mach daraus mal schnell ein "fmMyForm.Free", denn .Release benötigt noch eine Botschaftenschleife, die du aber nicht mehr hast.

Was steckt denn in Schnittstellen_Rec noch so alles drinnen?

_________________
Ist Zeit wirklich Geld?