unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TFunc =
procedure(State: Integer);
stdcall;
TStdProcProt =
procedure;
stdcall;
TInitProcProt =
procedure (AFunc: TFunc);
stdcall;
TGetHndProcProt =
function : Longword;
stdcall;
TPostProcProt =
procedure (Target: Longword);
stdcall;
TForm1 =
class(TForm)
shpLED: TShape;
btnOn: TButton;
btnOff: TButton;
btnROn: TButton;
btnROff: TButton;
Label1: TLabel;
lblMyHnd: TLabel;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
GroupBox3: TGroupBox;
Label2: TLabel;
edtTrgt: TEdit;
btnToggle: TButton;
procedure btnOnClick(Sender: TObject);
procedure btnOffClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure btnROnClick(Sender: TObject);
procedure btnROffClick(Sender: TObject);
procedure btnToggleClick(Sender: TObject);
private
{ Private-Deklarationen }
fDLLInstance : THandle;
fDLLInit : TInitProcProt;
fDLLOn : TStdProcProt;
fDLLOff : TStdProcProt;
fDLLGetHandle : TGetHndProcProt;
fDLLPost : TPostProcProt;
public
{ Public-Deklarationen }
end;
procedure SetLED(State: Integer);
stdcall;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure SetLED(State: Integer);
stdcall;
begin
if State = 0
then
Form1.shpLED.Brush.Color := clGreen
else
Form1.shpLED.Brush.Color := clLime;
end;
procedure TForm1.btnOnClick(Sender: TObject);
begin
SetLED(1);
end;
procedure TForm1.btnOffClick(Sender: TObject);
begin
SetLED(0);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
fDLLInstance := 0;
@fDLLInit :=
nil;
@fDLLOn :=
nil;
@fDLLOff :=
nil;
@fDLLGetHandle :=
nil;
@fDLLPost :=
nil;
fDllInstance := LoadLibrary('
cbDLL.dll');
if fDllInstance <> 0
then
begin
@fDLLInit := GetProcAddress(fDLLInstance, '
Init');
@fDLLOn := GetProcAddress(fDLLInstance, '
CallOn');
@fDLLOff := GetProcAddress(fDLLInstance, '
CallOff');
@fDLLGetHandle := GetProcAddress(fDLLInstance, '
GetHandle');
@fDLLPost := GetProcAddress(fDLLInstance, '
Post');
end;
fDLLInit(SetLED);
lblMyHnd.Caption := IntToStr(fDLLGetHandle);
end;
procedure TForm1.btnROnClick(Sender: TObject);
begin
fDLLOn;
end;
procedure TForm1.btnROffClick(Sender: TObject);
begin
fDLLOff;
end;
procedure TForm1.btnToggleClick(Sender: TObject);
begin
fDLLPost(StrToInt(edtTrgt.Text));
end;
end.