DLL源码如下:
library ExampleDLL;{ 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,
  windows,
  forms,
  Classes;{$R *.res}
function Getmax(para1:integer;para2:integer):integer;stdcall;
begin
        if para1>para2 then result:=para1
        else result:=para2;
end;exports
        getmax;   
end.
程序调用源码如下:
unit Unit1;
 interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,sharemem;type
  TForm1 = class(TForm)
    Edit1: TEdit;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementationfunction getmax(para1,para2:integer):integer;stdcall;external 'exampledll.dll' name 'getmax';
{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
 var
        ddd:integer;
begin
       ddd:=getmax(2,5);
       edit1.text:=inttostr(ddd);
end;end.

解决方案 »

  1.   

    library ExampleDLL;{ 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,
      windows,
      forms,
      Classes;{$R *.res}
    function getmax(para1:integer;para2:integer):integer;stdcall;  //DLL函数要注意大小写和下面的exports段的一致要
     
    begin
            if para1>para2 then result:=para1
            else result:=para2;
    end;exports
            getmax;   
    end.
      

  2.   

    DELPHI是不分大小写的,没想到这里竟然分大小写!!!!