MS Detours 2.1-未解决的外部问题

MS Detours 2.1 - Unresolved externals

本文关键字:外部 问题 未解决 Detours MS      更新时间:2023-10-16

我使用的是MS Detours 2.1 Library和VS 2010。我试图绕过PlaySoundW功能。

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

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

Error 1 error LNK2001: unresolved external symbol __imp__PlaySoundW@12 (...)detoursLearningmain.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

您没有链接到winmm.lib.

http://msdn.microsoft.com/en-us/library/dd743680%28VS.85%29.aspx

Martyn