I am writing a DLL that needs to call a separate DLL dynamically several times. I would like to save the download and then just unload it when my DLL is unloaded. But, according to Microsoft, a bad idea .
The entry point function should perform simple initialization tasks and should not call any other loading or terminating DLL. For example, in an entry point function, you should not directly or indirectly call the LoadLibrary function or the LoadLibraryEx function. Additionally, you should not call FreeLibrary when the process is terminating.
Here is the abusive code. Can someone explain why I should not call LoadLibrary and FreeLibrary from my DLL entry point?
BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_DETACH : if (hLogLib != NULL) FreeLibrary(hLogLib); break; } return TRUE; }
source share