DllMain没有被调用

时间:2010-10-24 04:15:10

标签: c++ visual-studio-2008 dll

我有一个DllMain定义如下:

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;
 }

这是我从工作中买回家的项目,在我编译并运行之后,dllmain从未被调用,因此我的问题是process_attach开关永远不会被击中。是什么导致这种情况发生?编译器中有什么东西,链接选项之一?

dll在工作中完美运行......

感谢。

2 个答案:

答案 0 :(得分:0)

您无法“运行”DLL。也许您已将其构建为可执行项目,DllMain没有特殊意义。

答案 1 :(得分:0)

今天早上用新鲜的眼睛看着它,并意识到dllmain被调用了,但事实上我在其中一个检查NBTargets值中犯了一个错误,这就是为什么我的代码没有触发......

回到它......

相关问题