title: Marshaling pointer to an array of strings
body: <p>I am having some trouble marshaling a pointer to an array of strings.  It looks harmless like this:</p>
  
  <pre><code>typedef struct
  {
      char* listOfStrings[100];
  } UnmanagedStruct;
  </code></pre>
  
  <p>This is actually embedded inside another structure like this:</p>
  
  <pre><code>typedef struct
  {
      UnmanagedStruct umgdStruct;
  } Outerstruct;
  </code></pre>
  
  <p>Unmanaged code calls back into managed code and returns Outerstruct as an IntPtr with memory allocated and values filled in.</p>
  
  <h1>Managed world:</h1>
  
  <pre><code>[StructLayout(LayoutKind.Sequential)]
  public struct UnmanagedStruct
  {
      [MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.LPStr, SizeConst=100)]
      public string[] listOfStrings;
  }
  
  [StructLayout(LayoutKind.Sequential)]
  public struct Outerstruct
  {
      public UnmanagedStruct ums;
  }
  
  public void CallbackFromUnmanagedLayer(IntPtr outerStruct)
  {
      Outerstruct os = Marshal.PtrToStructure(outerStruct, typeof(Outerstruct));
      // The above line FAILS! it throws an exception complaining it cannot marshal listOfStrings field in the inner struct and that its managed representation is incorrect!
  }
  </code></pre>
  
  <p>If I change listOfStrings to simply be an IntPtr then Marshal.PtrToStructure works but now I am unable to rip into listOfStrings and extract the strings one by one.</p>