学习钩子之前,先准备一下即将使用的一些函数和相关内容
在钩子链中安装钩子(具体函数参数作用及解释参考MSDN)
2 __in int idHook,
3 __in HOOKPROC lpfn,
4 __in HINSTANCE hMod,
5 __in DWORD dwThreadId
6 );
Specifies the type of hook procedure to be installed. This parameter can be one of the following values.
这个参数指明安装钩子的类型
Pointer to the hook procedure. If the dwThreadId parameter is zero or specifies the identifier of a thread created by a different process, the lpfn parameter must point to a hook procedure in a DLL. Otherwise, lpfn can point to a hook procedure in the code associated with the current process.
这个参数是钩子函数的指针、如果是系统级钩子则函数必须在DLL中
Handle to the DLL containing the hook procedure pointed to by the lpfn parameter. The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by the current process and if the hook procedure is within the code associated with the current process.
这个没啥好解释、看名字猜猜都知道是什么
Specifies the identifier of the thread with which the hook procedure is to be associated. If this parameter is zero, the hook procedure is associated with all existing threads running in the same desktop as the calling thread.
此参数若为0、则是系统级钩子、否则为模块
函数返回值
Return Value
HHOOK
If the function succeeds, the return value is the handle to the hook procedure.
如果执行成功、返回钩子函数的句柄
If the function fails, the return value is NULL. To get extended error information, call GetLastError.
如果执行失败、返回NULL值(Delphi应该是0)
删除安装的钩子
2 __in HHOOK hhk
3 );
Handle to the hook to be removed. This parameter is a hook handle obtained by a previous call toSetWindowsHookEx.
此参数传递SetWindowsHookEx的返回值
函数返回值:
如果删除钩子成功返回非零值、否则返回零
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
· dotnet 源代码生成器分析器入门
· ThreeJs-16智慧城市项目(重磅以及未来发展ai)
· .NET 原生驾驭 AI 新基建实战系列(一):向量数据库的应用与畅想
· Ai满嘴顺口溜,想考研?浪费我几个小时
· Browser-use 详细介绍&使用文档
· 软件产品开发中常见的10个问题及处理方法