我是照《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的具体步骤。谢谢!

解决方案 »

  1.   

    他告诉你DLL文件不能单独运行。必须用菜单Run|Parameters来捆绑一个EXE文件来调试执行
      

  2.   

    dll本身怎么能运行呢?
    要再写一个EXE来调用DLL
      

  3.   

    是不是写好上面的这些再新建一个工程?我要保存上面的这个project1用.dll结尾咋不行。
    能否有一个具体的步骤,从建立到保存再到引用,谢谢
      

  4.   

    DLL做为一个单独的工程。然后另外建立一个工程,编译成为EXE文件,在程序中调用DLL文件即可。
      

  5.   

    你将此library当作一般的项目保存,编译后(不能运行)在同一目录下将出现一个***.DLL(如果你的程序正确地话) 然后你可以在其他项目中使用它了.使用如下:
    新建一个项目

    implementation下面加上
    function penniestocoins(totpennies:word;coinsrec:pcoinsrec):word;stdcall;far;external '***.dll';
    此后,DLL中的方法就可以在这个项目中用了.试试看.
      

  6.   

    自己写一个测试的EXE,然后绑定这个DLL进行测试
      

  7.   

    先在控制面板中的管理工具中的组件服务中把你的DLL文件安装到COM+环境中,然后在DELPHI\RUN\PARAMETERS设置相应的参数。
    host application 可以用C:\WINNT\system32\dllhost.exe
    parameters 中加入你的DLL文件在COM+应用程序中的应用程序ID,然后在OPTIOS的LINKER中把 include remote debug sysbols打上勾,就可以支持远程调试了,然后在另外的程序中调用DLL就可以进入此DLL进行调试了
      

  8.   

    多谢各位,对于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.这是什么意思?
      

  9.   

    pm.exe 里面调用dll是怎么写的?
      

  10.   

    你的dll文件没问题,提示的是:dll文件不能独立运行你用Project->Build All来生成完整的dll文件就可以了,如果提示你:BuildAll,这是你就放心的调用好了。//祝你变成愉快@_@
      

  11.   

    我就在mainfrm中uses penniesint
      

  12.   

    晕~根据Delphi提供的有关 DLL编写和调用的帮助信息,你可以很快完成一般的 DLL编写和调用的 应用程序。本文介绍的主题是如何编写和调用能够传递各种参数(包括对象实例)的 DLL。例如, 主叫程序传递给 DLL一个ADOConnection 对象示例作为参数, DLL中的函数和过程调用通过该对象 实例访问数据库。  需要明确一些基本概念。对于 DLL,需要在主程序中包含 exports子句,用于向外界提供调用 接口,子句中就是一系列函数或过程的名字。对于主叫方(调用 DLL的应用程序或其它的 DLL), 则需要在调用之前进行外部声明,即external保留字指示的声明。这些是编写 DLL和调用 DLL必须 具备的要素。  另外需要了解Object Pascal 中有关调用协议的内容。在Object Pascal 中,对于过程和函数 有以下五种调用协议:  指示字 参数传递顺序 参数清除者 参数是否使用寄存器 
      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.