钩子教程 - 原理(四) : 钩子子程

原文地址:http://www.zdexe.com/program/201004/578.html

To take advantage of a particular type of hook, the developer provides a hook procedure and uses the SetWindowsHookEx function to install it into the chain associated with the hook. A hook procedure must have the following syntax:

为了利用某种特定类型的钩子,开发者提供了钩子子程。可以使用SetWindowsHookEx方法将该钩子子程安装到和该钩子相关联的钩子链表中。钩子子程必须具有下面的语法:

LRESULT CALLBACK HookProc
(
  int nCode, 
  WPARAM wParam, 
  LPARAM lParam
);

HookProc is a placeholder for an application-defined name.

HookProc是应用程序定义的名字的占位符。即,HookProc是应用程序定义的名字。

The nCode parameter is a hook code that the hook procedure uses to determine the action to perform. The value of the hook code depends on the type of the hook; each type has its own characteristic set of hook codes. The values of the wParam and lParamparameters depend on the hook code, but they typically contain information about a message that was sent or posted..

参数nCode:钩子代码,钩子子程通过该代码来决定执行什么动作。该值取决于钩子的类型,每种类型都拥有自己特有的钩子代码集合。

参数wParam和lParam的值,都取决于钩子代码。但是一般都包含发送或者传递的消息的信息。

The SetWindowsHookEx function always installs a hook procedure at the beginning of a hook chain. When an event occurs that is monitored by a particular type of hook, the system calls the procedure at the beginning of the hook chain associated with the hook. Each hook procedure in the chain determines whether to pass the event to the next procedure. A hook procedure passes an event to the next procedure by calling the CallNextHookEx function.

方法SetWindowsHookEx总是在钩子链的开始位置安装钩子子程。当被某种类型的钩子监视的事件发生时,系统调用和该钩子相关的位于钩子链表开始位置的钩子子程。每个钩子链表中的钩子子程决定是否将该事件传递给下一个钩子子程。钩子子程通过调用方法CallNextHookEx向下一个钩子子程传递事件。

Note that the hook procedures for some types of hooks can only monitor messages. the system passes messages to each hook procedure, regardless of whether a particular procedure calls CallNextHookEx.

注意:某些类型的钩子子程仅仅能够监视消息,系统不管是否有特殊的钩子子程调用CallNextHookEx方法,都将把消息传递给每个钩子子程,

global hook monitors messages for all threads in the same desktop as the calling thread. A thread-specific hook monitors messages for only an individual thread. A global hook procedure can be called in the context of any application in the same desktop as the calling thread, so the procedure must be in a separate dynamic-link library (DLL) module. A thread-specific hook procedure is called only in the context of the associated thread. If an application installs a hook procedure for one of its own threads, the hook procedure can be in either the same module as the rest of the application‘s code or in a DLL. If the application installs a hook procedure for a thread of a different application, the procedure must be in a DLL. For information, see Dynamic-Link Libraries.

上面的字面意思为:全局钩子监视同一桌面下所有做为调用线程的线程消息。线程钩子仅仅监视该单个线程的消息。全局钩子子程可以在所在桌面下任何应用程序的上下文中被调用,因此,该钩子子程序须在一个单独的动态链接库DLL中。(译者注:在DLL中,可以映射到内存中,从而被所有程序调用)。线程钩子的钩子子程只能在本线程的上下文中被调用。如果应用程序为他自己线程中的某个安装钩子子程,钩子子程能够放在本模块中、应用程序代码的其它部分、Dll中。如果应用程序为另外一个不同的应用程序安装钩子子程,钩子子程必须放在Dll中。参照 DLL 查找更多信息。

个人认为这里理解起来比较费劲。如果这样理解会更好:请参看钩子初接触(二)最后部分。呵呵。

Note   You should use global hooks only for debugging purposes; otherwise, you should avoid them. Global hooks hurt system performance and cause conflicts with other applications that implement the same type of global hook.

注意:只应为了调试目的而使用全局钩子;否则应避免使用。全局钩子会牺牲系统性能。使用了相同类型的全局钩子的应用程序之间也会有冲突。

时间: 2024-08-30 00:19:46

钩子教程 - 原理(四) : 钩子子程的相关文章

钩子教程 - 原理(十六) : KeyboardProc

原文地址:http://www.zdexe.com/program/201004/590.html 方法11 : KeyboardProc Function The KeyboardProc hook procedure is an application-defined or library-defined callback function used with the SetWindowsHookEx function. The system calls this function when

钩子教程 - 原理(十五) : JournalRecordProc

原文地址:http://www.zdexe.com/program/201004/589.html 方法10 : JournalRecordProc Function The JournalRecordProc hook procedure is an application-defined or library-defined callback function used with the SetWindowsHookEx function. The function records mess

钩子教程 - 原理(三)

原文地址:http://www.zdexe.com/program/201004/577.html 勿在浮沙筑高台.继续学习.今天主要学习官方的资料.但是查找到的都是E文,俺只是翻译了一下.全部查找自msdn. Hooks tend to slow down the system because they increase the amount of processing the system must perform for each message. You should install a

钩子教程 - 原理(二)

原文地址:http://www.zdexe.com/program/201004/576.html 比较专业的对钩子的技术性理解 钩子(Hook),是Windows消息处理机制的一个平台,应用程序可以在上面设置子程以监视指定窗口的某种消息,而且所监视的窗口可以是其他进程所创 建的.当消息到达后,在目标窗口处理函数之前处理它.钩子机制允许应用程序截获处理window消息或特定事件. Windows系统是建立在事件驱动的机制上的,说穿了就是整个系统都是通过消息的传递来实现的.而钩子是Windows系

钩子教程 - 原理(一)

原文地址:http://www.zdexe.com/program/201004/575.html 第一步.了解什么是钩子. 我们可以首先从字面上了解钩子,钩子是干什么的呢?日常生活中,我们的钩子是用来钩住某种东西的,比如,说,鱼钩是用来钓鱼的,一旦鱼咬了钩,钩子就一直钩住鱼了,任凭鱼在水里怎么游,也逃不出鱼钩的控制.同样的,Windows的钩子Hook也是用来钩东西的,比较抽象的是他是用来钩Windows事件或者消息的.最常见的就是鼠标和键盘钩子,用Hook钩子钩住鼠标.键盘,当你的鼠标.键盘

php 钩子函数原理 解析

目前对钩子的理解:<转载:http://www.cnblogs.com/del/archive/2008/02/25/1080825.html> 譬如我们用鼠标在某个窗口上双击了一次, 或者给某个窗口输入了一个字母 A; 首先发现这些事件的不是窗口, 而是系统! 然后系统告诉窗口: 喂! 你让人点了, 并且是连续点了两鼠标, 你准备怎么办? 或者是系统告诉窗口: 喂! 有人向你家里扔砖头了, 不信你看看, 那块砖头是 A. 这时窗口的对有些事件会忽略.对有些事件会做出反应: 譬如, 可能对鼠标

C++基础学习教程(四)

2.9字符专题 2.9.1类型同义词 也就是typedef声明,这个东西就是相当于起绰号,为了方便记忆和简化而生.相信在学习其他语言的时候一定有所了解,在此不再赘述. 再次示例一个之前写过的用typedef改写的程序: /************************************************************************* > File Name: char_count.cpp > Author: suool > Mail: [email pr

Photoshop入门教程(四):混合模式

学习心得:混合模式在Photoshop常容易被忽视,最大原因就是它所处的位置比较隐蔽,在图层面板左上部的角落里.使用混合模式,决定图像中上图层像素如何与图像中的下层像素进行混合,使图层的叠加更加炫酷.多种混合模式组合使用,会得到意想不到的结果.在没有灵感的时候,不妨试一试混合模式. 混合模式选项: 变暗模式(减色) 正常 溶解 变暗 正片叠底 颜色加深 线性加深 深色 变亮模式(加色) 变亮 滤色 颜色减淡 线性减淡(添加) 浅色 饱和度模式 叠加 柔光 强光 亮光 线性光 点光 实色混合 差集

Senparc.Weixin.MP SDK 微信公众平台开发教程(四):Hello World

Senparc.Weixin.MP SDK 微信公众平台开发教程(四):Hello World =============  以下写于2013-07-20 ============= 这一篇文章其实可以写在很前面,不过我还是希望开发者们尽多地了解清楚原理之后再下手. 通过上一篇Senparc.Weixin.MP SDK 微信公众平台开发教程(三):微信公众平台开发验证,我们已经使微信客户端发来的信息都可以转发到我们自己的服务器上. 下面将介绍如何处理这些请求,并且返回符合规定格式的数据.当然,这