我想修改 Windows API 中可用的 native 函数,例如 CreateWindowEx
或 ShowWindow
而是调用我的函数,在那里执行任务,然后调用原始的 native 函数。
换句话说,我想以某种方式代理函数,同时仍然使用相同的名称(因此,如果编写程序是为了使用 native API 进行编译,只需添加这些函数就会修改这些 native 函数的方式处理)
HWND WINAPI CreateWindowEx(
__in DWORD dwExStyle,
__in_opt LPCTSTR lpClassName,
__in_opt LPCTSTR lpWindowName,
__in DWORD dwStyle,
__in int x,
__in int y,
__in int nWidth,
__in int nHeight,
__in_opt HWND hWndParent,
__in_opt HMENU hMenu,
__in_opt HINSTANCE hInstance,
__in_opt LPVOID lpParam
) {
//my custom code here....
// done with my custom code... so now I want to run the native function
return CreateWindowEx(dwExStyle, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
}
这(出于明显的原因)导致堆栈溢出,因为它不断地一遍又一遍地调用自己。我希望它做的是,当它被调用时,它运行我创建的自定义函数,然后运行 Windows API 中可用的 native 函数。
我是 c++ 的新手,但例如在许多其他语言中,我可以将对 native 函数的引用存储在另一个名称下,然后我可以在我的自定义函数中调用它。在 C++ 中有类似的东西吗?
最佳答案
正如我在评论中所写,许多 Hook 库的父级可能是 Microsoft Detours
现在它不再免费了,有多种选择。这里有其中一些的比较(链接已删除。我不确定它是否安全。尝试使用谷歌搜索“Microsoft Detours is a library used in the particular interception”并选择来源或更简单地选择 Detours Alternatives。
嗯,看来目前唯一的免费选择是 http://easyhook.codeplex.com/和 http://www.codeproject.com/KB/system/mini_hook_engine.aspx
有个SO问题:Detours alternative for Registry interception如果你有兴趣。
关于c++ - Windows API函数是否可以被覆盖并在其后调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7770520/