Right know in my code I have structure declared as like this, with fixed this 16, know at compile time.
struct CONSOLE_SCREEN_BUFFER_INFOEX
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public int ColorTable[];
}
but what I need is to be able to have this structure:
struct CONSOLE_SCREEN_BUFFER_INFOEX
{
int arraySize;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 0)]
public int ColorTable[];
}
get the arraySize from C function response, initialize ColorTable array with proper size, put result of response into ColorTable.
Not sure if it's possible, just doing investigation right now, and any comments are very welcome.
You can do this easily enough with some manual marshalling using the
Marshal
class. For example: