作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我不会在 Minesweeper 中绕过 PlaySoundW 功能。游戏一调用 PlaySoundW 函数就崩溃了。如果我在我的代码中取消对 Beep 的注释,游戏会发出哔哔声然后崩溃。
现在代码正在从钩子(Hook)函数调用原始函数,所以它不应该做任何事情。但无论如何它都会崩溃。
你能告诉我哪里出了问题吗?
在 Olly 中调试应用程序后,我发现当绕行处于事件状态时,并非所有垃圾都从堆栈中弹出。如何解决?
这是我的代码:
#include <Windows.h>
#include <tchar.h>
#include <detours.h>
namespace Hooks
{
BOOL(__stdcall *OrgPlaySoundW)(LPCTSTR pszSound, HMODULE hmod, DWORD fdwSound) = &PlaySoundW;
BOOL HookPlaySoundW(LPCTSTR pszSound, HMODULE hmod, DWORD fdwSound)
{
//Beep(1000, 250);
//return TRUE;
return OrgPlaySoundW(pszSound, hmod, fdwSound);
}
void DetourPlaySoundW(BOOL disable)
{
if(!disable)
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)OrgPlaySoundW, &HookPlaySoundW);
DetourTransactionCommit();
} else
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)OrgPlaySoundW, &HookPlaySoundW);
DetourTransactionCommit();
}
}
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch(fdwReason)
{
case DLL_PROCESS_ATTACH:
Hooks::DetourPlaySoundW(FALSE);
break;
case DLL_PROCESS_DETACH:
Hooks::DetourPlaySoundW(TRUE);
break;
}
return TRUE;
}
最佳答案
尝试将HookPlaySoundW
的调用约定设置为__stdcall
(因为PlaySoundW
的CC也是__stdcall
(来自 Windows.h
): WINMMAPI BOOL WINAPI PlaySoundW( __in_opt LPCWSTR pszSound, __in_opt HMODULE hmod, __in DWORD fdwSound);
).
我在不经意的一瞥之前和之后都绕过弯路,除了我上面提到的以外,一切看起来都是正确的。如果这不能解决您的问题,我很乐意做一些进一步的调查。
Visual C++ 的默认设置是 __cdecl
,其中调用*er* 清理堆栈,但在 __stdcall
中调用* ee* 清理堆栈。这可能是(即可能是)所有“垃圾从堆栈中弹出”的原因。
关于c++ - MS Detours 2.1 - 从堆栈中弹出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6245639/
我是一名优秀的程序员,十分优秀!