HOOK问题求救!(200分)

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

x44348428

Unregistered / Unconfirmed
GUEST, unregistred user!
请问为什么我的程序就只能是局部hook,不能全局。我写dll了,也建共享内存了。谢谢!<br>基本代码如下:<br>
代码:
function MsgHookProc(xiCode: Integer;xwParam: WPARAM;xlParam: LPARAM): LRESULT; stdcall; <br>var <br>&nbsp; LMsgInfo: PMsgInfo; <br>begin <br>&nbsp; if xiCode &nbsp;&lt; 0 then <br>&nbsp; &nbsp; Result:=CallNextHookEx(MsgHookHandle,xiCode,xwParam,xlParam) <br>&nbsp; else <br>&nbsp; if (xiCode = HC_ACTION) then <br>&nbsp; begin <br>&nbsp; &nbsp; if (PCWPRetStruct(xlParam)^.hwnd = pSharedMem^.HWndSpy) then <br>&nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; //走不到这里。 <br>&nbsp; &nbsp; end; <br>&nbsp; &nbsp; Result:=CallNextHookEx(MsgHookHandle,xiCode,xwParam,xlParam); <br>&nbsp; end; <br>end;
<br>----------------------<br>挂钩代码:<br>
代码:
function StartHook(AHSpyWnd,AHRevWnd: THandle;MessageID: Word): BOOL; stdcall;<br>begin<br>&nbsp; Result:=False;<br>&nbsp; if MsgHookHandle &lt;&gt; 0 then<br>&nbsp; &nbsp; Exit;<br>&nbsp; pSharedMem^.HWndSpy:=AHSpyWnd;<br>&nbsp; pSharedMem^.HRevWnd:=AHRevWnd;<br>&nbsp; //pSharedMem^.MessageID:=MessageID;<br>&nbsp; MsgHookHandle:=SetWindowsHookEx(WH_CALLWNDPROCRET,@MsgHookProc,HInstance,0);<br>&nbsp; Result:=MsgHookHandle&lt;&gt;0;<br>end;
 
MsgHookHandle:=SetWindowsHookEx(WH_CALLWNDPROCRET,@MsgHookProc,HInstance,0);<br>--&gt;<br>MsgHookHandle:=SetWindowsHookEx(WH_CALLWNDPROCRET,@MsgHookProc,0,0);
 
楼上的: HInstance的写法没错<br><br>我觉得是挂的HOOK不对吧 WH_CALLWNDPROCRET这个hook是目标窗体处理完的message之后才会到你的钩子函数,意思就是说如果在窗口处理函数中中止传递的话,压根就不会到你的函数。所以应该钩这个 WH_CALLWNDPROC
 
to wonhunter:<br>&nbsp;谢谢!但是我用这种方法钩当前进程是好使的啊,换成全局钩子就不行了。
 
还有,我换成WH_CALLWNDPROC后怎么连当前线程都钩不到了啊?也是不行啊 好像 help!
 
The WH_CALLWNDPROC and WH_CALLWNDPROCRET hooks enable you to monitor messages sent to window procedures by the SendMessage function. Windows calls a WH_CALLWNDPROC hook procedure before passing the message to the receiving window procedure, and calls the WH_CALLWNDPROCRET hook procedure after the window procedure has processed the message. <br>The WH_CALLWNDPROC and WH_CALLWNDPROCRET hooks可以监视用SendMessage函数发送到指定窗口的消息。windows在发送这些消息到指定窗口消息处理过程之前会调用WH_CALLWNDPROC hook,在指定窗口过程处理完消息后会调用WH_CALLWNDPROCRET hook <br>楼主对对你的需求
 
谢谢各位的回答,问题已经解决了。其实问题木有存在,本来就好使的。只是我测试的时候把测试文件写被钩程序目录了。自己还很傻的找不到原因。真是丢脸啊,呵呵。结贴!谢谢大家!
 
后退
顶部