扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:caishaoting 来源:CSDN BLOG 2007年10月31日
关键字:
type //定义接口函数类型,接口函数来自DLL接口 TShowDLLForm = Function(AHandle:THandle; ACaption: String; AUserID:string):Boolean;stdcall; TFreeDLLForm = Function(AHandle:THandle; ACaption: String; AUserID:string):boolean;stdcall; |
…… var ShowDLLForm: TShowDLLForm; //DLL接口函数实例 FreeDLLForm: TFreeDLLForm; begin try begin APlugin.ProcAddr := LoadLibrary(PChar(sPath)); APlugin.FuncFreeAddr := GetProcAddress(APlugin.ProcAddr,’FreeDLLForm’); APlugin.FuncAddr := GetProcAddress(APlugin.ProcAddr ,’ShowDLLForm’); @ShowDLLForm:=APlugin.FuncAddr ; @FreeDLLForm:=APlugin.FuncFreeAddr; if ShowDllForm(Self.Handle, APlugin.Caption , APlugin.UserID) then Result:=True …… |
字段名 | 作用 | 类型 |
AutoID | 索引 | INT |
modAlias | 模块别称 | VARCHAR |
modName | 模块名称 | VARCHAR |
modWndClass | 窗体唯一标识 | VARCHAR |
modFile | DLL路径 | VARCHAR |
modMemo | 备注 | TEXT |
type //定义插件信息类 TMyPlugins = class Caption:String; //DLL窗体标题 DllFileName:String; //DLL文件路径 WndClass:String; //窗体标识 UserID:string; //用户名 ProcAddr:THandle; //LOADLIBRARY载入的库句柄 FuncAddr:Pointer; //SHOWDLLFORM函数指针 FuncFreeAddr:Pointer; //FREEDLLFORM函数指针 end; …… |
…… //----------------------------------------- //Name: OpenPlugin //Func: 插件信息类控制过程: 初始化==》设置权限==》载入DLL窗口 //Para: APlugin-TMyPlugins; sAlias别名; iFuncValue权限值 //Rtrn: N/A //Auth: CST //Date: 2005-6-2 //----------------------------------------- procedure TFormHall.OpenPlugin(AFromActn: TAction ;APlugin:TMyPlugins; sAlias:string; sUserID:string); var hWndPlugin:HWnd; begin //判断插件窗口是否已经载入 hWndPlugin:=FindWindow(PChar(APlugin.WndClass),nil); if hWndPlugin <> 0 then //插件窗口已经载入 begin if not IsWindowVisible(hWndPlugin) then begin AFromActn.Checked := True; ShowWindow(hWndPlugin,SW_SHOWDEFAULT); //显示 end else begin AFromActn.checked := False; ShowWindow(hWndPlugin,SW_HIDE) ; end; Exit; //离开创建插件过程 end; //初始化插件类实例 if not InitializeMyPlugins(APlugin,sAlias) then begin showmessage(’初始化插件类错误。’); exit; end; //获得当前权限值 APlugin.UserID := sUserID; //载入DLL窗口 if not LoadShowPluginForm(APlugin) then begin showmessage(’载入中心插件出错。’); exit; end; end; //----------------------------------------- //Name: InitializeMyPlugins //Func: 初始化MYPLUGIN实例 (Caption | DllFileName | IsLoaded) //Para: APlugin-TMyPlugins //Rtrn: N/A //Auth: CST //Date: 2005-6-2 //----------------------------------------- function TFormHall.InitializeMyPlugins(APlugin:TMyPlugins; sAlias:String):Boolean; var strSQL:string; myDA:TMyDataAdapter; begin Result:=False; myDA:=TMyDataAdapter.Create; strSQL:=’SELECT * FROM SystemModuleList WHERE modAlias=’+QuotedStr(sAlias); try myDA.RetrieveData(strSQL); except on E:Exception do begin result:=false; myDA.Free ; exit; end; end; try begin with myDA.MyDataSet do begin if Not IsEmpty then begin APlugin.Caption:= FieldByName(’modName’).Value; APlugin.DllFileName := FieldByName(’modFile’).Value; APlugin.WndClass := FieldByName(’modWndClass’).Value ; result:=True; end; Close; end; //end of with...do... end; //end of try except on E:Exception do begin Result:=False; myDA.Free ; Exit; end; //end of exception end; //end of try...except myDA.Free ; end; //----------------------------------------- //Name: LoadShowPluginForm //Func: 载入DLL插件并显示窗口 //Para: APlugin-TMyPlugins //Rtrn: true-创建成功 //Auth: CST //Date: 2005-6-2 //----------------------------------------- function TFormHall.LoadShowPluginForm (const APlugin:TMyPlugins):boolean; var ShowDLLForm: TShowDLLForm; //DLL接口函数实例 FreeDLLForm: TFreeDLLForm; sPath:string; //DLL文件的完整路径 begin try begin sPath:=ExtractFilepath(Application.ExeName)+ ’plugins\’ + APlugin.DllFileName ; APlugin.ProcAddr := LoadLibrary(PChar(sPath)); APlugin.FuncFreeAddr := GetProcAddress(APlugin.ProcAddr,’FreeDLLForm’); APlugin.FuncAddr := GetProcAddress(APlugin.ProcAddr ,’ShowDLLForm’); @ShowDLLForm:=APlugin.FuncAddr ; @FreeDLLForm:=APlugin.FuncFreeAddr; if ShowDllForm(Self.Handle, APlugin.Caption , APlugin.UserID) then Result:=True else Result:=False; end; except on E:Exception do begin Result:=False; ShowMessage(’载入插件模块错误,请检查PLUGINS目录里的文件是否完整。’); end; end; end; …… |
procedure TFormHall.ClosePlugin(aPLG:TMyPlugins); var FreeDLLForm:TFreeDLLForm; begin if aPLG.ProcAddr = 0 then exit; if aPLG.FuncFreeAddr = nil then exit; @FreeDLLForm:=aPLG.FuncFreeAddr; if not FreeDLLForm(Application.Handle,’’,’’) then showMessage(’err’); end; |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。