I am creating my own DLL which make use of Detours 2.1 of MS Research.
But I got these errors:
detours.lib(detoured.obj) : error LNK2005: _DllMain@12 already defined in SampleDLL.obj
Debug/SampleDLL.dll : fatal error LNK1169: one or more multiply defined symbols found
I think its because, detoured.cpp contains
BOOL WINAPI DllMain(...)
when I compiled it using
nmake
How should I fix this problem. I saw in some other forums, that it should be removed. But is it okay have a DLL without it?
Here's the code regarding the DLL I want to make (The code isn't mine, just copied it on a forum. It actually tries to hook to DrawTextW):
// SampleDLL.cpp code
int (WINAPI * Real_DrawText)(HDC a0, LPCWSTR a1, int a2, LPRECT a3, UINT a4) = DrawTextW;
// Our custom version of DrawText
int WINAPI Mine_DrawText(HDC hdc, LPCWSTR text, int nCount, LPRECT lpRect, UINT uOptions)
{
TRACE("=== %s", text, " ===");
int rv = Real_DrawText(hdc, text, nCount, lpRect, uOptions);
return rv;
}
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)Real_DrawText, Mine_DrawText); // <- magic
DetourTransactionCommit();
break;
case DLL_PROCESS_DETACH:
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)Real_DrawText, Mine_DrawText);
DetourTransactionCommit();
break;
}
return TRUE;
}