送你一段程序:
{插件功能}
unit Func_DLL;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;
type
{定义接口函数类型}
TplugShow = function(AHandle:THandle
ACaption:string):Boolean
Stdcall;
TplugName = function
char
StdCall;
plugFail = class(Exception);
{定义TTestPlugIn类,存放caption,Address,call等信息}
TplugInfo = class
Name :string
{存取加载后,GetCaption返回的标题}
Addr :THandle
{存取加载DLL的句柄}
Call
ointer
{存取ShowDLLForm函数句柄}
end;
var
plugShow :TplugShow;{声明接口函数类型}
plugList :TList
{存放每一个DLL加载后的相关信息}
{------------------------------------------------------------------------------}
{载入插件}procedure PlugIns_Load;
{执行插件}procedure PlugIns_Exec(const intplug :integer);
{释放插件}procedure PlugIns_Free;
{------------------------------------------------------------------------------}
implementation
procedure PlugIns_Load;
function fileQuery(const currDir,currExt:string):string;
var
recFile :TSearchRec;
strTemp :string;
FlgTemp :Integer;
begin{返回指定目录下指定扩展名的文件列表}
result := '';
strTemp := currDir+currExt;
FlgTemp := FindFirst(strTemp, faAnyFile, RecFile);
while (FlgTemp=0) do
begin
if(RecFile.Attr and faDirectory =0) then
result := result +recFile.Name+#13#10;
FlgTemp := FindNext(recFile);
end;
FindClose(recFile);
end;
{000000000000000000000000000000000000000000000000000000000000000000000000000000}
var
intLoop :Integer;
strList :TStrings;
PluRecd :TplugInfo;
pluName :TplugName;
begin{加载插件}
strList := TStringList.Create;
try
plugList := TList.Create;
//查找指定目录下的.dll文件,并存于strList对象中
strList.Text := fileQuery(ExtractFilepath(Application.Exename), '*.dll');
//加载查找到的DLL
for intLoop:=0 to strList.Count-1 do
begin
if(strList[intLoop] = '') then continue;
PluRecd := TplugInfo.Create;
PluRecd.Addr := LoadLibrary(PChar(strList[intLoop]));
if PluRecd.Addr = 0 then
begin
showMessage(format('插件:%s'#$D'装载失败!',[strList[intLoop]]));
continue;
end;
try
@pluName := GetProcAddress(PluRecd.Addr, 'plugName');
PluRecd.Name := pluName;
PluRecd.Call := GetProcAddress(PluRecd.Addr, 'plugShow');
plugList.Add(PluRecd);
except
// raise plugFail.Create('初始化失败');
end;
end;
finally
FreeAndNil(strList);
end;
end;
procedure PlugIns_Exec(const intplug:integer);
begin{运行插件}
try
@plugShow := TplugInfo(plugList[intplug]).Call;{函数调用地址}
if plugShow(application.Handle, TplugInfo(plugList[intplug]).Name) then exit;
except
showMessage('插件执行错误!');
end;
end;
procedure PlugIns_Free;
var
intLoop: Integer;
begin{释放插件}
for intLoop:=plugList.Count-1 downto 0 do
try FreeLibrary(TplugInfo(plugList[intLoop]).Addr)
except end;
plugList.Free;{释放plugIns对象}
end;
end.