title: C# Interop with C DLL, how do I marshal a char array where length is returned from the function?
body: <p>I have to access a C DLL from C#. I don't have source for the DLL so I am stuck with the following function signature:</p>
  
  <pre><code>int func(unsigned char* instr, unsigned char* outstr, int inlength);
  </code></pre>
  
  <p>How do I declare the DllImport for this in C# so that .NET understands that the returned INT is the length of the outstr array. The output char* is not a C-style string. They are byte arrays and thus there can be zeroes embedded in the output.</p>
  
  <pre><code>[DllImport("the.dll")]
  int func([In] string instr, [Out] ?????? outstr, int inlength);
  </code></pre>
  
  <p>EDIT: Please read carefully. The RETURN value is length of the outstr parameter.</p>