Is it possible to marshal a C-style struct containing bit-fields to a C# struct, or would you have to marshal it to a basic type and then do bit-masks?
E.g. I would like to marshal from a C style structure like this:
struct rgb16 {
unsigned int R : 4;
unsigned int G : 5;
unsigned int B : 4;
}
And marshal it onto something like this:
[StructLayout(LayoutKind.Sequential)]
public struct Rgb16 {
public byte R;
public byte G;
public byte B;
}
There are no bit-fields in C#. So I’d go with properties that encapsulate the bit fiddling:
I’ve avoided adding setters, because I like immutable structs, but in principle you can add them too.