If you want to write your own DllMain in a MFC Dll then you have to do some real cool stuff because MFC internally calls its DllMain. If you try to write your own DllMain, you get a linker error saying “DllMain already defined”. To resolve this issue you have to copy “DllModul.cpp” from MFC source directory to your project directory and include it in your own project.
The code for this follows:
// export DllMain for the DLL
BOOL WINAPI DllMain(HINSTANCE hInstance,
// Add your own initialisation Here
if (dwReason == DLL_PROCESS_ATTACH)
BOOL bResult = FALSE;
// wire up resources from core DLL