title: Passing strings from C# to C++ DLL and back -- minimal example
body: <p>I am trying to make the absolute simplest minimal example of how to pass strings to and from a C++ DLL in C#.</p>
  
  <p>My C++ looks like this:</p>
  
  <pre><code>using std::string;
  
  extern "C" {
      string concat(string a, string b){
          return a + b;
      }
  }
  </code></pre>
  
  <p>With a header like</p>
  
  <pre><code>using std::string;
  
  extern "C" {
      // Returns a + b
      __declspec(dllexport) string concat(string a, string b);
  }
  </code></pre>
  
  <p>My C# is</p>
  
  <pre><code>[DllImport("*****.dll", CallingConvention = CallingConvention.Cdecl)]
      static extern string concat(string a, string b);
  }
  </code></pre>
  
  <p>And I am calling it with:
       Console.WriteLine(concat("a", "b"));</p>
  
  <p>But this gives a System.AccessViolationException. This seems like it out to be the most trivial thing to deal with, but I am completely stuck on it. When I tried to do a similar experiment with a function "Add" that took two doubles and returned a double I had no problems.</p>