我在 C++ 中有一个结构定义,如下所示
typedef struct
{
unsigned __int32 SetCommonPOP:1;
unsigned __int32 SetCommonSVP:1;
unsigned __int32 SetCommonUHDP:1;
unsigned __int32 SetCommonMHDP:1;
unsigned __int32 MinPwdLength:8;
unsigned __int32 MaxPwdLength:8;
unsigned __int32 StoredHdpBackups:8;
} HPM_PWD_CONSTRAINTS;
我将其翻译为 c# 如下
[StructLayout(LayoutKind.Explicit, Size=28, CharSet=CharSet.Ansi)]
public struct HPM_PWD_CONSTRAINTS
{
[FieldOffset(0)] public uint SetCommonPOP;
[FieldOffset(1)] public uint SetCommonSVP;
[FieldOffset(2)] public uint SetCommonUHDP;
[FieldOffset(3)] public uint SetCommonMHDP;
[FieldOffset(4)] public uint MinPwdLength;
[FieldOffset(12)] public uint MaxPwdLength;
[FieldOffset(20)] public uint StoredHdpBackups;
};
我正在转换为 c# 的 c++ 中的代码定义了此结构的对象 PWD,并将 int x 的值传递给此对象。
*((uint*)&PWD) = x;
这是如何运作的?在此之后结构对象的值是多少?如何将其转换为 C#?