吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 6162|回复: 4
收起左侧

[其他转载] delphi hook dll

[复制链接]
hixiaosheng 发表于 2010-2-11 17:01
调用dll的
unit Unit1; 

interface 

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

type 
TForm1 = class(TForm) 
Button1: TButton; 
Button2: TButton; 
procedure FormClose(Sender: TObject; var Action: TCloseAction); 
procedure Button1Click(Sender: TObject); 
procedure Button2Click(Sender: TObject); 

private 
{ Private declarations } 
public 
{ Public declarations } 
end; 

var 
Form1: TForm1; 
function HookOn(lpHwnd:HWND;lpType:Longint):Longint;stdcall;external 'Hook32.dll' name 'HookOn'; 
function HookOff:Boolean;stdcall;external 'Hook32.dll' name 'HookOff'; 
implementation 

{$R *.dfm} 



procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); 
begin 
hookoff; 
end; 

procedure TForm1.Button1Click(Sender: TObject); 
var 

h1:HWND; 
begin 

h1:=FindWindow(NIL,'无标题 - 记事本');//这是窗口的句柄,要自己找到后,填写入。 
if h1=0 then showmessage('没找到进程!'); 
if h1>0 then showmessage('找到进程!'); 
sleep(2000); 
HookOn(h1,WH_KEYBOARD); 


end; 

procedure TForm1.Button2Click(Sender: TObject); 
begin 
HookOff; 
end; 

end.
-------------------------------------------------------------------------------------------------------
dll源码
library Hook32; 
uses 
SysUtils, 
Forms, 
Classes, 
myDLl in 'myDLl.pas' {Form1}; 
{$R *.res} 
exports 
HookOn,HookOff; 
begin 
{Application.Initialize; 
Application.Run; } 
end.
unit myDLl; 

interface 

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

type 
TForm1 = class(TForm) 
Memo1: TMemo; 

private 
{ Private declarations } 
public 
{ Public declarations } 
end; 

var 
Form1: TForm1; 
function HookProc(nCode:Integer;WParam: WPARAM;LParam:LPARAM):LRESULT;stdcall; 
function HookOn(lpHwnd:HWND;lpType:Longint):Longint;stdcall;export; 
function HookOff:Boolean;stdcall;export; 

implementation 

var 
hHk: HHOOK=0; 
mhwnd:HWND=0; 
bShow:Integer=1; 
hThread: Cardinal; 
hmod: Pointer; //Hinstance 
hProcessId: Cardinal; 
mMode:Integer; 

{$R *.dfm} 

function HookProc(nCode:Integer;WParam: WPARAM;LParam:LPARAM):LRESULT;stdcall; 
begin 

if (bShow=1) And (wParam=VK_F8) then 
begin 
bShow:=5; 
Form1:=TForm1.Create(Application); 
Form1.Show; 
ShowCursor(true); 
end; 
if (bShow=2) And (wParam=VK_F8) then 
begin 
bShow:=6; 
Form1.Free; 
end; 

if (bShow=3) And (wParam=VK_F8) then 
begin 
bShow:=2; 
end; 

if (bShow=4) And (wParam=VK_F8) then 
begin 
bShow:=1; 
end; 
if (bShow=5) then bShow:=3; 
if (bShow=6) then bShow:=4; 
Result := CallNextHookEx(hHk,nCode,WParam,LParam); 
end; 

function HookOn(lpHwnd:HWND;lpType:Longint): Longint;stdcall; export; 
begin 
hThread :=GetWindowThreadProcessId(lpHwnd,hmod); 
if lpHwnd<>0 then hHk :=SetWindowsHookEx(lpType,@HookProc,hInstance,hThread); 
Result :=hHk 
end; 

function HookOff:Boolean;stdcall; export; 
begin 
if hHk<>0 then 
begin 
UnHookWindowsHookEx(hHk); 
hHk :=0; 
Result :=true; 
end 
else 
Result :=false; 
end; 
end. 

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

zhan1616 发表于 2010-3-6 22:53
谢谢分享~!

测试一下~!
sunflover 发表于 2013-6-6 23:40
月光灬指引 发表于 2013-8-8 02:25
小淫仙 发表于 2013-8-8 04:00
欢迎讨论交流,[吾爱破解]有你更精彩!
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-16 08:39

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表