title: Reading string from C# managed code to C++ wchar* [] getting AccessViolation
body: <p>The question is easy, Want to read a string from managed C# code to my unmanaged C++ code in <code>WCHAR* []</code>.
   The C function is:</p>
  
  <pre><code>extern "C"  __declspec(dllexport) int __cdecl myfunc(int argc, WCHAR* argv[])
  </code></pre>
  
  <p>and in C# I imported the DLL:</p>
  
  <pre><code>[DllImport("mydll.dll", CharSet = CharSet.Auto, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
  public static extern int myfunc(int argc, [MarshalAs(UnmanagedType.LPTStr)]  StringBuilder str);
  </code></pre>
  
  <p>I run, but when I tried to read the string in my C++ code I get <code>AccessViolationException : Attempted to read or write protected memory. This is often an indication that other memory is corrupt.</code></p>
  
  <p>What is the correct way to do this and vice versa (i.e. passing a string from C++ unmanaged to C# managed code)?</p>
  
  <p>Help Appreciated.
  Thanks</p>