Note that there are some explanatory texts on larger screens.

plurals
  1. POMixing versions of the MSVCRT
    primarykey
    data
    text
    <p>So, I have a C++ library with a statically linked copy of the MSVCRT. I want for anyone to be able to use my library with any version of the MSVC Runtime. What is the best way to accomplish this goal? </p> <p>I'm already being quite careful with how things are done. </p> <ol> <li>Memory never passes the DLL barrier to be freed</li> <li>Runtime C++ objects aren't passed across barriers (ie, vectors, maps, etc.. unless they were created on that side of the barrier)</li> <li>No file handles or resource handles are passed between barriers</li> </ol> <p>Yet, I still have some simple code that causes heap corruption. </p> <p>I have an object like so in my library:</p> <pre><code>class Foos { public: //There is an Add method, but it's not used, so not relevant here DLL_API Foos(); DLL_API ~Foos(); private: std::map&lt;std::wstring, Foo*&gt; map; }; Foos::~Foos() { // start at the begining and go to the end deleting the data object for(std::map&lt;std::wstring, Foo*&gt;::iterator it = map.begin(); it != map.end(); it++) { delete it-&gt;second; } map.clear(); } </code></pre> <p>And then I use it from my application like so:</p> <pre><code>void bar() { Foos list; } </code></pre> <p>After I call this function from anywhere, I get a debug warning about stack corruption. And If I actually let it run out, it actually does corrupt the stack and segfault. </p> <p>My calling application is compiled with Visual Studio 2012 platform tools. The library is compiled using Visual Studio 2010 platform tools. </p> <p>Is this just something I should absolutely not be doing, or am I actually violating the rules for using multiple runtimes? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload