麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > Delphi > 正文

Delphi 用DLL實現插件的簡單實例

2020-01-31 20:50:14
字體:
來源:轉載
供稿:網友

Delphi 用DLL實現插件的簡單實例

這是DLL的代碼  

實現代碼: 

library MyDll;  uses  SysUtils,  Dialogs,  Classes;  procedure ShowInfo(info:PChar);stdcall; begin  ShowMessage('您選擇了【'+info+'】'); end;  function GetCaption:Pchar; begin  Result := '中國'; end;  exports ShowInfo,         GetCaption;  {$R *.res}  begin end. 

這是調用窗體的代碼 

本例只使用了一個DLL,所以當有多個DLL時,需要循環DLL所在目錄,依次加載DLL  

unit Main;  interface  uses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, StdCtrls, Menus, ExtCtrls;  type  TShowInfo = procedure (info:PChar);stdcall;  TGetCaption = function : PChar;stdcall;    TForm1 = class(TForm)   Button1: TButton;   Button2: TButton;   MainMenu1: TMainMenu;   Image1: TImage;   procedure Button2Click(Sender: TObject); private   { Private declarations }   FHandel : THandle;   //DLL句柄   FProAddress: Pointer; //DLL中ShowInfo的地址   showinfo: TShowInfo;  //為動態加載DLL而設   procedure LoadPlusIn; //加載插件(DLL)   procedure ItemClick(Sender: TObject);  //自定義菜單點擊事件  public   { Public declarations }  end;  var  Form1: TForm1;  implementation  {$R *.dfm}  procedure TForm1.Button2Click(Sender: TObject); begin  LoadPlusIn; end;  procedure TForm1.ItemClick(Sender: TObject); begin  @showinfo := FProAddress;   //取地址  if @showinfo <> nil then   showinfo(PWideChar(TMenuItem(Sender).Caption)); //執行DLL中的ShowInfo end;  procedure TForm1.LoadPlusIn; var  getcaption: TGetCaption;  item : TMenuItem; begin  FHandel := LoadLibrary('MyDll.dll');  //加載  if FHandel = 0 then  begin   ShowMessage('加載失敗!');   Exit;  end  else  begin   @getcaption := GetProcAddress(FHandel,'GetCaption');  //取DLL中GetCaption地址   if @getcaption <> nil then   begin    item := TMenuItem.Create(MainMenu1);  //創建一個菜單    item.Caption := getcaption;       //取Caption,即調用DLL中的GetCaption    FProAddress := GetProcAddress(FHandel,'ShowInfo'); //取得DLL中ShowInfo的地址    item.OnClick := ItemClick;       //賦予菜單項的點擊事件    MainMenu1.Items.Add(item);       //添加到主菜單   end;   end; end;  end. 

如有疑問請留言或者到本站社區交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 久久久aa | 国产在线观看91精品 | 九九热精品视频在线 | 久久久久久久久日本理论电影 | 日日做夜夜操 | 日韩精品久久久久久 | 欧美成人小视频 | 国产手机在线视频 | 黄色一级片免费观看 | 视频www| 成人毛片100免费观看 | 久久国产精品影视 | 欧美激情第一区 | 91热久久免费频精品黑人99 | 亚洲小视频在线观看,com | 特片网久久 | 国产精品视频专区 | 毛片小网站 | 日本a v免费观看 | 黄色一级电影网 | 欧美一级做a | 日日草夜夜 | 91精品福利视频 | 亚洲免费资源 | av在线看网站 | 护士xxxx| 免费a视频 | 国产女厕一区二区三区在线视 | av不卡毛片| 性爱视频在线免费 | 天天操很很操 | 99sesese| 中文字幕亚洲视频 | 亚洲草逼视频 | 国产成人自拍视频在线观看 | 久久草草影视免费网 | 成人短视频在线播放 | 日本欧美一区 | 午夜丰满少妇高清毛片1000部 | 毛片国产 | 国产精品久久久久久久av |