typedef union _USB_PROTOCOLS {
ULONG ul;
struct {
ULONG Usb110 : 1;
ULONG Usb200 : 1;
ULONG Usb300 : 1;
ULONG ReservedMBZ : 29;
};
} USB_PROTOCOLS, *PUSB_PROTOCOLS;
如上,这一段转换成C#d结构体是什么样的?
C语言的位域C#没法转换,不过可以换个思路用属性来模拟
public struct _USB_PROTOCOLS
{
public UInt32 ul;
public UInt32 Usb110
{
get => ul & 0x80000000;
set => ul = (ul & 0x7FFFFFFF) | (value << 31);
}
public UInt32 Usb200
{
get => Usb110;
set => Usb110 = value;
}
public UInt32 Usb300
{
get => Usb110;
set => Usb110 = value;
}
public UInt32 ReservedMBZ
{
get => ul & 0x7FFFFFFF;
set => ul = (ul & 0x80000000) | (value & 0x7FFFFFFF);
}
}