__attribute __ ((destructor)) equivalent in VC?

I reviewed the __ attribute __ ((constructor)) equivalent in VC? and CRT Initialization , which were useful with respect to gcc-specific __attribute__((constructor)). But what about __attribute__((destructor))? Is there a VC equivalent?

+4
source share
1 answer

If you are creating a dynamic link library, you can make a 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;
}
+2
source

All Articles