dll中调试Hook问题(50分)

  • 主题发起人 主题发起人 poy
  • 开始时间 开始时间
P

poy

Unregistered / Unconfirmed
GUEST, unregistred user!
我需要做一个hook的dll ,用于捕捉Desktop的重画事件。如以下HookWord代码 ,事先我先取得desktop的 handle 存在 hDesktop中。在捕捉到消息后,判断是否为desktop的重画事件,如果是就向宿主窗口,发送消息 : postmessage(fCallerHwnd,$0401,0,5);在宿 主窗口有有处理 $0401的消息函数,可是怎么也没起作用,于是向另一个进程的另一窗口发送一消息 postmessage(1573644,100,0,5); 再次执行,这个窗口有消息处理过程执行,而宿主窗口 依旧没有,真是晕死我了,困扰我两天了,各位请帮个忙。<br><br><br>library HookWord;<br>uses<br> &nbsp;SysUtils,Messages,Windows, Classes, &nbsp;Dialogs;<br>type<br> &nbsp; PMyMSG =^tagMyMSG;<br> &nbsp; tagMyMSG =record<br> &nbsp; &nbsp; hwnd &nbsp; :Cardinal;<br> &nbsp; &nbsp; msgCode:UInt;<br> &nbsp; &nbsp; wParam :LongInt;<br> &nbsp; &nbsp; lParam :LongInt;<br> &nbsp; &nbsp; time &nbsp; :DWord;<br> &nbsp; &nbsp; pt &nbsp; &nbsp; :TPoint;<br> &nbsp; end;<br>var<br> &nbsp;fCallerHwnd:HWND;<br> &nbsp;aHooK:HHook &nbsp;;<br><br>function GetMsgProcHook(Code:Integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>var<br> &nbsp; &nbsp;pmHWND :DWORD;<br> &nbsp; &nbsp;hDesktop :DWORD;<br>begin<br><br> &nbsp; &nbsp;hDesktop:=65698 ;<br> &nbsp; &nbsp;pmHWND:=PMyMsg(lparam).hwnd ;<br> &nbsp; &nbsp;if pmHWND =hDesktop then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;if (PMyMSG(lparam).msgCode = WM_PAINT) then<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; postmessage(1573644,100,0,5);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; postmessage(fCallerHwnd,$0401,0,5);<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp;end;<br> &nbsp; &nbsp;Result:=CallNextHookEx(aHooK,code,Wparam,lParam);<br><br>end;<br><br>procedure HookON(aHwnd:HWND);stdcall;<br>begin<br> &nbsp;aHooK :=SetWindowsHookEx(WH_GETMESSAGE ,@GetMsgProcHook,HInstance, 0);<br> &nbsp;fCallerHwnd:=aHwnd;<br>end;<br><br>procedure UnHook;stdcall;<br>begin<br> &nbsp;UnHookWindowsHookEx(aHook);<br>end;<br><br>{$R *.res}<br>exports<br> &nbsp;HookON,unHook ;<br>begin<br>end.
 
错在这儿:<br>aHooK :=SetWindowsHookEx(WH_GETMESSAGE ,@GetMsgProcHook,HInstance, 0);<br> &nbsp;fCallerHwnd:=aHwnd;<br>fCallerHwnd虽然是全局变量不过在HOOK里面不起作用。<br>要用“File Mapping Functions”建立共享内存(shared memory)。网上有很多Hook的例子可以作为参考。
 
接受答案了.
 
后退
顶部