DllMain not being called
I have a DllMain defined as so:
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
int i=0, DoHijack=0;
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
hMod = hModule;
hProcessCenter = ::FindWindow(NULL, _T("Form1"));
ExtractPaths(hModule, ExePath, &kNTIExeName, kNTIDllPath, &kNTIDllName);
//Only hook target processses
for(i=0; i < NB_TARGETS; i++)
{
if(strstr(kNTIExeName, Targets[i]))
DoHijack=1;
}
if(DoHijack)
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)Real_DrawText, Mine_DrawText); // <- magic
DetourAttach(&(PVOID&)Real_ExtTextOut, Mine_ExtTextOut);
DetourTransactionCommit();
break;
}
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
D开发者_如何学编程etourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)Real_DrawText, Mine_DrawText);
DetourDetach(&(PVOID&)Real_ExtTextOut, Mine_ExtTextOut); // <- magic
DetourTransactionCommit();
break;
}
return TRUE;
}
This is a project that I have bought home from work and after I compile and run it the dllmain is never being called, hence my problem which is the process_attach switch is never hit. What could be causing this to occur? Something in the compiler, one of the linking options?
The dll functions perfectly at work...
Thanks.
You can't "run" a DLL. Perhaps you've built it as an executable project, for which DllMain
has no special significance.
Looked at it with fresh eyes this morning and realized that dllmain was being called but in fact I had made a mistake in one of the check NBTargets values which is why my code was not firing...
back to it...
精彩评论