安装钩子 SetWindowsHookE

SetWindowsHookEx 函数应用程序定义钩子 安装 一个 安装 一个 钩子 监测 系统 某些 类型 事件这些 事件 特定线程 所有 线程 调用 线程 作为 同一 桌面 相关联

Syntax

HHOOK SetWindowsHookEx(      

    int idHook,     HOOKPROC lpfn,     HINSTANCE hMod,     DWORD dwThreadId );

Parameters

idHook
[in] 指定要安装的钩子的类型.可以是以下一个值:
WH_CALLWNDPROC
安装 之前 系统会将 它们 发送 目标 窗口 过程 监视 消息钩子更多信息 请参阅 CallWndProc 挂钩 过程
WH_CALLWNDPROCRET
安装 一个 钩子 监视 消息 他们 目标 窗口 过程 处理更多信息 请参阅 CallWndRetProc 挂钩 过程
WH_CBT
安装 一个 钩子 接收 通知 基于计算机 培训 (CBT)应用程序 很有用更多信息 请参阅 CBTProc 挂钩 过程
WH_DEBUG
安装 一个 钩子 调试 其他 钩子 程序 非常有用有关 详细 信息 请参阅 挂钩 过程 DebugProc
WH_FOREGROUNDIDLE
Installs a hook procedure that will be called when the application's foreground thread is about to become idle. This hook is useful for performing low priority tasks during idle time. For more information, see the ForegroundIdleProc hook procedure.
WH_GETMESSAGE
安装 一个 钩子 监视 消息 发送 消息 队列更多信息 请参阅 GetMsgProc 挂钩 过程
WH_JOURNALPLAYBACK
安装 一个 钩子 员额 WH_JOURNALRECORD 挂接 程序 以前 记录消息更多信息 请参阅 指定 挂接 程序
WH_JOURNALRECORD
安装 一个 钩子 记录 输入系统 消息 队列 发布 消息 用于 录制更多信息 请参阅 JournalRecordProc 挂钩 过程
WH_KEYBOARD
安装 一个 钩子 监视 键盘 消息更多信息 请参阅 KeyboardProc 挂钩 过程
WH_KEYBOARD_LL
Windows NT/2000/XP: 
安装 一个 钩子 监视 低级 键盘 输入事件更多信息 请参阅 LowLevelKeyboardProc 挂钩 过程
WH_MOUSE
安装 一个 钩子子程用 监视 鼠标 消息更多信息 请参阅 MouseProc 挂钩 过程
WH_MOUSE_LL
Windows NT/2000/XP:
安装 一个 钩子 监视 低级 鼠标 输入事件更多信息 请参阅 LowLevelMouseProc 挂钩 过程
WH_MSGFILTER
安装 一个 钩子 监视 对话框 消息 菜单 滚动 输入 事件 生成消息更多信息 请参阅 MessageProc 挂钩 过程
WH_SHELL
安装 一个 钩子 接收 通知 到 外壳 应用程序 非常有用更多信息 请参阅 ShellProc 挂钩 过程
WH_SYSMSGFILTER
安装 一个 钩子 监视 对话框 、 消息 框 、 菜单 或 滚动 栏 中 输入 事件 生成的 消息。 挂接 程序 监视 这些 相同桌面 作为 调用 线程 所有 应用程序消息更多信息 请参阅 SysMsgProc 挂钩 过程
lpfn
[in] 
挂接 程序指针如果 dwThreadId 参数 指定 不同进程 创建 线程 标识符 lpfn 参数 必须 指向 一个 钩子 DLL 否则 lpfn 可以 指向 一个 钩子 当前 进程 关联 代码
hMod
[in] 
包含 lpfn 参数指向挂接 程序 DLL句柄如果 参数 dwThreadId 指定 当前 进程 创建 一个 线程 如果 挂接 程序 当前 进程 关联 代码必须 hMod 参数 设置 NULL
dwThreadId
[in]
包含 由 lpfn 参数所 指向的 挂接 程序 的 DLL 的 句柄。 如果 参数 dwThreadId 指定 由 当前 进程 创建 一个 线程 , 如果 挂接 程序 内 与 当前 进程 关联 的 代码, 必须 将 hMod 参数 设置 为 NULL。

Return Value

如果成功,返回钩子句柄

如果失败,返回NULL



Remarks

SetWindowsHookEx can be used to inject a DLL into another process. A 32-bit DLL cannot be injected into a 64-bit process, and a 64-bit DLL cannot be injected into a 32-bit process. If an application requires the use of hooks in other processes, it is required that a 32-bit application call SetWindowsHookEx to inject a 32-bit DLL into 32-bit processes, and a 64-bit application call SetWindowsHookEx to inject a 64-bit DLL into 64-bit processes. The 32-bit and 64-bit DLLs must have different names.

An error may occur if the hMod parameter is NULL and the dwThreadId parameter is zero or specifies the identifier of a thread created by another process.

Calling the CallNextHookEx function to chain to the next hook procedure is optional, but it is highly recommended; otherwise, other applications that have installed hooks will not receive hook notifications and may behave incorrectly as a result. You should call CallNextHookEx unless you absolutely need to prevent the notification from being seen by other applications.

Before terminating, an application must call the UnhookWindowsHookEx function to free system resources associated with the hook.

The scope of a hook depends on the hook type. Some hooks can be set only with global scope; others can also be set for only a specific thread, as shown in the following table.

HookScope
WH_CALLWNDPROCThread or global
WH_CALLWNDPROCRETThread or global
WH_CBTThread or global
WH_DEBUGThread or global
WH_FOREGROUNDIDLEThread or global
WH_GETMESSAGEThread or global
WH_JOURNALPLAYBACKGlobal only
WH_JOURNALRECORDGlobal only
WH_KEYBOARDThread or global
WH_KEYBOARD_LLGlobal only
WH_MOUSEThread or global
WH_MOUSE_LLGlobal only
WH_MSGFILTERThread or global
WH_SHELLThread or global
WH_SYSMSGFILTERGlobal only

For a specified hook type, thread hooks are called first, then global hooks.

The global hooks are a shared resource, and installing one affects all applications in the same desktop as the calling thread. All global hook functions must be in libraries. Global hooks should be restricted to special-purpose applications or to use as a development aid during application debugging. Libraries that no longer need a hook should remove its hook procedure.

Windows 95/98/Me: SetWindowsHookEx is supported by the Microsoft Layer for Unicode (MSLU). However, it does not make conversions. To see Unicode messages, notifications, and so forth, you must subclass the window. To use this version of the API, you must add certain files to your application, as outlined in Installing and Releasing Hook Procedures.

转载于:https://www.cnblogs.com/dzqdzq/p/3250993.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值