Autor Beitrag
Wolle92
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Mi 29.08.07 17:49 
Hallo,
ich arbeite gerade an einem Vokabel-Lernprogramm, und es gibt immer nen Fehler beim Schließen des Programms, das liegt an einer DLL... wenn ich FreeLibrary benutze, was ich erst vergessen hatte, gibts den Fehler schon vorher...
ausblenden volle Höhe 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:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
procedure TForm2.Button1Click(Sender: TObject);
var vfl, ls, buffer: String;
    f: TextFile;
    li, i: Integer;
    decode: Tcode;
    handle: THandle;
begin
  handle := LoadLIbrary(PChar(ExtractFilePath(Application.ExeName)+'crypt.dll'));
  if handle = 0 then
  begin
    ShowMessage('Erforderliche DLL crypt.dll nicht gefunden...' + #13#10 +
    'Vokabelsammlung konnte nicht geladen werden!');
    Exit;
  end;
  decode := GetProcAddress(handle, 'decode');
  vfl := ExtractFilePath(Application.ExeName) + 'lists\' + ListView1.Selected.Caption + '.vfl';
  try
    AssignFile(f, vfl);
    Reset(f);
    ReadLn(f, ls);
    li := StrToInt(decode(ls));
    SetLength(Form1.ask, li);
    SetLength(Form1.answer, li);
    for i := 0 to li - 1 do
    begin
      ReadLn(f, buffer);
      Form1.ask[i] := decode(buffer);
      ReadLn(f, buffer);
      Form1.answer[i] := decode(buffer);
    end;
    Closefile(f);
  except
    on E: EInOutError do
      ShowMessage('Fehler beim lesen der Datei! Fehler-Code: ' + IntToStr(e.ErrorCode));
  end;
  Form1.Label5.Caption := 'Aktuelle Sammlung: ' + ListView1.Selected.Caption;
  Form1.Button3.Enabled := true;
  Form2.Hide;
end;
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 29.08.07 17:53 
Der Grund könnte sein, dass du als Variable handle benutzt. So heißt ja auch die Eigenschaft, die das handle des Fensters enthält...
Zwar werden lokale Variablen bei gleichem Namen eigentlich zuerst berücksichtigt, aber darauf sollte man sich nicht einfach verlassen, sondern seine Variablen "anständig" bezeichnen.
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Mi 29.08.07 18:01 
funzt bei anderen Progs aber auch mit handle...
Und mit nem anderen namen geht auch nicht...
"Program ... raised too many consecutive exceptions ..."
Aber wenn man die DLL nicht benutzt, also sie nicht geladen wird, dann gibts auch keinen Error... der error am Ende ist auch keine Exception...
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Do 30.08.07 16:33 
Also, ich weiß jetzt, wo der Fehler ist:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
begin
  handle1 := LoadLibrary(PChar(ExtractFilePath(Application.ExeName)+'crypt.dll'));
  if handle1 = 0 then
  begin
    ShowMessage('Erforderliche DLL crypt.dll nicht gefunden...' + #13#10 +
    'Vokabelsammlung konnte nicht geladen werden!');
    Exit;
  end;
... //Verwendung der DLL-Funktionen
  Form1.Label5.Caption := 'Aktuelle Sammlung: ' + ListView1.Selected.Caption;
  Form1.Button3.Enabled := true;
  Button1.Enabled := false;
  FreeLibrary(handle1);
  Form2.Hide;
end;


Wieso es da zu "too many exceptions" kommt, weiß ich leider nicht, aber deshalb bitte ich euch ja auch um hilfe...
Biiittte..., helft mir!
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Do 30.08.07 17:59 
Ich hab noch ein andres Programm gefunden um mit meinem Kodierungs-Algo Dateien zu verschlüsseln (eher: unleserlich zu machen).
Da funktioniert alles mit dem Aufruf der DLL und dem "befreien" derselben.
Was findet Delphi so falsch daran, dass ich ne DLL wieder freigebe? Will der die für sich behalten?
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Do 30.08.07 19:14 
Ich würde das ja gerne selbst ausprobieren, aber dafür bräuchte ich die crypt.dll und deine Deklaration von Tcode...
Ich nehme an, dass der eigentliche Fehler schon viel früher auftritt, z.B. weil Tcode falsch deklariert ist (also nicht passend zur DLL). Dann könnte es nämlich Probleme mit den Speicherbereichen oder dem Stack gegeben haben vorher, was dann beim Freigeben einen Fehler verursacht.
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Do 30.08.07 19:28 
OK, im Anhang die crypt.dll
Header der Funktionen:
ausblenden Delphi-Quelltext
1:
2:
3:
function encode(text: String): String; export;
...
function decode(text: String): String; export;


Hier der exports-Teil
ausblenden Delphi-Quelltext
1:
2:
3:
exports
  encode name 'encode',
  decode name 'decode';


Typendefiniton von Tcode:
ausblenden Delphi-Quelltext
1:
type TCode = function(text: String): String;					
Einloggen, um Attachments anzusehen!
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Do 30.08.07 19:44 
Das hier könnte vielleicht helfen... ;-)
www.michael-puff.de/..._07_String_DLL.shtml
Strings in DLL-Funktionen gehen nämlich nicht so ohne weiteres. Dafür ist eigentlich PChar da...

// EDIT:
Und mir fällt gerade etwas auf:
user profile iconWolle92 hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
  decode := GetProcAddress(handle, 'decode');					

Müsste das nicht
ausblenden Delphi-Quelltext
1:
@decode := GetProcAddress(handle, 'decode');					
sein?
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Do 30.08.07 20:07 
Dir wurde übrigens schonmal nahegelegt, stdcall zu verwenden. Vielleicht liest du dir deinen Thread nochmal genau durch:
www.delphi-forum.de/viewtopic.php?t=75691

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Do 30.08.07 20:08 
Ja, das habe ich auch überlegt, ist hier aber wohl nicht das Problem, da es ja in der DLL wohl auch nicht verwendet wird.
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Fr 31.08.07 13:08 
Ha, ich hab den Fehler gefunden:
Habe in dem Programm vergessen, ShareMem einzufügen...
Endlich hab ichs!
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 01.09.07 11:21 
Dachte ichs mir doch, deshalb hab ich als ich Strings in den Funktionen gesehen habe, ja auch den Link gepostet, wo das erklärt wird. (Und wo auch die bessere Alternative ohne die Notwendigkeit, die DLL mitzugeben, gezeigt wird.)