[델파이] 델파이에서 정말 간단한 DLL 만들고 그것을 사용하기 예제
델파이 DLL 만들기
library FirstDll;
uses
SysUtils, Classes, Windows;
{$R *.res}
// 더하기
function NumPlus(iA, iB: Integer): Integer; stdcall;
begin
Result := iA + iB;
end;
// 메세지 박스 표시하기
function MsgBoxYN(pcMsg: PChar; pcTitle: PChar): BOOL; stdcall;
begin
Result := (MessageBox(0, pcMsg, pcTitle, MB_YESNO or MB_ICONQUESTION) = IDYES);
end;
exports
NumPlus,
MsgBoxYN;
begin
end.
델파이에서 만든 DLL 사용하기
unit uMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm2 = class(TForm)
edtNumA: TEdit;
edtNumB: TEdit;
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
edtTitle: TEdit;
edtMsg: TEdit;
Label3: TLabel;
Label4: TLabel;
Button2: TButton;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
// DLL 함수 선언
function NumPlus(iA, iB: Integer): Integer; stdcall; external 'FirstDll.dll';
function MsgBoxYN(pcMsg: PChar; pcTitle: PChar): BOOL; stdcall; external 'FirstDll.dll';
implementation
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
var
iRet : integer;
begin
iRet := NumPlus(StrToInt(edtNumA.Text), StrToInt(edtNumA.Text));
Button1.Caption := IntToStr(iRet);
end;
procedure TForm2.Button2Click(Sender: TObject);
begin
MsgBoxYN(PChar(edtTitle.Text), PChar(edtMsg.Text));
end;
end.

예제 소스