본문 바로가기

컴터/delphi

dll 만들기 기초

336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

dll1.dll 파일

------------------------------------------------------------------------

library dll1;

{ 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;

{$R *.res}

Function Sun(a, b:Integer) : Integer;  export;
begin
  Result:= a + b;
end;

Function Avg(a, b:Integer) : Integer; export; /////export 는 밖에서 호출 하겠다
begin
  Result:= (a+b) div 2;
end;

exports    /////여기서 실질적으로 호출함.
 Sun;
 Avg;

begin
end.

------------------------------------------------------------------------




실행파일

------------------------------------------------------------------------
unit dlltest;

interface

uses
  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

function Sum(a, b:Integer) : Integer;
   external 'dll1.dll'; //////////해당 dll을 부른다.
 ////pascal은 대소문자를 구분하지 않지만, 유독 dll파일의 함수의 호출시 함수명은 대소문자를 구분한다.

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(IntToStr(Sum(1, 2)));
end;

end.
------------------------------------------------------------------------

'컴터 > delphi' 카테고리의 다른 글

동적 dll 링크  (0) 2007.12.10
TQuery의 묵시적 transaction 을 줄이기 위해.(cachedUpdate : false => true 로 전환)  (0) 2007.11.29
BDE > Query(DBTables) 사용시  (0) 2007.11.29
북마크  (0) 2007.11.28