69 lines
1.8 KiB
ObjectPascal
69 lines
1.8 KiB
ObjectPascal
unit LLVM.Runner;
|
|
|
|
interface
|
|
|
|
uses
|
|
System.SysUtils, Winapi.Windows, System.Classes;
|
|
|
|
type
|
|
// Callback-Prozedur, die von der DLL aufgerufen wird
|
|
TLogIntegerCallback = procedure( AValue: Integer ); stdcall;
|
|
|
|
// Signatur der exportierten DLL-Funktion
|
|
TStarteLogikProc = procedure( ALogCallback: TLogIntegerCallback ); stdcall;
|
|
|
|
type
|
|
TLLVMRunner = class
|
|
private
|
|
FModule: HMODULE;
|
|
FStarteLogik: TStarteLogikProc;
|
|
class var
|
|
FLog: TStrings;
|
|
class procedure LogInteger( AValue: Integer ); static; stdcall;
|
|
public
|
|
constructor Create(const ADLLPath: string);
|
|
destructor Destroy; override;
|
|
procedure Execute;
|
|
class property Log: TStrings read FLog write FLog;
|
|
end;
|
|
|
|
implementation
|
|
|
|
{ TLLVMRunner }
|
|
|
|
constructor TLLVMRunner.Create(const ADLLPath: string);
|
|
begin
|
|
inherited Create;
|
|
FModule := LoadLibrary( PChar( ADLLPath ) );
|
|
if FModule = 0 then
|
|
raise Exception.Create( 'Failed to load DLL.' );
|
|
|
|
FStarteLogik := GetProcAddress( FModule, 'StarteLogik' );
|
|
if not Assigned( FStarteLogik ) then
|
|
raise Exception.Create( 'Procedure "StarteLogik" not found in DLL.' );
|
|
end;
|
|
|
|
destructor TLLVMRunner.Destroy;
|
|
begin
|
|
if FModule <> 0 then
|
|
FreeLibrary( FModule );
|
|
inherited;
|
|
end;
|
|
|
|
procedure TLLVMRunner.Execute;
|
|
begin
|
|
if Assigned( FStarteLogik ) then
|
|
// Führe die DLL-Funktion aus und übergebe unsere Callback-Methode
|
|
FStarteLogik( LogInteger );
|
|
end;
|
|
|
|
// Dies ist die Methode, die die DLL aufruft.
|
|
// Sie muss "static" (class procedure) sein, um eine feste Adresse zu haben.
|
|
class procedure TLLVMRunner.LogInteger( AValue: Integer );
|
|
begin
|
|
if Assigned( FLOg ) then
|
|
FLog.Add( Format( 'DLL logged integer: %d', [AValue] ) );
|
|
end;
|
|
|
|
end.
|