Why do global native objects cause problems in C++/CLI dlls?

徘徊边缘 提交于 2019-12-23 18:30:28

问题


I have read somewhere that it has something to do with non-simple global native objects that have constructors/destructors. Can someone explain what it is exactly that may cause trouble?


回答1:


An Example: Once I tried to link a native C++ lib into a C++/CLI application. That lib contained a const static std::string. The application did always crash. Reason:

When the application starts, it initializes the const static objects. To make sure that the static objects get deleted properly on application exit, the compiler generates a call to the standard library function atexit. This call causes a crash in the native C runtime, which is not yet properly initialized at this point in time.

There is no problem with non-const static fields, which are initialized later.

I consider this as a bug - maybe it is fixed in the meantime (I had the problem with Visual Studio 2005). Unfortunately, I cannot provide an appropriate link, but I hope this helps for your further research.



来源:https://stackoverflow.com/questions/6424761/why-do-global-native-objects-cause-problems-in-c-cli-dlls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!