【问题标题】:MS Detours 2.1 - Unresolved externalsMS Detours 2.1 - 未解决的外部问题
【发布时间】:2011-06-05 17:54:15
【问题描述】:

我正在使用 MS Detours 2.1 库和 VS 2010。我正在尝试绕过 PlaySoundW 函数。

我无法编译该代码并且出现以下错误:

Error 2 error LNK1120: 1 unresolved externals (...)\detoursLearning.dll detoursLearning

Error 1 error LNK2001: unresolved external symbol __imp__PlaySoundW@12 (...)\detoursLearning\main.obj detoursLearning

我的代码:

#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;
    }

    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;
}

还有一件事,你能解释一下吗:

&(PVOID&)OrgPlaySoundW

【问题讨论】:

    标签: c++ winapi detours


    【解决方案1】:

    【讨论】:

    • 那行得通,谢谢。还有一件事:你能解释一下吗:&(PVOID&)OrgPlaySoundW
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-15
    • 2011-12-19
    • 2017-09-25
    • 1970-01-01
    • 1970-01-01
    • 2014-05-19
    • 1970-01-01
    相关资源
    最近更新 更多