Delphi dll的使用

DLL定义

library SUM;

{ 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,
  Uni_dllFile in 'Uni_dllFile.pas';

{$R *.res}
  exports
   sum1;
begin
end.

 

unit Uni_dllFile;

interface
  function sum1(a,b:Integer):Integer;stdcall;
implementation
  function sum1(a,b:Integer):Integer;
  begin
    Result:=a+b;
  end;  
end.

 

 

调用

unit Uni_sum;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Edit2: TEdit;
    Label1: TLabel;
    Button1: TButton;
    edit3: TEdit;
    edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
   function sum1(a,b:Integer):Integer;stdcall;external 'dall_pak\SUM.dll';
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
 edit3.Text:=IntToStr(sum1(strToint(edit1.Text),strToint(edit2.Text)));
end;

end.

 

 

posted on 2015-01-07 19:37  @冰糖  阅读(179)  评论(0编辑  收藏  举报

导航