在DELPHI开发人员指南中 ,介绍DLL章节中有这么一个例子// PenniesLib.dpr;转换美分到其他单位的DLLlibrary penniesLib;
{$define pennieslib}{ 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;
penniesint; function PenniesToCoins(Totppennies:word;CoinsRec:PCoinsRec):word;stdcall;
begin
result:=Toppennies;
with coinsrec^ do
begin
quarters:=toppennies div 25;
toppennies:=toppennies-quarters*25;
dimes:=toppennies div 10;
toppennies:=toppennies-dimes*10;
nickels:=toppennies div 5;
toppennies:=toppennies-nickels*5;
pennies:=toppennies;
end; exports PenniesToCoins;
{$R *.res}
begin
end
//PenniesLib.Dll的接口单元 PenniesInt.pasunit PenniesIntinterface
type
PCoinsRec=^TCoinsRec;
TCoinsRec=record
Quarters,
Dimes,
Nickels,
Pennies:word;function PenniesToCoins(TotPennies:word;CoinsRec:PCoinsRec):word;stdcall;implementationfunction PenniesToCoines;external 'PENNIESLIB.dll' name 'PenniesToCoins';有些不理解,想问下高手们:
1.这个PCoinsRec 是指的什么,是什么数据类型吗?
2.它这里用到这个 CoinsRec指针具体有什么用,为什么要这样用啊?
{$define pennieslib}{ 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;
penniesint; function PenniesToCoins(Totppennies:word;CoinsRec:PCoinsRec):word;stdcall;
begin
result:=Toppennies;
with coinsrec^ do
begin
quarters:=toppennies div 25;
toppennies:=toppennies-quarters*25;
dimes:=toppennies div 10;
toppennies:=toppennies-dimes*10;
nickels:=toppennies div 5;
toppennies:=toppennies-nickels*5;
pennies:=toppennies;
end; exports PenniesToCoins;
{$R *.res}
begin
end
//PenniesLib.Dll的接口单元 PenniesInt.pasunit PenniesIntinterface
type
PCoinsRec=^TCoinsRec;
TCoinsRec=record
Quarters,
Dimes,
Nickels,
Pennies:word;function PenniesToCoins(TotPennies:word;CoinsRec:PCoinsRec):word;stdcall;implementationfunction PenniesToCoines;external 'PENNIESLIB.dll' name 'PenniesToCoins';有些不理解,想问下高手们:
1.这个PCoinsRec 是指的什么,是什么数据类型吗?
2.它这里用到这个 CoinsRec指针具体有什么用,为什么要这样用啊?
1.这个PCoinsRec 是指的什么,是什么数据类型吗?
type
PCoinsRec=^TCoinsRec;
TCoinsRec=record一个自定义的记录类型,2.它这里用到这个 CoinsRec指针具体有什么用,为什么要这样用啊?
要将一个数据从主程序传到 dll 中,这是一个标准的做法