用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 = 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.
用DLL实现插件的简单演示的更多相关文章
- ASP.NET MVC5 插件机制中插件的简单实现
Autofac 依赖注入 ASP.NET MVC5 插件机制中插件的简单实现 一.前言 由于项目业务复杂,创建了多个插件并把他们放在了不同的项目中,项目使用AutoFac做的IOC:但是主项目可以注入 ...
- nice-validator表单验证插件的简单使用
前言 前端表单校验是过滤无效数据.假数据.有毒数据的第一步,是数据安全的第一道关卡,虽然我们不能100%相信客户端提交的数据(真正的校验还得在服务端进行),但设置前端表单校验也是至关重要的,自己写逻辑 ...
- Xcode7使用插件的简单方法&&以及怎样下载到更早版本的Xcode
Xcode7自2015年9上架以来也有段时间了, 使用Xcode7以及Xcode7.1\Xcode7.2的小伙伴会发现像VVDocumenter-Xcode\KSImageNamed-Xcode\HO ...
- 移动端全屏滑动的小插件,简单,轻便,好用,只有3k swiper,myswiper,page,stage
https://github.com/donglegend/mySwiper mySwiper 移动端全屏滑动的小插件,简单,轻便,好用,只有3k 下载 直接下载 bower install mySw ...
- 数据统计表插件,highcharts插件的简单应用
highcharts插件的简单应用,非常全能好用的一个数据统计表插件. $(function () { $('#container').highcharts({ chart:{ type:" ...
- Introspector(内省)简单演示样例 与 简单应用
简单演示样例: package com.asdfLeftHand.test; import java.beans.BeanDescriptor; import java.beans.BeanInfo; ...
- JBoss 系列九十六:JBoss MSC - 简介及一个简单演示样例
什么是 JBoss MSC JBoss MSC 即 JBoss Modular Service Container,是第三代 JBoss 产品 JBoss 7和WildFfly的内核,JBoss MS ...
- Thrift的安装和简单演示样例
本文仅仅是简单的解说Thrift开源框架的安装和简单使用演示样例.对于具体的解说,后面在进行阐述. Thrift简述 ...
- 在VC6中基于dll开发插件用于各种图片显示(BMP/TGA/JPG/GIF/PNG/TIF/ICO/WMF/EMF/...)
一.图片显示 图片显示的方法: 1. 直接写程序 2. 第3方库 3. 调用COM组件的IPicture接口 4. 使用MFC的CPictureHolder类 5. 使用GDI+的CImag ...
随机推荐
- vue mapbox 地图 demo
执行以下命令: npm install --save mapbox-gl// cnpm install --save mapbox-gl <template> <div style= ...
- 【Python】混合驱动实例
keywords2.txt: get||ie||{urls.txt} get||chrome||http://www.iciba.com main.py: from selenium import w ...
- 树莓派与node.js —— onoff、dht
1. 发光二极管 tm-onoff var Gpio = require('tm-onoff').Gpio, led = new Gpio(17, 'out'), button = new Gpio( ...
- help2man: can't get `--help' info from automake-1.15 Try `--no-discard-stderr' if option outputs to stderr Makefile:3687: recipe for target 'doc/automake-1.15.1' failed
/********************************************************************** * help2man: can't get `--hel ...
- httpd: config error '*.php:/usr/bin/php-cgi' in '/etc/httpd.conf'
/********************************************************************************* * httpd: config e ...
- git get submodule after clone
/********************************************************************************* * git get submodu ...
- [LeetCode&Python] Problem 292. Nim Game
You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac ...
- day021python 正则表达式
正则表达式是由普通字符和元字符组成, 普通字符包含大小写字母, 数字. 在匹配普通字符 的时候我们直接写就可以了. 比如"abc" 匹配的就是"abc". 元字 ...
- Github&&SourceTree
如何将本地的代码或者是文件上传到github 方法一:(github上面创建仓库,远程仓库克隆到本地,将文件拖拽到本地仓库) cd 文件夹 git clone 链接(github上面创建新仓库的链 ...
- struts2简单类型参数转换器(拦截器自动转换)
这边测试类型int,string,date,list(set),map,下面贴代码 struts.xml文件代码 <!-- 类型转换 --> <action name="C ...