DelPhi 2020. 4. 12. 14:00

{ 여기서 부터 dll 작성부분이다 }

{ 여기서 두함수가 DLL 함수가 된다 }

library Firstdll;

uses

Windows;

 

function Triple( N : Integer) : Integer; stdcall;

begin

MessageBox(0,'Triple function called',

'First Dll',mb_Ok);

Result := N * 3;

end;

function Double( N : Integer) : Integer; stdcall;

begin

MessageBox(0,'Double function called',

'First Dll',mb_Ok);

Result := N * 2;

end;

exports

Triple , Double;

begin

end.

{ 여기까지가 Dll 작성 루틴이다 }

{ 여기서 부터는 DLL 에 있는 함수를 호출하는것을 보여주는 예이다.}

unit dllcall;

interface

uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

StdCtrls, Spin;

type

TForm1 = class(TForm)

Button1: TButton;

Button2: TButton;

SpinEdit1: TSpinEdit;

SpinEdit2: TSpinEdit;

procedure Button1Click(Sender: TObject);

procedure Button2Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

{ DLL 함수를 선언한다 }

function Double( N : Integer) : Integer;

stdcall; external 'FirstDll.dll';

function Triple( N : Integer) : Integer;

stdcall; external 'FirstDll.dll';

implementation

{$R *.DFM}

{DLL 함수의 호출}

procedure TForm1.Button1Click(Sender: TObject);

begin

SpinEdit1.Value := Double(SpinEdit1.Value);

end;

procedure TForm1.Button2Click(Sender: TObject);

begin

SpinEdit2.Value := Triple(SpinEdit2.Value);

end;

end.

----- Dfm 파일 -----

object Form1: TForm1

Left = 200

Top = 108

Width = 328

Height = 156

Caption = 'Form1'

Font.Charset = DEFAULT_CHARSET

Font.Color = clWindowText

Font.Height = -11

Font.Name = 'MS Sans Serif'

Font.Style = []

PixelsPerInch = 96

TextHeight = 13

object Button1: TButton

Left = 24

Top = 24

Width = 75

Height = 25

Caption = 'Double'

TabOrder = 0

OnClick = Button1Click

end

object Button2: TButton

Left = 24

Top = 80

Width = 75

Height = 25

Caption = 'Triple'

TabOrder = 1

OnClick = Button2Click

end

object SpinEdit1: TSpinEdit

Left = 144

Top = 24

Width = 121

Height = 22

MaxValue = 0

MinValue = 0

TabOrder = 2

Value = 0

end

object SpinEdit2: TSpinEdit

Left = 144

Top = 80

Width = 121

Height = 22

MaxValue = 0

MinValue = 0

TabOrder = 3

Value = 0

end;

end;

posted by 핵커 커뮤니티
: