Search code examples
c++dlldll-injection

Injected DLL does nothing


I attempted to inject a C++ DLL in another WIN32 console programme. The injector (winjet) shows that it is successfully injected but the DLL itself does nothing. As compiler I use Visual Studio 2013 and I just found out if I use precompiled header and this preset .cpp instead of a empty project without precompiled header, it works.

Dll.cpp :

BOOL APIENTRY Dllmain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved){
     switch (reason) {
     case DLL_PROCESS_ATTACH:
          MessageBoxA(NULL, "Attached!", "InjectedDLL", MB_OK);
     }
     return TRUE;
}

This code works with preset settings and precompiled header. But why it doesn't without that?


Solution

  • The entry point to a Windows DLL is called DllMain, not Dllmain.

    You do not get a compile error for this (like when mis-spelling main), because it is optional.