Wednesday, January 27, 2010 7:18 AM
I have a dll build with VC++ 2003 using code having some STL objects (including std::string).
1. Does my STL objects causes any problems if it is used in a dll comipled with different/later version of VC++ CRT?
2. Is it possible to make my dll compatible across different versions of CRTs?
Wednesday, January 27, 2010 7:40 AM1. Yes, if you pass STL objects across module boundaries you will most definitely have immediate memory corruption.2. No.
- Marked As Answer by N. V. Hari Krishna Wednesday, January 27, 2010 12:53 PM
Wednesday, January 27, 2010 9:22 AMDoes compiling my dll with /MD flag helps to prevent memory corruption across boundaries?
Wednesday, January 27, 2010 1:28 PMN. V. Hari Krishna wrote:
> Does compiling my dll with /MD flag helps to prevent memory corruption across boundaries?No. It still won't work if you try to combine modules built with different versions of the compiler (or even the same version, but with different settings). It is a bad idea to use STL classes, or indeed any C++ classes, in the DLL's public interface (with the exception of interfaces - that is, classes with no data members and all functions being pure virtual).
- Marked As Answer by N. V. Hari Krishna Thursday, January 28, 2010 6:08 AM
Wednesday, July 04, 2012 4:47 PMThis is true if DLLs are having different heap if heap is same across dll and process then there should not be issue.
Wednesday, July 04, 2012 7:49 PM
Even then, there can be differences in STL version and differences in compiler flags, causing all sorts of issues.
It is a bad idea to do this.
Thursday, July 05, 2012 2:01 PM
In every major version (VS 2005, 2008, 2010, 2012, etc.) we change the representations of STL objects like string and vector, making them binary-incompatible. We now have linker checks that prevent mixing object files/static libraries compiled with different major versions (2010+), but it's up to you to ensure consistency for DLLs.
The issue is not "stuff might misbehave, maybe". It is "stuff will crash, horribly and incomprehensibly".