dll调用(一)
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons;
type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Memo1: TMemo;
Button1: TButton;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
isHookInstalled:Boolean;
public
{ Public declarations }
end;
{DLL 中的函数声明}
function SetHook: Boolean; stdcall;
function DelHook: Boolean; stdcall;
procedure PrintHook;stdcall;
var
Form1: TForm1;
implementation
{$R *.dfm}
{DLL 中的函数实现, 也就是说明来自那里, 原来叫什么名}
function SetHook; external 'KeyboardHook.dll' name 'SetHook';
function DelHook; external 'KeyboardHook.dll' name 'DelHook';
procedure PrintHook; external 'KeyboardHook.dll' name 'PrintHook';
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
Self.BitBtn1.Enabled:=False;
Self.BitBtn2.Enabled:=True;
Self.Button1.Enabled:=True;
if SetHook then
begin
isHookInstalled:=True;
Self.Memo1.Lines.Add('键盘钩子已安装。。。');
end;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
if DelHook then
begin
isHookInstalled:=False;
Self.Memo1.Lines.Add('键盘钩子已撤销!!!');
Self.Memo1.Lines.Add(' ');
end;
Self.BitBtn1.Enabled:=True;
Self.BitBtn2.Enabled:=False;
Self.Button1.Enabled:=False;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
PrintHook;
Self.Memo1.Lines.Add('已打印');
end;
end.