As Dirk has already stated, the DLL entry point is named DllMain()
, not DLLMain()
. The signature for DllMain()
is:
BOOL WINAPI DllMain(
HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpvReserved
);
From Best Practices for Creating DLLs , you should never perform the following tasks from within DllMain():
...Call functions in User32.dll or Gdi32.dll. Some functions load another DLL, which may not be initialized...
MessageBox()
is implemented in User32.dll
so this may be a possible cause of DllMain()
appearing to not be invoked.
It is unwise to perform any time consuming tasks with DllMain()
as it will prevent the application loading any other DLLs that is requires, as the loader lock is held when inside DllMain()
. Instead, spawn a thread to perform any time consuming task. The linked document advises against using CreateThread()
but only if synchronization is involved.