c – __attribute __((析构函数))在VC中等效吗?

我查看了
__attribute__((constructor)) equivalent in VC?
CRT Initialization,它们对gcc特定的__attribute __((构造函数)都有帮助.但是__attribute __((析构函数))呢?有VC等价吗? 最佳答案 如果你正在创建一个动态链接库,你可以让你的
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;
}
点赞