我是照《delphi5 开发人员指南》上的例子做的。
具体代码如下:
library Project1;
{ 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 in '..\..\..\..\Documents and Settings\sss\My Documents\dll\penniesint.pas';{$R *.res}
function PenniesToCoins(TotPennies:Word;Coinsrec:PCoinsRec):word;StdCall;
begin
result:=totpennies;
with coinsrec^ do
begin
quarters:=totpennies div 25;
totpennies:=totpennies -quarters *25;
dimes:=totpennies div 10;
totpennies:=totpennies-dimes*10;
nickels:=totpennies-nickels*5;
pennies:=totpennies;
end;
end;
exports
penniestocoins;begin
end.
--------------------------------------------------------------------
unit penniesint;interface
type
pcoinsrec=^tcoinsrec;
tcoinsrec=record
quarters,
dimes,
nickels,
pennies:word;
end;function penniestocoins(totpennies:word;coinsrec:pcoinsrec):word;stdcall;implementation
function penniestocoins;external 'pennieslib.dll'name 'penniestocoins';
end.编译通过了,但运行时出错:Cannot debug project unless a host application is defined.Use the Run|Parameters..dialog box.
这是咋回事呀?
哪位能帮我讲一下dll的具体步骤。谢谢!
具体代码如下:
library Project1;
{ 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 in '..\..\..\..\Documents and Settings\sss\My Documents\dll\penniesint.pas';{$R *.res}
function PenniesToCoins(TotPennies:Word;Coinsrec:PCoinsRec):word;StdCall;
begin
result:=totpennies;
with coinsrec^ do
begin
quarters:=totpennies div 25;
totpennies:=totpennies -quarters *25;
dimes:=totpennies div 10;
totpennies:=totpennies-dimes*10;
nickels:=totpennies-nickels*5;
pennies:=totpennies;
end;
end;
exports
penniestocoins;begin
end.
--------------------------------------------------------------------
unit penniesint;interface
type
pcoinsrec=^tcoinsrec;
tcoinsrec=record
quarters,
dimes,
nickels,
pennies:word;
end;function penniestocoins(totpennies:word;coinsrec:pcoinsrec):word;stdcall;implementation
function penniestocoins;external 'pennieslib.dll'name 'penniestocoins';
end.编译通过了,但运行时出错:Cannot debug project unless a host application is defined.Use the Run|Parameters..dialog box.
这是咋回事呀?
哪位能帮我讲一下dll的具体步骤。谢谢!
解决方案 »
- 求remobject for delphi7 控件,谢谢啦!
- 关于Midas(DataSnap)处理主从表的问题。
- 邮件中如何保证在中文及日文系统都正常显示?
- 求罗马数字转换为阿拉伯数字的函数
- 有什么辞职最好的理由
- 求数据集里面某个字段的特定值的指针号
- 在各位师父的帮助下,偶的通讯录已经写好,师父门如有时间的话,帮偶测试一下,好吗?(特别感谢老千,老鱼,chechy,小昂)
- 让一个窗体位置不能改变
- 设计显示学生名次的名次表(时间较紧,老师要求近期交货,恳请各位汇编的高手务必相助,小弟不胜感激)
- 关闭窗体的具体事件是什么?怎么样在窗体关闭时释放所有资源(窗体)???
- 如何往Excel的Cell里面写数据?附调试代码~
- 备份数据库的问题!路径不对!
要再写一个EXE来调用DLL
能否有一个具体的步骤,从建立到保存再到引用,谢谢
新建一个项目
在
implementation下面加上
function penniestocoins(totpennies:word;coinsrec:pcoinsrec):word;stdcall;far;external '***.dll';
此后,DLL中的方法就可以在这个项目中用了.试试看.
host application 可以用C:\WINNT\system32\dllhost.exe
parameters 中加入你的DLL文件在COM+应用程序中的应用程序ID,然后在OPTIOS的LINKER中把 include remote debug sysbols打上勾,就可以支持远程调试了,然后在另外的程序中调用DLL就可以进入此DLL进行调试了
unit mainfrm;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,stdctrls,mask;type
TForm1 = class(TForm)
lblTotal: TLabel;
lblQlbl: TLabel;
lblquarters: TLabel;
lblplbl: TLabel;
lblnlbl: TLabel;
lblDlbl: TLabel;
lblpennies: TLabel;
lblnickels: TLabel;
lbldimes: TLabel;
Button1: TButton;
MaskEdit1: TMaskEdit;
procedure MaskEdit1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation
uses
penniesint;
{$R *.dfm}procedure TForm1.MaskEdit1Change(Sender: TObject);
var
coinsrec:tcoinsrec;
TotPennies:word;
begin
TotPennies:=PenniesToCoins(strtoint(maskedit1.text),@coinsrec);
with coinsrec do
begin
lblquarters.caption:=inttostr(quarters);
lbldimes.caption:=inttostr(dimes);
lblnickels.caption:=inttostr(nickels);
lblpennies.caption:=inttostr(pennies);
end;
end;end.运行时出错:project d:\mu\pm.exe faulted with message:'access violation at 0x77f849b:write of address 0x00030cb4'.Process Stopped.Use Step or Run to continue.这是什么意思?
register 自左向右 被调例程 是
pascal 自左向右 被调例程 否
cdecl 自右向左 调用者 否
stdcall 自右向左 被调例程 否
safecall 自右向左 被调例程 否 这里的指示字就是在声明函数或过程时附加在例程标题之后的保留字,默认为register,即是 唯一使用 CPU寄存器的参数传递方式,也是传递速度最快的方式; pascal: 调用协议仅用于向后兼容,即向旧的版本兼容;
cdecl: 多用于 C和 C++语言编写的例程,也用于需要由调用者清除参数的例程;
stdcall: 和safecall主要用于调用Windows API 函数;其中safecall还用于双重接口。
在本例中,将使用调用协议cdecl ,因为被调用的 DLL中,使用的数据库连接是由主叫方传递 得到的,并且需要由主叫方处理连接的关闭和销毁。 下面是 DLL完整源程序和主叫程序完整源程序。包括以下四个文件: Project1.DPR {主叫程序}
Unit1.PAS {主叫程序单元}
Project2.DPR {DLL}
Unit2.PAS {DLL单元}
{---------- DLL 主程序 Project2.DPR ----------} library Project2; uses
SysUtils,
Classes,
Unit2 in ‘Unit2.pas‘ {Form1}; {$R *.RES} { 下面的语句用于向调用该 DLL的程序提供调用接口 }
exports
DoTest; { 过程来自单元Unit2 } begin
end.