title: How to get unmanaged variable-length C-array within a struct from C to C#?
body: <p>How do I return  the <code>MIB_IPFORWARDROW</code> array?</p>
  
  <pre><code>struct MIB_IPFORWARDTABLE
  {
      public uint Size;
  
      [MarshalAs(/* what goes here? */)]
      public IPFORWARDROW[] Table;
  };
  
  [DllImport("iphlpapi", CharSet = CharSet.Auto)]
  private static extern int GetIpForwardTable(
      IntPtr /* MIB_IPFORWARDTABLE* */ pIpForwardTable,
      ref uint /* ULONG* */ pdwSize,
      bool bOrder);
  
  public static MIB_IPFORWARDROW[] Temp()
  {
      var fwdTable = IntPtr.Zero;
      uint size = 0;
      var result = GetIpForwardTable(fwdTable, ref size, true);
      fwdTable = Marshal.AllocHGlobal((int) size);
      result = GetIpForwardTable(fwdTable, ref size, true);
  
      /*
      what now ?
      I tried:
  
      var table = (MIB_IPFORWARDTABLE) Marshal.PtrToStructure(fwdTable, typeof(MIB_IPFORWARDTABLE));
  
      but table.Table is always null
      */
  }
  </code></pre>
  
  <p>(See <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa365953%28v=vs.85%29.aspx" rel="nofollow noreferrer">GetIpForwardTable</a>)</p>
  
  <p>I've seen this:
  <a href="https://stackoverflow.com/questions/5902103/how-do-i-marshal-a-struct-that-contains-a-variable-sized-array-to-c">How do I marshal a struct that contains a variable-sized array to C#?</a></p>
  
  <p>But whatever I do, fwdTable.Table is always null, IntPtr.Zero or 0. That is ofcourse, if no Exception is thrown..</p>