Delphi Dll示例
//MyInt.pas
unit MyInt; interface {$IFNDEF MYLIB}
function MyAdd(a,b:integer):integer ;stdcall;
{$ENDIF} implementation {$IFNDEF MYLIB}
function MyAdd; external 'MyLib.dll' name 'MyAdd';
{$ENDIF}
end.
//MyLib.dpr
library MyLib; { Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. } uses
SysUtils,
Classes,
MyInt in 'MyInt.pas'; {$R *.res}
function MyAdd(a,b:integer):Integer ; stdcall;
begin
result := (a + b);
end;
exports
MyAdd;
end.
//使用:
unit UnitMain; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls; type
TForm1 = class(TForm)
btnTestDll: TButton;
btnDynamicCall: TButton;
procedure btnTestDllClick(Sender: TObject);
procedure btnDynamicCallClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TFuncMyAdd = function (a,b:Integer) : integer;stdcall; var
Form1: TForm1; implementation
uses
MyInt;
{$R *.dfm} procedure TForm1.btnTestDllClick(Sender: TObject);
begin
ShowMessageFmt('结果=%d',[MyAdd(1,2)]);
end; procedure TForm1.btnDynamicCallClick(Sender: TObject);
var
libHandle : THandle;
funcAdd : TFuncMyAdd;
begin
libHandle := LoadLibrary('MyLib.dll');
try
if libHandle = 0 then
begin
//raise error;
ShowMessage('加载DLL失败!');
end;
@funcAdd := GetProcAddress(libHandle,'MyAdd');
if not (@funcAdd = nil) then
begin
ShowMessageFmt('动态加载结果=%d',[funcAdd(1,2)]);
end;
finally
FreeLibrary(libHandle)
end;
end;
end.
Delphi Dll示例的更多相关文章
- C# 调用Delphi dll
delphi dll 源码: library dllres; type char10 = ..] of char; TMydata = packed record id: Integer; name: ...
- 在.net中调用Delphi dll的Pchar转换
Pchar是非托管代码,要在.net中调用Delphi dll中的功能,请使用MarshalAs属性告知.net调用PInvoke去转换.net中标准的string类型.如果Delphi dll是De ...
- Delphi Dll 动态调用例子(3)-仔细看一下
http://blog.163.com/bxf_0011/blog/static/35420330200952075114318/ Delphi 动态链接库的动态和静态调用 为了让人能快速的理解 静态 ...
- Borland.Delphi.dll
Borland.Delphi.dll Borland Delphi Runtime for .NET Imports Borland.DelphiImports Borland.Delphi.Unit ...
- vb6如何调用delphi DLL中的函数并返回字符串?
1,问题描述 最近发现vb6调用delphi DLL中的函数并返回字符串时出现问题,有时正常,有时出现?号,有时干脆导致VB程序退出 -- :: 将金额数字转化为可读的语音文字:1转化为1元 ???? ...
- delphi dll调用问题
dll传递string实现方法 delphi中dll传递string的实现方法: dll项目uses第一个引用sharemem单元; 调用的项目uses第一个引用sharemem单元; 调用的单元us ...
- Delphi静态加载DLL和动态加载DLL示例
下面以Delphi调用触摸屏动态库xtkutility.dll为例子,说明如何静态加载DLL和动态加载DLL. 直接上代码. 1.静态加载示例 unit Unit1; interface uses W ...
- Delphi调用C++写的dll示例
最近做一个读市民卡的项目,读卡器公司提供的读市民卡dll是用C++写的. 下面记录一些自己的心得,供需要的朋友参考. 声明dll函数要加上stdcall关键字,否则可能会报地址非法的错误. 代码: u ...
- C#调用Delphi Dll返回字符串的示例(使用Move才能拷贝字符串)
//----------------------Delphi------------------- procedure GetSqlData(ASource: PChar; ADest: PChar; ...
随机推荐
- http://blog.sina.com.cn/s/blog_5f103c9c0101atny.html
http://blog.sina.com.cn/s/blog_5f103c9c0101atny.html http://www.oschina.net/question/117304_51525
- 阿里云DRDS:分布式数据库服务
最近在做阿里云相关的项目,用到阿里的很多接口服务的API,于是想把这段项目做个总结,顺便梳理下阿里云的云计算的相关知识点. DRDS:分布式数据库服务. 1.相关术语 DRDS(Distribute ...
- 概率 Gym 100502D Dice Game
题目传送门 /* 题意:两个人各掷两个骰子,给出每个骰子的最小值和最大值,其余值连续分布 问两人投掷,胜利的概率谁大 数据小,用4个for 把所有的可能性都枚举一遍,统计每一次是谁胜利 还有更简单的做 ...
- Sql 字符串替换
(1) 字符串替换 Update SongADD_EMH0055 SET songno = REPLACE(songno, '231', '233') where songno like '%1022 ...
- Gap
Gap Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- WebRTC手记Channel概念
转载请注明出处:http://www.cnblogs.com/fangkm/p/4401075.html 前面两篇博文完整地介绍了WebRTC音视频的采集模块,接下来应该开始介绍关键的音视频编码模块. ...
- windows raid mode重新安装系统(win10)
常规安装模式: STEP 1 进入bios 将高级设置中,引导模式设置为传统(旧模式)模式,一般存在legacy (旧模式),uefi with csm ,uefi without csm 三个模式, ...
- 使用C++/C qsort 标准库对结构体进行快速排序
C++标准快速排序库qsort进行结构体快速排序 代码如下 #include <stdio.h> #include <stdlib.h> typedef struct { in ...
- MySQL 用户管理——权限表
权限表 权限表存放在mysql数据库中 user表结构 用户列:Host.User.Password 权限列:*priv 资源控制列:max* 安全列:其余 db表 存储了用户对某个数据库的操作权 ...
- iOS开发之--UITextField属性
UITextField属性 0. enablesReturnKeyAutomatically 默认为No,如果设置为Yes,文本框中没有输入任何字符的话,右下角的返回按钮是disabled的. ...