diff --git a/PInvoke/Kernel32/WinIOCtl.Structs.cs b/PInvoke/Kernel32/WinIOCtl.Structs.cs index f6cc334c..63c8e69c 100644 --- a/PInvoke/Kernel32/WinIOCtl.Structs.cs +++ b/PInvoke/Kernel32/WinIOCtl.Structs.cs @@ -698,7 +698,7 @@ namespace Vanara.PInvoke // DRIVE_LAYOUT_INFORMATION_GPT Gpt; } DUMMYUNIONNAME; PARTITION_INFORMATION_EX PartitionEntry[1]; } DRIVE_LAYOUT_INFORMATION_EX, *PDRIVE_LAYOUT_INFORMATION_EX; [PInvokeData("winioctl.h", MSDNShortId = "381c87a8-fe40-4251-a4df-dddc9e2a126d")] [VanaraMarshaler(typeof(SafeAnysizeStructMarshaler), nameof(PartitionCount))] - [StructLayout(LayoutKind.Explicit)] + [StructLayout(LayoutKind.Sequential)] public struct DRIVE_LAYOUT_INFORMATION_EX { /// @@ -722,7 +722,6 @@ namespace Vanara.PInvoke /// /// /// - [FieldOffset(0)] public uint PartitionStyle; /// @@ -731,25 +730,33 @@ namespace Vanara.PInvoke /// PartitionType member of the PARTITION_INFORMATION_MBR structure of the Mbr member of the /// PARTITION_INFORMATION_EX structure of the PartitionEntry member of this structure. /// - [FieldOffset(4)] public uint PartitionCount; + private DUMMYUNIONNAME union; + + /// A variable-sized array of PARTITION_INFORMATION_EX structures, one structure for each partition on the drive. + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] + public PARTITION_INFORMATION_EX[] PartitionEntry; + /// /// A DRIVE_LAYOUT_INFORMATION_MBR structure containing information about the master boot record type partitioning on the drive. /// - [FieldOffset(8)] - public DRIVE_LAYOUT_INFORMATION_MBR Mbr; + public DRIVE_LAYOUT_INFORMATION_MBR Mbr => union.Mbr; /// /// A DRIVE_LAYOUT_INFORMATION_GPT structure containing information about the GUID disk partition type partitioning on the drive. /// - [FieldOffset(8)] - public DRIVE_LAYOUT_INFORMATION_GPT Gpt; + public DRIVE_LAYOUT_INFORMATION_GPT Gpt => union.Gpt; - /// A variable-sized array of PARTITION_INFORMATION_EX structures, one structure for each partition on the drive. - [FieldOffset(48)] - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] - public PARTITION_INFORMATION_EX[] PartitionEntry; + [StructLayout(LayoutKind.Explicit, Size = 40)] + private struct DUMMYUNIONNAME + { + [FieldOffset(0)] + public DRIVE_LAYOUT_INFORMATION_MBR Mbr; + + [FieldOffset(0)] + public DRIVE_LAYOUT_INFORMATION_GPT Gpt; + } } /// Contains information about a drive's GUID partition table (GPT) partitions.