DllMain not being called

£可爱£侵袭症+ 提交于 2019-12-25 01:05:10

问题


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:
        DetourTransactionBegin(); 
        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.


回答1:


You can't "run" a DLL. Perhaps you've built it as an executable project, for which DllMain has no special significance.




回答2:


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...



来源:https://stackoverflow.com/questions/4007161/dllmain-not-being-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!