title: Exporting STL std::vector functionality trough DLL
body: <p>I have written a piece of code which uses C++ STL (std::vector) internally to store some info and then provide it trough C like functions that will be exported later in Windows DLL. I am wondering if this way will be correct and stable. I will be appreciate if someone with some experience in this field could confirm me that it is ok or point me to the problems. 
  This is just a draft example and all error handling functionality will be added later.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  typedef struct _c_vector_wrapper_config
  {
      size_t currentPosition = -1;
      // for std::string
      std::vector&lt;std::string&gt; *vPointer = nullptr;
      std::vector&lt;std::string&gt;::iterator vIterator;
  
      // for C null terminated string 
      // we support 2 type of vectors to have ability to work with C like strings from other than C++
      // languages 
      // Also we allocate memory for this string using C runtime malloc and at the end we can easily free 
      // this memory to avoid memory leaks.
  
      // Why we use also std::vector&lt;std::string&gt; ? Because STL string operation is more simple and safe
      // and we need C like strings only to export them from DLL
      std::vector&lt;char*&gt; *vPointerChar = nullptr;
      std::vector&lt;char*&gt;::iterator vIteratorChar;
  
  } c_vector_wrapper_config;
  
  
  
  c_vector_wrapper_config *vector_wrapper_config = new c_vector_wrapper_config();
  
  // c_vector_wrapper_config *vector_wrapper_config = new c_vector_wrapper_config();
  
  
  
  void create_vector();
  void delete_vector();
  void add_value(std::string value);
  char* get_value();
  
  
  int main(void)
  {
  
      create_vector();
  
      add_value("test1");
      add_value("test2");
      add_value("test3");
  
      std::cout &lt;&lt; get_value() &lt;&lt; std::endl;
      std::cout &lt;&lt; get_value() &lt;&lt; std::endl;
  
      delete_vector();
  
      return 0;
  }
  
  void create_vector()
  {
      if (vector_wrapper_config-&gt;vPointer == nullptr)
      {
          vector_wrapper_config-&gt;vPointer = new std::vector&lt;std::string&gt;();
          vector_wrapper_config-&gt;vPointerChar = new std::vector&lt;char*&gt;();
      }
  
  }
  
  void add_value(std::string value)
  {
      vector_wrapper_config-&gt;vPointer-&gt;push_back(value);
  
      std::size_t str_length = value.size();
      char *c_string = static_cast&lt;char*&gt;(malloc(str_length +1));
      value.copy(c_string, str_length, 0);
      c_string[str_length] = '\0';
  
      vector_wrapper_config-&gt;vPointerChar-&gt;push_back(c_string);
  }
  
  char* get_value()
  {
      vector_wrapper_config-&gt;currentPosition++;
      char* current_value =  (*vector_wrapper_config-&gt;vPointerChar)[vector_wrapper_config-&gt;currentPosition];
  
      return current_value;
  }
  
  void delete_vector()
  {
      delete vector_wrapper_config-&gt;vPointer;
  
      // free memory allocated previously for C like strings
      for (std::vector&lt;char*&gt;::iterator it = vector_wrapper_config-&gt;vPointerChar-&gt;begin(); it != vector_wrapper_config-&gt;vPointerChar-&gt;end(); ++it)
      {
          free(*it);
      }
  }
  </code></pre>