小弟刚刚在看关于dll的书,有一点疑惑请教一下
我创建一个dll的框架dll wizard
怎么保存的时候是dpr后缀名的,是不是应该是.dll后缀名啊在dll的exports中声名的函数是不是要由另一个.pas文件来实现啊(是不是也可以在dll中直接实现啊)如果是静态调用,是不是还要一个接口单元来声明什么external东西啊再问一下它们之间的包含关系是什么样的?
library Project1;//dll单元?{ 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,
mydll in 'mydll.pas'
{$R *.res}
exports
area,volume;
begin
end.unit mydll;//实现部分??interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
function area(r:integer):integer;stdcall;export;
function volume(r:integer):integer;stdcall;export;implementation
function area(r:integer):integer;stdcall
begin
showmessage('求一个的面积');
result:=r*2;
end;
function volume(r:integer):integer;stdcall;
begin
result:=r*3;
showmessage('求一个圆的体积');
end;
end.
unit jiekou;//借口单元???interface
function area(r:integer):integer;stdcall;
function volume(r:integer):integer;stdcall;
implementation
function area;external 'mydll1.dll' name 'area';
function volume;external 'mydll1.dll' name 'volume';
end.请问以下我概念是不是有问题啊????
我创建一个dll的框架dll wizard
怎么保存的时候是dpr后缀名的,是不是应该是.dll后缀名啊在dll的exports中声名的函数是不是要由另一个.pas文件来实现啊(是不是也可以在dll中直接实现啊)如果是静态调用,是不是还要一个接口单元来声明什么external东西啊再问一下它们之间的包含关系是什么样的?
library Project1;//dll单元?{ 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,
mydll in 'mydll.pas'
{$R *.res}
exports
area,volume;
begin
end.unit mydll;//实现部分??interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
function area(r:integer):integer;stdcall;export;
function volume(r:integer):integer;stdcall;export;implementation
function area(r:integer):integer;stdcall
begin
showmessage('求一个的面积');
result:=r*2;
end;
function volume(r:integer):integer;stdcall;
begin
result:=r*3;
showmessage('求一个圆的体积');
end;
end.
unit jiekou;//借口单元???interface
function area(r:integer):integer;stdcall;
function volume(r:integer):integer;stdcall;
implementation
function area;external 'mydll1.dll' name 'area';
function volume;external 'mydll1.dll' name 'volume';
end.请问以下我概念是不是有问题啊????
exports可以和代码在同一个文件中,没有必要单独放在另外一个文件里如果你用静态调用的时候说什么找不到入口点,那么你用用VS自带的 Depends Walker来看看导出函数借口吧。
而mydll是.pas的,我就有点不明白了,请教alphax,能不能把我的那个程序写的更清楚点(步骤,先是什么,后是什么?)
我现在是写了,可是怎么也调试不通过,书也看了,可是讲得不详细,还望赐教,先谢了呵呵!!
如果你的dll文件的名称和liarary的名字相同在主程序中
function area;external 'mydll1.dll' name 'area';
function volume;external 'mydll1.dll' name 'volume';
implementation
。
如果你主程序中用mydlll.dll
这里改为
library mydlll;
/\
|
这里要放DLL的文件名,而不是实现的单元名
DLL Project的名称就是DLL的文件名,像你的情况,上面那个mydll1.dll应该用Project1.dll
来代替。还有就是如果你有一个Project2.exe要静态连接这个Project1.DLL,那么Project1.DLL应该在Project2.exe的搜索路径上
我以前也遇到这样的 问题,后来发先,只要编译一下就可以,
或者就在dll中实现?当你编译后就会自动生成dll文件?那么这个dll是不是就依赖那个实现的unit文件了。
试一下吧>>那么这个dll是不是就依赖那个实现的unit文件了
实现的unit会被连接到dll的,也就是dll已经包含这个unit了