How do you declare a struct in C# with a fixed sized array of another struct ? I need this declared so that it works. Or is my approach wrong if I want the bitmapinfo (-header) created ?
[StructLayout(LayoutKind.Sequential)]
public struct RGBQUAD
{
public byte b;
public byte g;
public byte r;
public byte reserved;
}
[StructLayout(LayoutKind.Sequential)]
public struct BITMAPINFO
{
public BITMAPINFOHEADER bmiHeader;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.LPStruct, SizeConst = 1)]
public RGBQUAD[] bmiColors;
}
Edit: What I learned myself is that UnmanagedType.ByValArray
and SizeConst = 1
is important here to keep the BITMAPINFO marshal size constantly at 44 bytes event if I assign 256 sized array of RGBQUAD.
Edit 2: But SizeConst mustn't be smaller than the actual array size otherwise unmanaged code can crash the app.