title: How to marshall array of structs in C#?
body: <p>I've the following structure in C#:</p>
  
  <pre><code>[StructLayoutAttribute(LayoutKind.Sequential)]
  public struct RECORD
  {
      public uint m1;
      public uint m2;
      public uint m3;
  }
  </code></pre>
  
  <p>I need too pass an <strong>array</strong> (fixed length) of these structs over to native Code, which writes some data to these structures. The array is allocated in C# and passed over to the C dll. I declared the imported function as:</p>
  
  <pre><code>[DllImport("marshall.dll", CallingConvention = CallingConvention.Cdecl)]
  private static extern void doIt(RECORD[] dataRecord);
  </code></pre>
  
  <p>but I don't get any data back. I already tried the PInvoke Interop Assistant. Should I use IntPtr here? Any ideas?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Here is the C# code to call the native function:</p>
  
  <pre><code>RECORD[] rec = new RECORD[256];
  doIt(rec);
  // values of rec are all zero here
  </code></pre>
  
  <p>Here is the C function:</p>
  
  <pre><code>int doIt(RECORD* rec)
  {
      // deref pointer and write some data
  }
  </code></pre>