终于写好了 Hook API 的控件了,发分庆贺~~(200分)

  • 主题发起人 白河愁
  • 开始时间
LZ,先恭喜你~<br>然后,发出来让大家试试<br><br>2CCC.com 有类似源码,http://www.2ccc.com/article.asp?articleid=2075
 
to webz<br><br>你的是鼠标与键盘钩子.<br>别人说的是 Hook API <br><br>两回事.
 
楼主好功力。<br>您的HookAPI组件能否可以考虑授权移植入CnPack的组件包中?<br>我们的网址和介绍: http://www.cnpack.org
 
刚看了下介绍似乎不错,等回公司后安装看看先......
 
弄了半天还是弄不好 DLL, <br><br> &nbsp;TOnAPIMessage = procedure(const MSG: string) of object;<br> &nbsp;TOnAPIHookProc = function(const aParam: array of DWORD): DWORD of object;<br> &nbsp;TOnAPIErrorCode = procedure(const ErrorCode: DWORD) of object;<br><br>象这样的函数,如何做成回调函数......
 
savetime的作品,类成员函数转 Windows 回调函数:<br>http://www.delphibbs.com/keylife/iblog_show.asp?xid=8603
 
谢谢,研究看看先.
 
回调方法:<br>DLL中的代码:<br>type<br>TOnAPIMessage = procedure(const MSG: string);<br><br>procedure testmsg(xx:string;callback:TOnAPIMessage);stdcall;<br>bgin<br>callback(xx);<br>end;<br><br>EXE调用:<br><br>type<br>TOnAPIMessage = procedure(const MSG: string);<br>procedure testmsg(xx:string;callback:TOnAPIMessage);stdcall; ...........<br><br>procedure APIMessage(const msg:String);<br>begin<br>showmessage(msg);<br>end;<br><br>procedure tform1.button1click(sender:tobject);<br>begin<br>testmsg('xxxxxxxxxxxxx',APIMessage);<br>end;
 
但关键是这个东西....<br><br>TOnAPIHookProc = function(const aParam: array of DWORD): DWORD of object;
 
给你个例子:<br><br>// 这个是被 hook 的函数<br>function Test2(a1, a2, a3, a4: LongWord): LongWord; stdcall;<br>begin<br> &nbsp;Writeln('a1: ', a1, '; a2: ', a2, '; a3: ', a3, '; a4: ', a4);<br> &nbsp;Writeln('Test2 called.');<br> &nbsp;Result := 2;<br>end;<br><br>// 这个是 hook 的 event:回调<br>procedure Test3(a0, a1, a2, a3, a4: LongWord); cdecl;<br>begin<br> &nbsp;Writeln('a1: ', a1, '; a2: ', a2, '; a3: ', a3, '; a4: ', a4);<br> &nbsp;Writeln('Test3 called.');<br>end;<br><br>// 你插进去的处理 hook 的函数<br>procedure Test4(); stdcall;<br>begin<br> &nbsp;asm<br> &nbsp; &nbsp;pop &nbsp;callBack &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// callBack<br> &nbsp; &nbsp;push $1<br><br> &nbsp; &nbsp;call Test3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // event for hook, no change sp<br><br> &nbsp; &nbsp;pop &nbsp;eax &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // a0, call Test2 ?<br> &nbsp; &nbsp;call Test2<br> &nbsp; &nbsp;<br> &nbsp; &nbsp;push callBack &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// callBack<br> &nbsp; &nbsp;mov &nbsp;callBack, $0<br> &nbsp;end;<br>end;
 
我设计成这样:<br>用户的 hook event 多第一个参数:a0,用来指明是否继续调用这个 hook,默认 push $1<br>处理 hook 的函数 test4 是挂接 hook 的时候你自己填出来的,其中填入了包括 hook 的函数和 hook event 的地址,另外一个变量 callBack 指明是否进入了你的 hook 控制内<br><br>这种设计的好处是,你的 hook 处理代码很少(你适当加一点控制代码即可),速度很快,用户的 hook event 函数非常好写,参数全部都有了
 
终于弄好回调函数了,写个抓数据包的demo就发表...
 
楼主真厉害,恭贺啊!
 
楼主怎么联系啊?<br>我有个很难的问题,问了几个月了,连一个回答我的人都没有,晕!<br><br>问题就是如何获取游戏里的鼠标状态变化,如形状发生变化。问题原文如下:<br>http://www.delphibbs.com/delphibbs/dispq.asp?lid=3552681
 
快点发表控件呀,就等着用了
 
我想请教一下,<br>1.能否用钩子捕获游戏里的鼠标状态变化?如移动鼠标到特定位置,鼠标形状会发生变化。<br>2.能否捕获游戏里的文字状态变化?例如鼠标移到到文字上,文字会发生变色的状态。<br><br>我汇编语言还没学的,看来不学汇编就不能上档次啊,晕
 
哇塞这么多的评论,我先占个地,要慢慢品味各位的东西了。
 
to 16cy:<br>如果不采用系统标准 API, 就不行.一般这些操作都是用游戏自定义的操作,所以要自己分析程序.
 
都等了几天了,怎么还不发布呢?
 
就发了,在整理异常的处理...
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
顶部