Ich bekomme es einfach nicht hin eine DLL mit Lazarus fehlerfrei zu compilieren. Hier mal mein Quellcode:
DLL:
Code: Alles auswählen
library dll;
{$mode objfpc}{$H+}
uses
Classes,Dialogs
{ you can add units after this };
{$IFDEF WINDOWS}{$R dll.rc}{$ENDIF}
function DLLFunction(var1 : cardinal) : cardinal;
begin
Result := var1 + 10;
end;
exports DLLFunction;
end.
Code: Alles auswählen
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, Windows;
type
TDLLFUNCTION = function(var1 : cardinal) : cardinal;
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
procedure Load(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1 : TForm1;
dllHandle : THandle;
dllFunction : TDLLFUNCTION;
implementation
{ TForm1 }
procedure TForm1.Load(Sender: TObject);
begin
dllHandle := LoadLibrary(PChar(ExtractFilePath(ParamStr(0)) + '\DLL\dll.dll'));
showmessage('Geladen');
dllFunction := TDLLFUNCTION(GetProcAddress(dllHandle,'DLLFunction'));
ShowMessage(IntToStr(dllFunction(10)));
FreeLibrary(dllHandle);
showmessage('Frei');
end;
initialization
{$I unit1.lrs}
end.
Bevor ich die zwei Zeilen zum Zugriff auf die DLL-Funktion drinnen hatte, hat FreeLibrary auch mal funktioniert. Aber jetzt weiß ich nicht mehr weiter. Es kommt auch kein Fehler, oder so.
Irgendwie muss man aber doch DLLs mit Lazarus erstellen können. Ich bin ja wohl kaum der erste, der das versucht...?
Also meine Frage: Was läuft da schief?
PS: Hab' mal einen ZIP-Ordner mit dem kompletten Programm und Quellcode angehängt.