首页 > Windows开发 > 详细

Delphi dll的使用

时间:2015-01-07 20:28:38      阅读:315      评论:0      收藏:0      [点我收藏+]

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.

 

技术分享

 

Delphi dll的使用

原文:http://www.cnblogs.com/thrive/p/4209194.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!