dll问题 (100分)

  • 主题发起人 主题发起人 xwhjq
  • 开始时间 开始时间
X

xwhjq

Unregistered / Unconfirmed
GUEST, unregistred user!
我的程序如下:var th1:thandle; function HookProc(Code: Integer; WParam: Longint; var Msg: TMsg): Longint; stdcall;
var
pt:tpoint;
s,s1,s2,s3,s4:string;
begin

Result:=0;
if Code<0 then exit;
if (Msg.Message<>WM_KEYDOWN) and (Msg.Message<>WM_KEYUP) then
begin
s3:=inttostr(Msg.Message);
message_s(Msg.Message,s1,s2);
s:=s1+' '+s2+' '+s3;

SendMessage(th1,WM_SETTEXT,0,Integer(pchar(s)));

end;
Result := CallNextHookEx(hhook, Code, WParam, Longint(@Msg));
end;

Procedure Load (TID : dWord;h:thandle); stdcall;
Begin
th1:=h; // showmessage(inttostr(th1));
if hHook=0 then hHook:=SetWindowsHookEx(WH_GETMESSAGE,@HookProc,hInstance,TID); //

end; 为何th1 在HookProc中总被置为0?
 
Hook in dll, you must set as following:
hHook:=SetWindowsHookEx(WH_GETMESSAGE,@HookProc,hInstance,0);
 
我只搜索某一程序
 
You have called Load in your process, so in your process, th1 is a valid
handle(nonzero), but every process have one copy of dll data, so in other
process, th1 is initialized to zero, of course it it zero.
You can use MappingFile to share data in two process.
 
1、你想将系统发给别的进裎的键盘消息先发给你,但是这种Hook一定要放在
Dll中由宿主Process调用。
2、另外你程序中的TID参数是如何得来的,要知道这样调用SetWindowsHookEx函数
你的Hook回调函数只和这个线裎有关联。
3、能否确定TID线程是窗口线程。

总之我觉得你写的代码不好,似乎对Windows的理解还不够深入。
关于以下这些Hook类型
WH_CALLWNDPROC
WH_CALLWNDPROCRET
WH_CBT
WH_DEBUG
WH_FOREGROUNDIDLE
WH_GETMESSAGE
WH_JOURNALRECORD
WH_KEYBOARD
WH_KEYBOARD_LL
WH_MOUSE
WH_MOUSE_LL
WH_MSGFILTER
WH_SHELL
WH_SYSMSGFILTER
虽然入口一样,但系统的要求却不同,建议看看msdn/windows development/
sdk document/user interface/hooks一节。
 
多人接受答案了。
 

Similar threads

后退
顶部