So, I have a C ++ library with a statically linked copy of MSVCRT. I want someone to be able to use my library with any version of MSVC Runtime. What is the best way to achieve this?
I am already very careful how things are.
- Memory never misses the DLL barrier that will be freed.
- C ++ Runtime objects are not passed through barriers (i.e. vectors, maps, etc., unless they are created on that side of the barrier).
- No files or resource descriptors are passed between barriers.
However, I still have some simple code that causes heap corruption.
There is an object in my library:
class Foos { public: //There is an Add method, but it not used, so not relevant here DLL_API Foos(); DLL_API ~Foos(); private: std::map<std::wstring, Foo*> map; }; Foos::~Foos() { // start at the begining and go to the end deleting the data object for(std::map<std::wstring, Foo*>::iterator it = map.begin(); it != map.end(); it++) { delete it->second; } map.clear(); }
And then I use it from my application like this:
void bar() { Foos list; }
After I call this function from anywhere, I get a debug warning about stack corruption. And if I actually let this run out, it will actually damage the stack and segfault.
My calling application was compiled using the tools of the Visual Studio 2012 platform. The library was compiled using the tools of the Visual Studio 2010 platform.
Is it just something that I should absolutely not do, or am I really breaking the rules for using several modes of operation?
c ++ visual-c ++ msvcrt
Earlz
source share