-
Link the CRT statically - in Config Properties / C/C++ / Code Generation / Runtime Library select the non-DLL multi-threaded option, for example
/MTin the release build. -
Add
/Zc:threadSafeInit-(n.b. the trailing-is part of the switch) to the compiler options under Config Properties / C/C++ / Command Line / Additional Options.
Workaround #2 comes from the open case at https://connect.microsoft.com/VisualStudio/feedback/details/1907257.
Windows Server 2003 and Windows XP have problems with dynamically loading a DLL (via LoadLibrary) that uses thread-local storage, which is what thread-safe statics use internally to provide efficient execution when the static local has already been initialized. As these systems are out of support, it is extremely unlikely for a patch to be created for those systems to add this support as is present in Vista and newer OSes, and we are reluctant to penalize the performance on in-support OSes to provide this functionality to the old out-of-support ones.
To work around the issue you can use /Zc:threadSafeInit- to disable the thread-safe initialization code and this will avoid the thread-local variable. Of course by doing so the initialization code reverts back to the VS2013 mode and is not thread-safe, so this option is only viable if you don't rely on the thread-safety of local statics.

本文详细介绍了如何通过修改配置属性和编译选项,解决使用VS2015创建的ATL ActiveX控件在Windows XP系统中注册时出现的内存分配失败问题。
607

被折叠的 条评论
为什么被折叠?



