unit UTestDLL2;

interface

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

type
  TForm1 = class(TForm)
    BBeep: TButton;
    Edit1: TEdit;
    BCode: TButton;
    BDialog: TButton;
    BLoad: TButton;
    BUnLoad: TButton;
    procedure BLoadClick(Sender: TObject);
    procedure BBeepClick(Sender: TObject);
    procedure BUnLoadClick(Sender: TObject);
    procedure BCodeClick(Sender: TObject);
    procedure BDialogClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

var H : THandle = 0;
    DoBeep : procedure; stdcall;
    Code: function(S: PChar; Key:integer): PChar; stdcall;
    MyDialog: function(User: PChar): PChar; stdcall;

procedure TForm1.BLoadClick(Sender: TObject);
begin
 H := LoadLibrary('MyDll.dll');
 if H <> 0
 then begin
  DoBeep := GetProcAddress (H,'DoBeep');
  Code := GetProcAddress (H,'Code');
  MyDialog := GetProcAddress (H,'MyDialog');
 end
 else ShowMessage('Не удалось загрузить MyDll.dll');
end;

procedure TForm1.BUnLoadClick(Sender: TObject);
begin
 FreeLibrary(H);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
 while FreeLibrary(H) do;
end;

procedure TForm1.BBeepClick(Sender: TObject);
begin
 DoBeep;
// DoBeep := GetProcAddress (H,'DoBeep');
// if (@DoBeep <> nil) then DoBeep
// else ShowMessage('Библиотека не загружена или функция DoBeep отсутствует в ней');
end;

procedure TForm1.BCodeClick(Sender: TObject);
begin
 Edit1.Text := Code(PChar(Edit1.Text), 5);
end;

procedure TForm1.BDialogClick(Sender: TObject);
begin
 Edit1.Text := MyDialog('Пользователь');
end;

end.
