There is a dll for implementation in an already running process that does something and then unloads itself. All this happens at the very stage of implementation (with DLL_PROCESS_ATTACH ).
library Test; uses Winapi.Windows; procedure DllMain(Reason: integer); begin if Reason = DLL_PROCESS_ATTACH then begin // что-то делаем FreeLibraryAndExitThread(HInstance, 0); // выгружаемся end; end; begin DllProc := @DllMain; DllMain(DLL_PROCESS_ATTACH); end. Probably, during the unloading, some kind of blocking occurs, as a result of which sometimes the process hangs tight. Sometimes this does not happen, but it is still impossible to close the process properly after that.
Example:
1) Run, say, a calculator
2) Introduce this dll into it (Process Hacker, for example)
Then I was able to catch three types of process behavior:
a) it hangs tight
b) ceases to respond to the closure of the cross
c) When you close the main window, it remains to hang in the list of processes.
Despite the fact that the dll itself successfully unloads and even terminates its flow - it spoils something in the process.
If you remove the unloading from the code, and do it separately, everything works as it should.
Question: how to get rid of this behavior while maintaining the functionality of self-unloading dll?
UPD1: If you replace FreeLibraryAndExitThread with FreeLibrary everything becomes even worse: the process immediately drops with a BEX64 error.
FreeLibraryAndExitThread? - Igor