title: PInvoke for C function that returns char *
body: <p>I'm trying to write some C# code that calls a method from an unmanaged DLL.  The prototype for the function in the dll is:</p>
  
  <pre><code>extern "C" __declspec(dllexport) char *foo(void);
  </code></pre>
  
  <p>In C#, I first used:</p>
  
  <pre><code>[DllImport(_dllLocation)]
  public static extern string foo();
  </code></pre>
  
  <p>It seems to work on the surface, but I'm getting memory corruption errors during runtime. I think I'm pointing to memory that happens to be correct, but has already been freed.</p>
  
  <p>I tried using a PInvoke code gen utility called "P/Invoke Interop Assistant".  It gave me the output:</p>
  
  <pre><code>[System.Runtime.InteropServices.DLLImportAttribute(_dllLocation, EntryPoint = "foo")]
  public static extern System.IntPtr foo();
  </code></pre>
  
  <p>Is this correct? If so, how do I convert this IntPtr to a string in C#?</p>