title: Calling a native c++ dll with std::string argument from c++/cli
body: <p>I have a native c++ dll which I am trying to call from a c++/cli project.  Here's the dll's function</p>
  
  <pre><code>extern "C"
  {
     int DLL_EXPORT Add(std::string s1, std::string s2, std::string s3)
     {
       [do stuff]
     }
  }
  </code></pre>
  
  <p>Here's the reference in c++/cli:</p>
  
  <pre><code>using namespace System::Runtime::InteropServices;
  [DllImport("my_dll.dll")]
  extern "C" int Add(std::string, std::string, std::string);
  </code></pre>
  
  <p>When I call the function, I marshal the String^ objects to std::string:</p>
  
  <pre><code>Add(msclr::interop::marshal_as&lt;std::string&gt;(stringA),
              msclr::interop::marshal_as&lt;std::string&gt;(stringB),
              msclr::interop::marshal_as&lt;std::string&gt;(stringC));
  </code></pre>
  
  <p>I get an access violation exception when the call to the DLL is made.  </p>