这是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实现插件的简单演示的更多相关文章

  1. ASP.NET MVC5 插件机制中插件的简单实现

    Autofac 依赖注入 ASP.NET MVC5 插件机制中插件的简单实现 一.前言 由于项目业务复杂,创建了多个插件并把他们放在了不同的项目中,项目使用AutoFac做的IOC:但是主项目可以注入 ...

  2. nice-validator表单验证插件的简单使用

    前言 前端表单校验是过滤无效数据.假数据.有毒数据的第一步,是数据安全的第一道关卡,虽然我们不能100%相信客户端提交的数据(真正的校验还得在服务端进行),但设置前端表单校验也是至关重要的,自己写逻辑 ...

  3. Xcode7使用插件的简单方法&&以及怎样下载到更早版本的Xcode

    Xcode7自2015年9上架以来也有段时间了, 使用Xcode7以及Xcode7.1\Xcode7.2的小伙伴会发现像VVDocumenter-Xcode\KSImageNamed-Xcode\HO ...

  4. 移动端全屏滑动的小插件,简单,轻便,好用,只有3k swiper,myswiper,page,stage

    https://github.com/donglegend/mySwiper mySwiper 移动端全屏滑动的小插件,简单,轻便,好用,只有3k 下载 直接下载 bower install mySw ...

  5. 数据统计表插件,highcharts插件的简单应用

    highcharts插件的简单应用,非常全能好用的一个数据统计表插件. $(function () { $('#container').highcharts({ chart:{ type:" ...

  6. Introspector(内省)简单演示样例 与 简单应用

    简单演示样例: package com.asdfLeftHand.test; import java.beans.BeanDescriptor; import java.beans.BeanInfo; ...

  7. JBoss 系列九十六:JBoss MSC - 简介及一个简单演示样例

    什么是 JBoss MSC JBoss MSC 即 JBoss Modular Service Container,是第三代 JBoss 产品 JBoss 7和WildFfly的内核,JBoss MS ...

  8. Thrift的安装和简单演示样例

    本文仅仅是简单的解说Thrift开源框架的安装和简单使用演示样例.对于具体的解说,后面在进行阐述. Thrift简述                                           ...

  9. 在VC6中基于dll开发插件用于各种图片显示(BMP/TGA/JPG/GIF/PNG/TIF/ICO/WMF/EMF/...)

    一.图片显示 图片显示的方法: 1.  直接写程序 2.  第3方库 3.  调用COM组件的IPicture接口 4.  使用MFC的CPictureHolder类 5.  使用GDI+的CImag ...

随机推荐

  1. VTP管理交换机的VLAN配置

    实验要求:将Switch1设置为VTPserver.Switch2设置为VTPtransparent.Swtich3和4设置为VTPclient 拓扑如下: 涉及内容: 1.VTP的创建 2.VTP的 ...

  2. Android全局可调试(ro.debuggable = 1)的一种另类改法

    网上流传比较多的,是重打包boot.img.读aosp的init进程源码,发现通过patch init进程也可以实现相同目的. 首先看一下init进程对ro只读属性的检查: /* property_s ...

  3. galera cluster,mysql配置wsrep_notify_cmd参数,增加邮件告警

    vi /usr/local/sunlight/wsrep_notify_cmd.sh chown mysql:mysql  /usr/local/sunlight/wsrep_notify_cmd.s ...

  4. angular-translate

    angular.module('app.core', ['pascalprecht.translate']).config(['$translateProvider', '$translatePart ...

  5. 20155219&20155224 《信息安全系统设计基础》实验一 开发环境的熟悉

    实验内容 实验两人一组,最多三人一组 可以使用自己的笔记本,也可以使用实验室台式机 使用实验箱作为超级终端. 实验中学到的知识点 交叉编译 宿主机与目标机 NFS 超级终端 file命令 实验步骤 实 ...

  6. Atcoder 1973:こだわり者いろはちゃん / Iroha's Obsession

    C - こだわり者いろはちゃん / Iroha's Obsession Time limit : 2sec / Memory limit : 256MB Score : 300 points Prob ...

  7. poj1504 Adding Reversed Numbers

    Adding Reversed Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17993 Accepted: 9 ...

  8. C与C++中实现 gotoxy()函数

    #include <stdio.h> #include <windows.h> void gotoxy(int x, int y) { COORD pos = {x,y}; H ...

  9. acm 2044

    ////////////////////////////////////////////////////////////////////////////////#include<iostream ...

  10. python------模块定义、导入、优化 ------->Shelve模块

    1. shelve模块 是一个简单的k,v将内存数据通过文件持久化的模块,可以持久化任何pickle可支持的python数据格式. import shelve import datetime d = ...