Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can Dllmain use FreeLibrary?

Tags:

c++

c

dll

winapi

I want to create a dll that unload it self in case of some condifiton, meaning

BOOL APIENTRY DllMain( HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
{
if (ul_reason_for_call==DLL_PROCESS_ATTACH)
if (!CheckSomething()) //check if a file doesnt exists for example
FreeLibrary(hModule);

}

I tried it, but i couldnt get it to work. if there is any walk around alternative solution. please tell me, I dont want the process which attached the dll to unload it, I want it to unload it self

like image 881
CnativeFreak Avatar asked Dec 27 '11 16:12

CnativeFreak


1 Answers

You can't unload the DLL, it hasn't been loaded yet. That's what the BOOL return is for. If you don't want to load the DLL, then return FALSE.

like image 88
Puppy Avatar answered Oct 12 '22 12:10

Puppy