Autor Beitrag
Willie1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32

Win 98 SE, Win XP Home
Delphi 5 Prof., Delphi 6/7 Pers.
BeitragVerfasst: So 05.03.06 19:49 
Hallo Leute,

eine Frage zu DLL's.

Folgende Funktion will ich eine DLL einbinden: (simples Beispiel)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
function IsCDROM(L: PChar): Boolean; stdcall;
begin
  Result := GetDriveType(PChar(L + ':\')) = DRIVE_CDROM;
end;


Wenn ich diese Funktion aus der DLL statisch einbinde, ist alles in Ordnung, wenn ich sie dynamisch einbinden will, ist das Ergebnis falsch. Ich habe mit dem Debugger festgestellt, dass bei dynmischer Einbindung für L Unsinn übergeben wird. Wie die dynamische Einbindung funktioniert, weiß ich und klappt sonst auch nur bei Parametern vom Typ PChar gibt es Probleme. Weiß jemand warum?

MfG
Willie1

Moderiert von user profile iconAXMD: Delphi-Tags hinzugefügt
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 05.03.06 21:44 
user profile iconWillie1 hat folgendes geschrieben:
Wie die dynamische Einbindung funktioniert, weiß ich und klappt sonst auch nur bei Parametern vom Typ PChar gibt es Probleme. Weiß jemand warum?

anscheinden doch nicht, sonst würdest du nicht fragen. Wie rufst du sie denn auf? Und reservierst du auch speicher für die Variable? Aber das ist alles nur Rumgerate.
Willie1 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32

Win 98 SE, Win XP Home
Delphi 5 Prof., Delphi 6/7 Pers.
BeitragVerfasst: Mo 06.03.06 09:03 
Titel: DLL statisch u. dynamisch
Zitat:
Aber das ist alles nur Rumgerate

Du irrst!
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
type
  TisCDROM = function(L: PChar): Boolean;
var
  HH: THandle;
...
procedure TForm1.FormCreate(Sender: TObject);
var
  FisCDROM: TIsCDROM;
begin
  HH:=LoadLibrary('SystemWA32.dll');
  @FIsCDROM:=GetProcAddress(HH,'IsCDROM');
  if @FIsCDROM <> nil then begin
    ShowMessage('"G" ist CD-Rom '+ BoolToStr(FIsCDROM('G'),true));
    Label1.Caption:='"C" ist CD-Rom '+ BoolToStr(FIsCDROM('C'),true);
  end;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  FreeLibrary(HH)
end;


Willie1

Moderiert von user profile iconAXMD: Code- durch Delphi-Tags ersetzt
Tastaro
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 414
Erhaltene Danke: 23



BeitragVerfasst: Mo 06.03.06 09:07 
Probiers mal so:

ausblenden Delphi-Quelltext
1:
2:
type  
   TisCDROM = function(L: PChar): Boolean;  stdcall;


Beste Grüße
Tastaro