title: Problem with Marshalling char* in c#
body: <p>I have a problem calling this function from a c++ DLL in c#</p>
  
  <pre><code>INT32 WINAPI PM_COM_GetText(INT32 TextId, char* pBuf, INT32 BufSize);
  </code></pre>
  
  <p>It writes a Text in a buffer for a given text id.
  I try to call it with the following c# code, but I constantly get an access violation and don't undrestand why:</p>
  
  <pre><code>public string GetText(Int32 TextId)
  {
    Int32 BufSize = 256;
    StringBuilder Str = new StringBuilder(BufSize);
    PM_COM_GetText(TextId, Str, BufSize);
    return Str.ToString();
  }
  
  [DllImport("ComDll.dll", CharSet = CharSet.Ansi)]
  private static extern Int32 PM_COM_GetText(Int32 TextId, StringBuilder Str, Int32 BufSize);
  </code></pre>
  
  <p>I don't see what's wrong, it looks to me like many other code snippets I found in the web.</p>
  
  <p>Any ideas?
  Thanks in advance!</p>