Implications of using std::vector in a dll exported function <p>I have two dll-exported classes A and B. A's declaration contains a function which uses a std::vector in its signature like:</p> <pre><code>class EXPORT A{ // ... std::vector&lt;B&gt; myFunction(std::vector&lt;B&gt; const &amp;input); }; </code></pre> <p>(EXPORT is the usual macro to put in place _<em>declspec(dllexport)/</em>_declspec(dllimport) accordingly.)</p> <p>Reading about the issues related to using STL classes in a DLL interface, I gather in summary:</p> <ul> <li><p>Using std::vector in a DLL interface would require all the clients of that DLL to be compiled with the same <em>version</em> of the same compiler because STL containers are not binary compatible. Even worse, depending on the use of that DLL by clients conjointly with other DLLs, the ''instable'' DLL API can break these client applications when system updates are installed (e.g. Microsoft KB packages) (really?).</p></li> <li><p>Despite the above, if required, std::vector can be used in a DLL API by exporting <code>std::vector&lt;B&gt;</code> like:</p> <pre><code>template class EXPORT std::allocator&lt;B&gt;; template class EXPORT std::vector&lt;B&gt;; </code></pre> <p>though, this is usually mentioned in the context when one wants to use std::vector as a <em>member</em> of A (http://support.microsoft.com/kb/168958).</p></li> <li><p>The following Microsoft Support Article discusses how to access std::vector objects created in a DLL through a pointer or reference from within the executable (http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q172396). The above solution to use <code>template class EXPORT ...</code> seems to be applicable too. However, the drawback summarized under the first bullet point seems to remain.</p></li> <li><p>To completely get rid of the problem, one would need to wrap std::vector and change the signature of <code>myFunction</code>, PIMPL etc..</p></li> </ul> <p>My questions are:</p> <ul> <li><p>Is the above summary correct, or do I miss here something essential?</p></li> <li><p>Why does compilation of my class 'A' not generate warning C4251 (class 'std::vector&lt;_Ty>' needs to have dll-interface to be used by clients of...)? I have no compiler warnings turned off and I don't get any warning on using std::vector in <code>myFunction</code> in exported class A (with VS2005).</p></li> <li><p>What needs to be done to correctly export <code>myFunction</code> in A? Is it viable to just export <code>std::vector&lt;B&gt;</code> and B's allocator? </p></li> <li><p>What are the implications of returning std::vector by-value? Assuming a client executable which has been compiled with a different compiler(-version). Does trouble persist when returning by-value where the vector is copied? I guess yes. Similarly for passing std::vector as a constant reference: could access to <code>std::vector&lt;B&gt;</code> (which might was constructed by an executable compiled with a different compiler(-version)) lead to trouble within <code>myFunction</code>? I guess yes again..</p></li> <li><p>Is the last bullet point listed above really the only clean solution?</p></li> </ul> <p>Many thanks in advance for your feedback.</p>