Thema: Delphi DLL Auslesen

Einzelnen Beitrag anzeigen

Benutzerbild von XXcD
XXcD

Registriert seit: 19. Sep 2006
581 Beiträge
 
Delphi 2007 Professional
 
#1

DLL Auslesen

  Alt 13. Jun 2009, 14:42
Hallo,
ich schreibe momentan an einem Programm dass durch DLL Datein erweitert werden kann.
Die DLLs sollen kleine Module sein.

Meine DLL sieht folgendermaßen aus(testdll.dll):
Delphi-Quellcode:
library testdll;

uses
  SysUtils,
  Classes,
  Forms;

  type
  TInformationen = class
    FVersion : String;
    FName : String;
    FDescription: string;
  end;

{$R *.res}

function DLLInformationen: TInformationen; stdcall;
var
Informationen: TInformationen;
begin
Informationen:= TInformationen.Create;
Informationen.FVersion:='1.0';
Informationen.FName:='First Modul';
Informationen.FDescription:='Kleine beschreibung';
Result:=Informationen;
end;

exports DLLInformationen;

begin
end.

Und so die Unit zum Auslesen der DLL(Modul_functions.pas):
Delphi-Quellcode:
uses
windows, SysUtils;

  type
  TInformationen = class
    private
    FVersion : String;
    FName : String;
    FDescription: string;
    FSettings: boolean;
    FVisible: boolean;
    public
    property Version: string read FVersion;
    property Name: string read FName;
    property Description: string read FDescription;
    property Settings: boolean read FSettings;
    property Visible: boolean read FVisible;
  end;

type
  TGetInformations = function: TInformationen; stdcall;
  function ModulInformationen: TInformationen;

implementation

function ModulInformationen: TInformationen;
var GetInformations: TGetInformations;
    Handle: THandle;
begin
  Handle:=LoadLibrary(PChar(ExtractFilePath(ParamStr(0))+'\Module\testdll.dll'));
  if Handle <> 0 then begin
    @GetInformations := GetProcAddress(Handle, 'DLLInformationen');
    if @GetInformations <> nil then begin
      result := GetInformations;
    end;
    FreeLibrary(Handle);
  end;
end;

end.

Und so der Aufruf in dem Formular:
Delphi-Quellcode:
uses
Modul_functions;
...
var
Informationen: TInformationen;
begin
Informationen:=ModulInformationen;
Showmessage(Informationen.Version+' | '+Informationen.Name);
Ich bin jetzt seit Stunden am suchen aber ich finde den Fehler einfach nicht.
Ich habe das genauso gemacht wie bei Delphi Treff in den TuTs
  Mit Zitat antworten Zitat