我今天读微软的DLL的官方文档的时候,看到了这样一句话:
"When handling DLL_PROCESS_DETACH, a DLL should free resources such as heap memory only if the DLL is being unloaded dynamically (the lpvReserved parameter is NULL). "
特别强调:only if!!!
该页面同时还有这样一句话:
"If your DLL is linked with the C run-time library (CRT), the entry point provided by the CRT calls the constructors and destructors for global and static C++ objects. Therefore, these restrictions for DllMain also apply to constructors and destructors and any code that is called from them."
举个例子解释一下:假如你有一个unique_ptr是一个global variable.那么,你需要在Dllmain里面视情况把这个unique_ptr给release掉,以防止它的析构函数被调用。不然在某些情况下会crash.
--
修改:snnn FROM 112.85.242.*
FROM 115.231.225.*