views:

56

answers:

3

Hi,

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.

A: 

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

Marcelo Cantos
Sorry, just poor choice of words, its compiled as a dll. As I said, it all works fine when I compile it on my work computer but not at home, I think one of the compile setting is different and I am wondering if anybody knows which one...
flavour404
A: 

What do you do inside DllMain? Can you post some code please?

nakiya
A: 

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

flavour404