、Dll文件的编写 调用 说明
1>新建Dll文件TestLib.dll
新建Unit文件U_TestFunc
U_TestFunc代码如下:
unit U_TestFunc;
interface
uses //尽可能的少uses这样会缩小dll的体积
SysUtils;
//求和
function Sum(x1,x2: Integer): Integer; stdcall
implementation
function Sum(x1,x2: Integer): Integer; stdcall
begin
Result := x1+x2;
end;
end.
TestLib代码如下:
library TestLib;
uses SysUtils,
U_TestFunc in 'U_TestFunc.pas';
{$R *.res}
exports
Sum;
begin
end.
2>调用方法 源码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons;
type
TForm1 = class(TForm)
Edit1: TEdit;
BitBtn1: TBitBtn;
Edit2: TEdit;
BitBtn2: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function Sum(a1,a2: Integer): Integer; stdcall; external 'C:\TestLib.dll';
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
//if FileExists('C:\TestLib.dll') then 这里感觉这两个函数没有什么区别,文件在本地不在本地貌似效果都一样。
if LocaleFileExists('C:\TestLib.dll') then
Edit1.Text := IntToStr(Sum(100,200))
else
ShowMessage('文件不存在!');
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
type
TIntFunc = function(a1,a2: Integer): Integer; stdcall;
var
Th: THandle;
Tf: TIntFunc;
begin
Th := LoadLibrary('C:\TestLib.dll');
if Th>0 then
begin
try
@Tf := GetProcAddress(Th, PAnsiChar('Sum'));
if @Tf<>nil then
begin
Edit2.Text := IntToStr(Tf(100,200));
end else
ShowMessage('Sum函数没有找到!');
finally
FreeLibrary(Th); //释放Dll
end;
end else
ShowMessage('TestLib.dll文件没有找到!');
end;
end.
、Dll文件的编写 调用 说明的更多相关文章
- C# 创建Dll文件供程序调用方法
C# 创建Dll文件供程序调用方法 使用C#创建动态Dll文件方法: 1. 在VS2017环境下,新建-项目-选择类库类型: 2. 新创建一个.cs文件(如test.cs),编写代码如下: usin ...
- Delphi 使用之dll文件生成与调用
DLL是Dynamic-Link Libraries(动态链接库)的缩写,库里面是一些可执行的模块以及资源(如位图.图标等).可以认为DLL和EXE基本上是一回事,只是DLL不能直接执行,而必须由应用 ...
- Delphi DLL文件的动态调用
樊伟胜
- Delphi DLL文件的静态调用
- .dll 文件编写和使用
1.基本概念 dll(dynamic-link library),动态链接库,是微软实现共享函数库的一种方式.动态链接,就是把一些常用的函数代码制作成dll文件,当某个程序调用到dll中的某个函数的时 ...
- LabVIEW如何方便地调用DLL文件
转自:http://bbs.elecfans.com/jishu_469502_1_1.html LabVIEW调用DLL文件 LabVIEW支持通过调用DLL文件的方式与其它编程语言混合使用.比 ...
- C++ exe调用dll文件
生成dll程序 extern "C"_declspec(dllexport) void maopao(int *p,int count);void maopao(int *p,in ...
- 获取DLL的文件路径以及调用DLL的文件路径
如何在DLL中,获取DLL本身的路径以及调用DLL的文件的路径呢?主要通过GetModuleFileName(HMODULEhModule,LPTSTR lpFilename,DWORD nSize) ...
- Delphi 封装Frame到Dll文件
做项目的时候,发现这个Frame很好用,为了省空间.调用和修改方便,就将Frame封装到dll(动态链接库)里面,确实很好使. 效果图如下: 上图是临时测试用的,忘了将Frame的align设置成al ...
随机推荐
- valgrind 生成mysqld调用图之 select now()跟踪
1.mysqld起动方式: 1.mysqld以root用户运行 valgrind --tool=callgrind --separate-threads=yes --trace-children=y ...
- Debug 之 The state information is invalid for this page and might be corrupted
1.问题描述: 网站部署之后,排序或者搜索之后报错:The state information is invalid for this page and might be corrupted 2.问题 ...
- sqlite数据下载链接地址
链接: http://pan.baidu.com/s/1pJN1abT 密码: yjg5
- VirtualBox中centos网络配置
VirtualBox图形界面下有四种网络接入方式,它们分别是: 1.NAT 网络地址转换模式(NAT,Network Address Translation) 2.Bridged Adapter 桥接 ...
- Android之HTTP网络通信--GET传递(二)
根据上一篇写的是实现了通过url接口将接口中的数据显示出来,这次根据上一篇的基础,进一步说明一下AsynTask的使用. AsynTask类有几个函数是大家必须知道的. doInBackGround( ...
- Convert Date between LocalDateTime
http://blog.progs.be/542/date-to-java-time Java8 has new date and time classes to “replace” the old ...
- jemalloc源码结构分析(三):arena_malloc_small内存分布
在arena_s结构中,由NBINS数组将bin按照不同规模等级分别存储,每一个等级对应一颗run树,即一颗以chunk_map_t为节点的红黑树,而这些chunk_map_t节点实际分布于各个chu ...
- Android 自学之拖动条SeekBar
拖动条(SeekBar)和进度条非常相似,只是进度条采用颜色填充来表明进度完成的程度,而拖动条则通过滑块的位置来标识数值----而且拖动条允许用户拖动滑动块来改变值,因此拖动条通常用于对系统的某种数值 ...
- JAXB - XML Schema Types, Defining an Enumeration
If you want a data type that enumerates discrete values you should use a restriction of the schema t ...
- scala学习笔记:理解函数
定义一个函数: scala> def foo(x:Int)=x*2 foo: (x: Int)Int 可以采用匿名参数: scala> def foo:((Int)=>Int) = ...