title: Returning a string from PInvoke?
body: <p>I am using PInvoke for interoperability between Native Code (C++) and Managed Code (C#). 
  I just write a simple function which gets a string from C++ code. My code looks like</p>
  
  <p><strong>C# Code:</strong></p>
  
  <pre><code>[DllImport("MyDll.dll")]
  private static extern string GetSomeText();
  public static string GetAllValidProjects() {
      string s = GetSomeText();
      return s;
  }
  </code></pre>
  
  <p><strong>C++ Code</strong></p>
  
  <pre><code>char* GetSomeText() {
      std::string stri= "Some Text Here";
      char * pchr = (char *)stri.c_str();
      return pchr;
  }
  </code></pre>
  
  <p>All works fine at C++ end, i.e the variable <code>pchr</code> contains "Some Text Here" but at C# the string <code>s</code> contains noting in it. I don't know what I am doing wrong. Any help would be appreciated</p>