Ignore what I posted previously, I was somewhat overcomplicating things! The method I suggested can be used when an unknown length of data is required to be marshalled.
As you know the length, it's simple:
[StructLayout(LayoutKind.Sequential)]
struct Inner
{
public uint A;
public byte B;
}
[StructLayout(LayoutKind.Sequential)]
struct Foo
{
public ushort W;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public byte[] X;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
public Inner[] data;
}
Why are you using
fixed
and
unsafe
?