unit MainF;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Menus, ActnList, interfaces, filefinder, inifiles;
type
TForm1 =
class(TForm)
MainMenu1: TMainMenu;
Programm1: TMenuItem;
Beenden1: TMenuItem;
Plugin1: TMenuItem;
ActionList1: TActionList;
Action1: TAction;
Memo1: TMemo;
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Beenden1Click(Sender: TObject);
procedure Action1Execute(Sender: TObject);
private
// app: IApp;
hDLL : HWND;
iPlg: IPlugin;
iPlgForm : IPluginForm;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
AktDll : Integer;
ProgDir :
String;
LibDir :
String;
implementation
{$R *.DFM}
procedure TForm1.Action1Execute(Sender: TObject);
type
TProcInitPlg =
function(PApp: TApplication; PForm: TForm): IPluginForm;
stdcall;
var fProc: TProcInitPlg;
begin
@fProc := GetProcAddress(hDLL, '
RunPlugin');
if fProc(Application,Form1) <>
nil then
begin
iPlgForm := fProc(Application,Form1);
end;
end;
procedure TForm1.Beenden1Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.FormCreate(Sender: TObject);
type
TProcInitPlg =
function: IPlugin;
stdcall;
var
fProc: TProcInitPlg;
New_Entry_Plugin : TMenuItem;
begin
ProgDir := extractfilepath(paramstr(0));
LibDir := copy(ProgDir,0,Pos('
bin',ProgDir)-1) + '
lib\';
messageDlg('
folgender Pfad wird durchsucht : ' + LibDir, mtInformation, [mbOK],0);
Memo1.Lines := FindPlugins(LibDir);
// Bibliothek laden und Interface holen
messageDlg('
Versuche folgende DLL zu laden : ' + LibDir + Memo1.Lines[0], mtInformation, [mbOK],0);
hDll := LoadLibrary(PCHAR(libdir + Memo1.Lines[0]));
@fProc := GetProcAddress(hDLL, '
InitPlugin');
if fProc <>
nil then
begin
iPlg := fProc;
New_Entry_plugin := TMenuItem.Create(self);
Action1.Caption := PCHAR(iPlg.GetName);
New_Entry_Plugin.Action := Action1;
Plugin1.Add(New_Entry_Plugin);
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
var i : Integer;
begin
// PlugIn zerstören
iplg :=
nil;
iPlgForm :=
nil;
// Bibliothek entladen
FreeLibrary(hDLL);
// Application-Interface zerstören
// app := nil;
end;
end.