title: Marshalling array of structures from c++ to c# in WinCE
body: <p>I'm trying to Marshal the following structures from c++ to c# on a Windows CE program and compact framework 2.0. I'm having a lot of difficulties with the marshalling of strings. </p>
  
  <p>I have this c++ code:</p>
  
  <pre><code>#define Console_Parameters_MAX 50
  
  struct AllParameters {
    Parameter Parameters[Console_Parameters_MAX];
  } ;
  
  struct Parameter { 
    int Index;
    int Id; 
    char Value[20];
  };
  
  extern "C" {
     BOOL GetAllConsoleParameters(AllParameters *pItem);
  }
  </code></pre>
  
  <p>and this are the corresponding c# code:</p>
  
  <pre><code>[StructLayout(LayoutKind.Sequential)]
  public struct AllParameters {
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 50)]
    public Parameter[] Parameters
  }
  
  [StructLayout(LayoutKind.Sequential)]
  public struct Parameter {
    public int Index;
    public int Id;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
    public byte[] Value;
  }
  
  [DllImport("exemple.dll", SetLastError = true)]
  public static extern bool GetAllConsoleParameters([MarshalAs(UnmanagedType.Struct)] ref AllParameters pItem);
  </code></pre>
  
  <p>and this is how I invoke it:</p>
  
  <pre><code>AllParameters item = new AllParameters();
  if (AppAPI.GetAllConsoleParameters(ref item)) {
     var array = item.Parameters;
  }
  </code></pre>
  
  <p>When I call the GetAllConsoleParameters I get exception NotSupportedException. I've tried many configurations but with no success.</p>
  
  <p>Can anyone advise on how to achieve it?</p>
  
  <p>Thanks in advance</p>