我目前正在研究一些插件概念,并且在我研究使用 dll 或 BPls 的过程中遇到了,我现在决定使用 bpls。
我想知道什么时候必须使用 UnloadPackage(包模块);最好的视图,因为加载后立即给我带来什么,因为形状然后立即消失
当前的程序结构
Hostapplication(PackageLoader.exe)
|_Plugin.bpl
|_TPluginForm
包加载器.exe
var
PackageModule : hModule;
createProc: Procedure;
begin
// Package laden
try
PackageModule := LoadPackage('plugin.bpl');
If PackageModule <> 0 then
begin
@createProc := GetProcAddress( PackageModule, 'CreatePluginForm' ); // Funktion aus den Exports aufrufen
if Assigned(CreateProc) then
CreateProc
else
ShowMessage('GetProcAddress failed');
end;
finally
//UnloadPackage(PackageModule);
end;
end;
plugin.bpl - uPlugin.pas
unit uPlugin;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TPluginForm = class(TForm)
Memo1: TMemo;
Panel1: TPanel;
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
PluginForm: TPluginForm;
Status: Boolean;
implementation
uses
uRandomString;
{$R *.dfm}
procedure TPluginForm.Button1Click(Sender: TObject);
var
User, pwd, mail: String;
ul, pl, ml: Integer;
begin
Status := True;
ul := StrToInt(Edit1.Text);
pl := StrToInt(Edit2.Text);
// ml := StrToInt(Edit3.Text);
while Status do
begin
Application.ProcessMessages;
User := RandomString(ul);
pwd := RandomString(pl);
//mail := RandomString(ml) + '@' + RandomString(5)+'.de';
Memo1.Lines.Add(User+':'+pwd); //+':'+mail);
end;
end;
procedure TPluginForm.Button2Click(Sender: TObject);
begin
Status := False;
end;
function CreatePluginForm(ApplicationHandle, ParentHandle: THandle): boolean;
begin
Result := False;
PluginForm := TPluginForm.Create(nil);
try
PluginForm.Show;
//PluginForm.ShowModal;
finally
end;
end;
exports
CreatePluginForm;
initialization
RegisterClass(TPluginForm);
finalization
UnRegisterClass(TPluginForm);
end.