What happens to global variables declared in a DLL?

后端 未结 6 729
眼角桃花
眼角桃花 2020-11-27 14:47

Let\'s say I write a DLL in C++, and declare a global object of a class with a non-trivial destructor. Will the destructor be called when the DLL is unloaded?

6条回答
  •  醉梦人生
    2020-11-27 15:12

    If you want to see the actual code that gets executed when linking a .dll, take a look at %ProgramFiles%\Visual Studio 8\vc\crt\src\dllcrt0.c.

    From inspection, destructors will be called via _cexit() when the internal reference count maintained by the dll CRT hits zero.

提交回复
热议问题