【发布时间】:2013-12-21 23:30:30
【问题描述】:
我查看了__attribute__((constructor)) equivalent in VC? 和CRT Initialization,它们都对gcc 特定的__attribute__((constructor)) 很有帮助。但是__attribute__((destructor)) 呢?有 VC 等价物吗?
【问题讨论】:
-
您链接的答案提供了等效的功能,使用 atexit 请参阅msdn.microsoft.com/en-us/library/tze57ck3.aspx
-
如果是库 - 在
DllMain中您可以安全地做的很少(阅读:调用 Kernel32.dll 的函数,只要它们不加载库 - 几乎没有别的)。不幸的是,其他方法(atexit等)也好不了多少,因为它们往往是通过DllMain实现的。在这种情况下,重写代码往往是一种简单的选择。
标签: c++ c visual-c++