我查看了__attribute__((constructor)) equivalent in VC?和CRT Initialization,这对于特定于gcc的__attribute__((constructor))
都有帮助。但是__attribute__((destructor))
呢?是否有VC等价物?
答案 0 :(得分:2)
如果您正在创建动态链接库,则可以让DllMain entry point处理此问题:
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
if (fdwReason == DLL_PROCESS_ATTACH)
{
// equivalent of __attribute__((constructor))...
// return TRUE if succeeded, FALSE if you failed to initialize properly
return TRUE; // I'm assuming you succeeded.
}
else if (fdwReason == DLL_PROCESS_DETACH)
{
// equivalent of __attribute__((destructor))...
}
// Return value is ignored when fdwReason isn't DLL_PROCESS_ATTACH, so we'll
// just return TRUE.
return TRUE;
}