请给出一个完整的DLL例子-----是要完整的例子!!!
我要的是给出具体细节的例子.

解决方案 »

  1.   

    2个工程文件
    ========================
    {dll工程文件,编译产生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,
      forms,
      windows,
      Classes;{$R *.res}procedure HelloDll(Myform:TForm);
    begin
      MessageBox(Myform.Handle,'Hello My First Dll','DllMessageBox',MB_OK);
    end;
    exports
      HelloDll;
    begin
    end.
    =================================================
    {调用dll函数的工程单元文件,编译后可调用dll文件中的函数}unit dllapp;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure HelloDll(Myform:TForm);external 'project1.dll';procedure TForm1.Button1Click(Sender: TObject);
    begin
      HelloDll(Form1);
    end;end.
      

  2.   

    1.file-->new-->other-->dll wizards生成一个框架,如
    library Test;
    uses WinTypes, WinProcs; 
    begin
    end.
    2.file->new->unit,新建一个unit,再里面写函数(或类)
    function myAdd(x,y:integer):integer;stdcall;
    begin
       result:=x+y;
    end;
    3.把写好的函数放在exports部分,这果文件看起来应该是这样的
    library Test;
    uses WinTypes, WinProcs,myunit in 'myunit';
    exports
          function myAdd(x,y:integer):integer;stdcall;
    begin
    end.
    4.编译生成DLL文件
    5.新建一个工程,在IMPELEMENTATION下声明:
    function myAdd(x,y:integer):integer;stdcall;external 'Test.dll'
    6.调用
    procedure button1click(sender:TObject)
    begin
            edit1.text:=inttostr(myAdd(1+2));
    end;