We are using 4 DLLs built with VS2005 in an application built with VS2010. When calling one of the methods of these libraries, the application crashes. (it may also happen in other methods too, but I haven't tried.). The method we are calling changes a long into a custom string class. Let's call it XString. This class extends std::string. The application seems to crash when XString's destructor (and std::string destructor) is called. I "guess" that the problem comes from the fact that the XString object is instantiated in the 2005 DLL using the 2005 CRT redistributable package, passed to our application, and destroyed in our application using the 2010 CRT. Any ideas on this ? We are about to give up and rebuild all DLLs with VS2010 (we don't want to as it will need more time and more money...).
If your DLL interface includes types that depend on the runtime library, such as std::string or std::vector, then any code that uses the DLL must use the same version of the runtime library as the DLL, in order to ensure that the type structures are the same, and that any dynamic memory is returned to the correct heap.
If you wish your DLL to work with code that uses a different version of the runtime library then you must restrict the types used in the DLL interface to things that are not dependent on the runtime library. e.g. pointers, integers, and simple structs that you have written. You could use BSTRs for passing strings, if plain char* strings are not suitable. You could also use an opaque type passed around by pointer, and have the DLL do all the accesses.
If you cannot change your DLL interface, then you will need to ensure that everything uses the same version of the compiler+runtime.
You're right Anthony. Further research showed us that the 2005 std::string byte length was different from the 2010 version. So an std::string instantiated in a 2005 DLL, and released in a 2010 application, will crash. Thanks for the help. We're going to rebuild the DLL.