Interface between exe and dll with another C / C ++ runtime library

Submission: The executable uses the dll. They have different c / C ++ runtimes. What are the limitations in the interface between them? In addition, they use the same compiler, the same version of Boost (but different pre-compiled boost files).

I understand that different runtimes can have different heaps. Thus, delete must match a new one from the same heap.

The most important thing is that we cannot go through STL interface objects, because when we create an exe STL object, they are associated with the same runtime and when creating a dll the same object (if we pass it by reference or copy through the interface) will be associated with a different runtime. And another runtime may have a different implementation of this object.

Consider the cases:

  • I think the following is safe. A Dll export function that has a parameter: a reference to the exported custom class that contains the private STL class as a member. Dll allocates memory for this object. Exe calls the release method of this object when it is deleted.

  • I think the following is NOT safe. The user class is created in exe and passed through the exe / dll interface. This class contains the private STL class as a member. exe and dll share the headers / implementation files of this user class. When this class is built in separate projects, various STL implementations will be used. For example, a different implementation of string :: size () (from different versions) will be applied to the same object in memory.

  • , . exe exe/dll. , ++. exe dll / . , . , new/delete, :: GetProcessHeap.

  • , : boost exe/dll, . .

  • , : boost exe/dll, , - boost lib ( ) boost lib ( ). .

( 3) exe dll dll exe. , new/delete, . , , ( 3).

1 , release ( boost:: shared_ptr )

? , .

+5
1

: - , EXE/DLL, , , , . . vtable, , DLL.

, ( , , - STL ..), .

:

  • Release(), , Release() DLL, , , EXE . , Release(), , vtable ( DLL).

  • , STL, string:: size(), .

  • . new/delete GetProcessHeap(), .
  • , . , . , .
  • STL, , , /delete (), (. ).

:

, , :

  • , (cdecl/stdcall).
  • , .
  • DLL, exe , .
  • / DLL , , . , , ++ .

, , Microsoft COM - . EXE/DLL :

  • . ++ . Virtual Release() .
  • . , . , , , :

    struct MyStruct
    {
        ...
    };
    C_ASSERT(sizeof(MyStruct) == ...);
    C_ASSERT(FIELD_OFFSET(MyStruct, MyMember) = ... );
    
  • C- , / .

  • , EXE
+4

All Articles