DLL Main on Windows Vs. __attribute__((constructor)) entry points on Linux

后端 未结 2 1223
旧巷少年郎
旧巷少年郎 2021-02-09 21:45

Consider code

EXE:

int main ()
{

    printf(\"Executable Main, loading library\\n\");
#ifdef HAVE_WINDOWS
    HMODULE lib = LoadLibrary         


        
2条回答
  •  野性不改
    2021-02-09 22:07

    Moo constructor isn't called before DllMain, it is called from DllMain. To be precise, its called from the real DllMain, the function Windows calls first. This real DllMain calls C++ constructors and then calls your C++ DllMain. The reason for this real DllMain is exactly to initialize constructors, something which wasn't needed in C before

    Linux (GCC/ELF) doesn't have this concept at all; it only has constructors. Your manual ctor and the C++ ctor for Moo are treated the same.

提交回复
热议问题