title: Converting mixed type return data from an unmanaged C DLL?
body: <p>I am writing a wrapper C# DLL to interface with a supplier provided unmanaged DLL written in C. For the most part everything is smooth, however there are some functions that in the provided documentation look like this:</p>
  <pre><code>int get_value(int unit, int id, int* value)
  </code></pre>
  <p>My issue is that <code>int* value</code> is an array with a mixture of int's and float's... The documentation states which is which, i.e. that the first value is an <code>int</code>, the second and third are <code>float</code>, etc.. I have some success if i specifically call out the DLL <code>value</code> as <code>int</code> or <code>float</code>. That returns some of the data i'm looking for, but only for the one type. For example, this kinda works:</p>
  <pre><code>[DllImport(&quot;supplier.dll&quot;)]
  public static extern int get_value(int unit, int id, float* value)
  
  public static int GetValue(int unit, int id, out float[] value)
  {
       float[] value = new float[3];
       int ret = get_value(unit, id, value);
       
       return ret;
  }
  </code></pre>
  <p><code>value</code> is returned with [NaN, value1, value2] because the 0 index is actually an integer and it's not interpreted correctly. I have attempted to use an IntPtr[] as the return <code>value</code> in the unmanaged DLL and then use <code>Marshal.Copy()</code> to get the data from the memory locations, but this hasn't gone well. Is that a promising approach? If so, I'm not sure which overload to use, an example would be very helpful!</p>