c++ - Why does calling WSASocket from DllMain lead to a hang? -
i need destroy objects when dll unloaded. object contains thread calls wsasocket function (for reconnecting connection). so, call destructor dllmain in response dll_process_detach
, causes application hang. specifically, call wsasocket locks up.
i know functions cannot called dllmain, functions call loadlibrary , freelibrary. why wsasocket function have same problem?
it's because shouldn't use dllmain cause. many system procs cause deadlock being called dllmain. declare additional export proc deinitialization of dll , call right before freelibrary.
also, recommend read "best dll practices" msft. there lot of reasons stay away dllmain.