MS Detours 2.1 - Неразрешенные внешние проблемы - PullRequest
0 голосов
/ 05 июня 2011

Я использую 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 (...)\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

1 Ответ

2 голосов
/ 05 июня 2011

Вы не ссылаетесь на winmm.lib.

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

Martyn

...