I'm using MS Detours 2.1 Library and VS 2010. I'm trying to detour PlaySoundW function.
I can't compile that code and I'm getting these errors:
Error 2 error LNK1120: 1 unresolved externals (...)\detoursLearning.dll detoursLearning
Error 1 error LNK2001: unresolved external symbol __imp__PlaySoundW@12 (...)\detoursLearning\main.obj detoursLearning
My code:
#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());
Det开发者_JAVA技巧ourDetach(&(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;
}
One more thing, can you explain me this:
&(PVOID&)OrgPlaySoundW
You're not linking to winmm.lib.
http://msdn.microsoft.com/en-us/library/dd743680%28VS.85%29.aspx
Martyn
精彩评论