I make a DLL injection to a process after ntdll.dll loading. Then, in DllMain (DLL_PROCESS_ATTACH event case) I call LdrRegisterDllNotification and wait when the specific DLL will be loaded (e.g. statistic.dll) which functions I want to hook. If statistic.dll wasn't loaded I need to unload injected DLL from the process.
The main question is: How to unload injected DLL correctly?
I wanted to implement it via different thread which will check (after some time) statistic.dll library in the process (or specific flag which I can set after the statistic.dll loading) and unload injected DLL if it wasn't loaded. But as I know, we can't create a thread in DllMain.
FreeLibraryAndExitThread
– RbMm