How to pass a Reference-to-Pointer between between C# and an un-managed C++ Library?
<p>In my C/C++ Library, I've a function with such a prototype:</p>

<pre><code>long myFunction( const wchar_t*&amp; pszOutput)
</code></pre>

<p>The Dll allocates the memory for pszOutput and deallocates it too.</p>

<p>How do I call this function from C# ?</p>

<p>I've tried a lot of variation of the following line (with out, with MarshalAs, ...), but I always get a crash when exiting myFunction:</p>

<pre><code>[DllImport("mydll.dll", EntryPoint = "myFunction", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
private static extern long myFunction(ref string szOutput);
</code></pre>

<p>Does anyone knows, how to do that?</p>