title: How to expose STL list over DLL boundary?
body: <p>I have a DLL which needs to access data stored in STL containers in the host application.  Because C++ has no standard ABI, and I want to support different compilers, the interface between the application and DLL basically has to remain plain-old-data.</p>
  
  <p>For vectors this is relatively straightforward.  You can simply return the memory block of the vector, because it is guaranteed to be contigious:</p>
  
  <pre><code>// To return vector&lt;int&gt; data
  virtual void GetVectorData(const int*&amp; ptr, size_t&amp; count) const
  {
      if (!vec.empty())
          ptr = &amp;(vec.front());
  
      count = vec.size();
  }
  </code></pre>
  
  <p>Now the DLL can have safe read-only access to the vector's data via that interface.  The DLL can also wrap this to copy the contents in to a vector for itself as well.</p>
  
  <p>What about STL lists (and deques) though?  Is there another straightforward way to allow access via a DLL boundary?  Or will I have to resort to some kind of GetFirst()/GetNext() interface?  I might need to do this for a lot of lists, so it'd be nice to have a solution as simple as vector's.</p>