、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 ...
随机推荐
- android学习日记03--常用控件tabSpec/tabHost
常用控件7.TabSpec和TabHost 比较常用的控件,感觉手机QQ的整体布局就是这个,只不过tab放在底部而已.TabSpec相当于浏览器的分页,而TabHost就相当于分页的集合TabSpec ...
- Struts2 Action的访问路径
1. Action的访问路径 扩展名 缺省以.action结尾,请参考:default.properties文件,可以通过配置改变这一点: <constant name="st ...
- 再探ASP.NET 5(转载)
就在最近一段时间,微软又有大动作了,在IDE方面除了给我们发布了Viausl Studio 2013 社区版还发布了全新的Visual Studio 2015 Preview. Visual Stud ...
- C#获取指定网页源码的几种方法
// WebClient private string GetWebClient(string url) { string strHTML = ""; WebClient myWe ...
- sass+require实现侧边栏
一.效果图(如下)及使用的技术 实现用sass实现页面中右侧固定侧边栏的样式,用require.js实现返回顶部的功能 二.sass 具体的sass的介绍就不多说了,大家可以参考sass官网介绍,下面 ...
- 需要一个分页,花了一个钟写了一个,刚学js,不是很完美
<script src="js/jquery.min.js" ></script> <script type="text/javascrip ...
- MySql添加用户,新建数据库,用户授权,删除用户,修改密码
转自:http://www.cnblogs.com/fly1988happy/archive/2011/12/15/2288554.html MySql中添加用户,新建数据库,用户授权,删除用户,修改 ...
- android开发之路04(初级android工程师必会,你懂得!)
Android初级Android工程师重点掌握内容如下: 1.Android开发基础: ①UI界面设计: ②SQLite数据库: ③android四大组件: ④android网络编程: ⑤androi ...
- NSURLSession 请求
参考网站:http://ningandjiao.iteye.com/blog/2010753 http://www.cocoachina.com/industry/20131106/7304.html ...
- chosen 下拉框
$("#teams").trigger("liszt:updated");//更新重新绑定 $(" ...