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; ...
随机推荐
- BZOJ3012 : [Usaco2012 Dec]First!
建立Trie,那么成为答案的串必须满足其终止节点到根路径上没有其它点. 对于Trie上每个节点维护一个bitset,表示哪些字符必须在哪些字符之前. 每到达一个可能成为答案的终止节点,对图进行拓扑排序 ...
- BZOJ3578 : GTY的人类基因组计划2
关于如何判断一个集合是否出现过: 给每个元素随机一个hash权值,然后xor起来即可 插入删除都只需xor 线段树维护区间有效人数和,以及打标记表示这个区间的集合要全部标记为出现过,并把区间内sum值 ...
- POJ 3580 (伸展树)
题目链接: http://poj.org/problem?id=3580 题目大意:对一个序列进行以下六种操作.输出MIN操作的结果. 解题思路: 六个操作,完美诠释了伸展树有多么吊.注意,默认使用L ...
- SpringMVC_The resource identified by this request is only capable of generating responses with characteristics
今天在调试springMVC的时候,在将一个对象返回为json串的时候,浏览器中出现异常: The resource identified by this request is only capabl ...
- shell中(),[]和[[]]的区别
1. 首先,尽管很相似,但是从概念上讲,二者是不同层次的东西."[[",是关键字,许多shell(如ash bsh)并不支持这种方式.ksh, bash(据说从2.02起引入对[[ ...
- RN组件之ViewPagerAndroid
一.ViewPagerAndroid 1.一个允许在子视图之间左右翻页的容器.每一个ViewPagerAndroid的子容器会被视作一个单独的页,并且会被拉伸填满 ViewPagerAndroid.注 ...
- hdu 1735 字数统计
这道题是到贪心的题目,首先用ans记录下所有的0的个数,然后尽量去掉更多的0,剩下的0的个数就是最少的字数.首先想到最后一行的0的个数可以减掉,然后就是m行开头的两个0可以减掉.然后思考最多还可以减掉 ...
- 在cmd下输入/g无效
如图: 原来一:斜杠得是\ 二:命令和它之间没空格.这个符号和分号的使用是一样的.
- pajax
pjax网址:https://libraries.io/bower/yii2-pjax 1. 连接指定的div,实行pjax ,利用 linkSelector 方法<div id="c ...
- 如何使用 Migration创建一个迁移
切换到YII所在的目录 yii migrate/create test