钩子初接触(十一)

本文详细介绍了DebugProc钩子子程的功能及应用。它作为回调函数,在系统调用任何类型的钩子前被触发,用于检查并决定是否允许钩子执行。文章还提供了DebugProc的语法及参数说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

方法6  :  DebugProc Function

The DebugProc hook procedure is an application-defined or library-defined callback function used with the SetWindowsHookEx function. The system calls this function before calling the hook procedures associated with any type of hook. The system passes information about the hook to be called to the DebugProc hook procedure, which examines the information and determines whether to allow the hook to be called.

DebugProc钩子子程是和SetWindowsHookEx方法一起使用的、程序定义的或者库定义的回调函数。系统在调用和任何类型钩子相关联的钩子子程之前调用该方法。系统将即将被调用的钩子的信息传递给DebugProc钩子子程,DebugProc钩子子程检查该信息,决定是否允许该钩子被调用。

The HOOKPROC type defines a pointer to this callback function. DebugProc is a placeholder for the application-defined or library-defined function name. HOOKPROC类型定义了指向该回调函数的指针。DebugProc是程序定义的或者库定义的方法名字。

Syntax 语法

LRESULT CALLBACK DebugProc(      
    int nCode,

    WPARAM wParam,

    LPARAM lParam

);

Parameters参数

nCode [in] Specifies whether the hook procedure must process the message. If nCode is HC_ACTION, the hook procedure must process the message. If nCode is less than zero, the hook procedure must pass the message to the CallNextHookEx function without further processing and should return the value returned by CallNextHookEx.

指定钩子子程是否必须处理该消息。如果nCodeHC_ACTION,钩子子程就必须处理该消息。如果nCode小于0,钩子子程就必须将该消息传递给CallNextHookEx方法,自己对消息不做进一步处理,并且应该返回由CallNextHookEx方法返回的返回值。

wParam [in] Specifies the type of hook about to be called. This parameter can be one of the following values. 指定即将被调用的钩子类型。参数可以是下列之一:

1WH_CALLWNDPROC Installs a hook procedure that monitors messages sent to a window procedure. 安装一个钩子子程来监视发送给窗体程序的消息。

2WH_CALLWNDPROCRET Installs a hook procedure that monitors messages that have just been processed by a window procedure. 安装一个钩子子程来监视刚刚被窗体程序处理完的消息。

3WH_CBT Installs a hook procedure that receives notifications useful to a computer-based training (CBT) application. 安装一个钩子子程来接收对CBT应用程序有用的通知。

4WH_DEBUG Installs a hook procedure useful for debugging other hook procedures. 安装一个有用的钩子子程来调试其他钩子子程。

5WH_GETMESSAGE Installs a hook procedure that monitors messages posted to a message queue. 安装一个钩子子程来监视传递给消息队列的消息。

6WH_JOURNALPLAYBACK Installs a hook procedure that posts messages previously recorded by a WH_JOURNALRECORD hook procedure. 安装一个钩子子程来传递先前使用WH_JOURNALRECORD钩子子程记录的消息。

7WH_JOURNALRECORD Installs a hook procedure that records input messages posted to the system message queue. This hook is useful for recording macros. 安装一个钩子子程来记录传递给系统消息队列的输入消息。该钩子用来记录宏很有用。

8WH_KEYBOARD Installs a hook procedure that monitors keystroke messages. 安装一个钩子子程来监视键盘敲击消息。

9WH_MOUSE Installs a hook procedure that monitors mouse messages. 安装一个钩子子程来监视鼠标消息。

10WH_MSGFILTER Installs a hook procedure that monitors messages generated as a result of an input event in a dialog box, message box, menu, or scroll bar. The hook procedure monitors these messages only for the application that installed the hook procedure. 安装一个钩子子程来监视下列输入事件的结果而产生的消息:对话框、消息框、菜单、滚动条。该钩子子程仅仅为安装该钩子子程的应用程序监视这些消息。

11WH_SHELL Installs a hook procedure that receives notifications useful to a Shell application. 安装一个钩子子程来接收对加壳类应用程序有用的通知。

12WH_SYSMSGFILTER Installs a hook procedure that monitors messages generated as a result of an input event in a dialog box, message box, menu, or scroll bar. The hook procedure monitors these messages for all applications in the system. 安装一个钩子子程来监视下列输入事件的结果而产生的消息:对话框,消息框,菜单,滚动条。该钩子子程为系统中所有的应用程序监视这些消息。

lParam  [in] Pointer to a DEBUGHOOKINFO structure that contains the parameters to be passed to the destination hook procedure. 指向DEBUGHOOKINFO结构的指针,该结构中含有传递给目标钩子子程的参数。

Return Value返回值

To prevent the system from calling the hook, the hook procedure must return a nonzero value. Otherwise, the hook procedure must call CallNextHookEx.

为了阻止系统调用该钩子,钩子子程必须返回一个非0值。否则,钩子子程必须调用CallNextHookEx方法。

Remarks备注

An application installs this hook procedure by specifying the WH_DEBUG hook type and the pointer to the hook procedure in a call to the SetWindowsHookEx function.

应用程序通过下面方式安装该钩子子程:指定WH_DEBUG钩子类型;在调用SetWindowsHookEx方法的函数中指向钩子子程的指针。

Helios 2007-04-12

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值