Using C++ DLLs with different compiler versions

前端 未结 5 431
情书的邮戳
情书的邮戳 2020-12-10 07:57

This question is related to \"How to make consistent dll binaries across VS versions ?\"

  • We have applications and DLLs built with VC6 and a new application bui
5条回答
  •  忘掉有多难
    2020-12-10 08:22

    Interface member names will not be decorated -- they're just offsets in a vtable. You can define an interface (using a C struct, rather than a COM "interface") in a header file, thusly:

    struct IFoo {
        int Init() = 0;
    };
    

    Then, you can export a function from the DLL, with no mangling:

    class CFoo : public IFoo { /* ... */ };
    extern "C" IFoo * __stdcall GetFoo() { return new CFoo(); }
    

    This will work fine, provided that you're using a compiler that generates compatible vtables. Microsoft C++ has generated the same format vtable since (at least, I think) MSVC6.1 for DOS, where the vtable is a simple list of pointers to functions (with thunking in the multiple-inheritance case). GNU C++ (if I recall correctly) generates vtables with function pointers and relative offsets. These are not compatible with each other.

提交回复
热议问题