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; ...
随机推荐
- json学习系列(3)-JSONObject的过滤设置
我们通常对一个json串和java对象进行互转时,经常会有选择性的过滤掉一些属性值.例如下面的实体类: package com.pcitc.json; /** * Person实体类 * * @Des ...
- LCS(滚动数组) POJ 1159 Palindrome
题目传送门 题意:一个字符串要变成回文串至少要插入多少个字符 分析:LCS,长度 - 原串和反串的最大相同长度就是要插入的个数.解释一下,当和反串相同时,在原串中已经是回文的部分了,那么减去LCS长度 ...
- 思维 UVALive 3708 Graveyard
题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...
- 贪心 POJ 2586 Y2K Accounting Bug
题目地址:http://poj.org/problem?id=2586 /* 题意:某公司要统计全年盈利状况,对于每一个月来说,如果盈利则盈利S,如果亏空则亏空D. 公司每五个月进行一次统计,全年共统 ...
- win8 中实现断点续传
1) Resume method does resume on cases where resume is possible. Meaning if the server accepts range- ...
- [Cocos2d-x For WP8]Hello world
[Cocos2d-x For WP8]Hello world Cocos2d-x For WP8使用C++开发,使用cocos2d-xv0.13同样的接口,Cocos2d-x For WP8的相关项目 ...
- Mysql_mysql force Index 强制索引
其他强制操作,优先操作如下: mysql常用的hint 对于经常使用oracle的朋友可能知道,oracle的hint功能种类很多,对于优化sql语句提供了很多方法.同样,在mysql里,也有类似的h ...
- 兼容ie[6-9]、火狐、Chrome、opera、maxthon3、360浏览器的js本地图片预览
html代码: <div id="divPreview"> <img id="imgHeadPhoto" src="Images/H ...
- PHPUnit在Windows下的配置及使用
由于我们项目涉及到php,因此需要对php代码进行单元测试.经过一番了解,决定用PHPUnit来测试php.PHPUnit花了不少时间摸索如何配置PHPUnit,看官网的文档也是一把泪.但知道怎么配置 ...
- lintcode :Coins in Line II 硬币排成线 II
题目 硬币排成线 II 有 n 个不同价值的硬币排成一条线.两个参赛者轮流从左边依次拿走 1 或 2 个硬币,直到没有硬币为止.计算两个人分别拿到的硬币总价值,价值高的人获胜. 请判定 第一个玩家 是 ...