Converted structures that supported IMarshalDirective to IVanaraMarshaler

pull/83/head
David Hall 2019-11-13 23:04:48 -05:00
parent 8f289e2760
commit e4959743fc
6 changed files with 101 additions and 32 deletions

View File

@ -4842,7 +4842,7 @@ namespace Vanara.PInvoke
// flAccel; DWORD cGlyphsSupported; DWORD cRanges; WCRANGE ranges[1]; } GLYPHSET, *PGLYPHSET, *LPGLYPHSET;
[PInvokeData("wingdi.h", MSDNShortId = "b8ac8d3f-b062-491c-966f-02f3d4c11419")]
[StructLayout(LayoutKind.Sequential)]
public struct GLYPHSET : IMarshalDirective
public struct GLYPHSET : IVanaraMarshaler
{
/// <summary>The size, in bytes, of this structure.</summary>
public uint cbThis;
@ -4872,8 +4872,9 @@ namespace Vanara.PInvoke
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public WCRANGE[] ranges;
MarshalDirectiveActivator IMarshalDirective.GetActivator() => (p, s) => p != IntPtr.Zero ? new SafeAnysizeStruct<GLYPHSET>(p, s, nameof(cRanges)).Value : default;
SafeAllocatedMemoryHandle IMarshalDirective.ToNative() => new SafeAnysizeStruct<GLYPHSET>(this, nameof(cRanges));
SizeT IVanaraMarshaler.GetNativeSize() => 20;
SafeAllocatedMemoryHandle IVanaraMarshaler.MarshalManagedToNative(object managedObject) => new SafeAnysizeStruct<GLYPHSET>((GLYPHSET)managedObject, nameof(cRanges));
object IVanaraMarshaler.MarshalNativeToManaged(IntPtr p, SizeT s) => p != IntPtr.Zero ? new SafeAnysizeStruct<GLYPHSET>(p, s, nameof(cRanges)).Value : default;
}
/// <summary>The <c>KERNINGPAIR</c> structure defines a kerning pair.</summary>

View File

@ -1042,7 +1042,7 @@ namespace Vanara.PInvoke
// DRIVE_LAYOUT_INFORMATION, *PDRIVE_LAYOUT_INFORMATION;
[PInvokeData("winioctl.h", MSDNShortId = "e67ccaa7-a735-4695-8385-28f57b41821c")]
[StructLayout(LayoutKind.Sequential)]
public struct DRIVE_LAYOUT_INFORMATION : IMarshalDirective
public struct DRIVE_LAYOUT_INFORMATION : IVanaraMarshaler
{
/// <summary>
/// <para>The number of partitions on a drive.</para>
@ -1060,8 +1060,9 @@ namespace Vanara.PInvoke
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public PARTITION_INFORMATION[] PartitionEntry;
MarshalDirectiveActivator IMarshalDirective.GetActivator() => (p, s) => p != IntPtr.Zero ? new SafeAnysizeStruct<DRIVE_LAYOUT_INFORMATION>(p, s, nameof(PartitionCount)).Value : default;
SafeAllocatedMemoryHandle IMarshalDirective.ToNative() => new SafeAnysizeStruct<DRIVE_LAYOUT_INFORMATION>(this, nameof(PartitionCount));
SizeT IVanaraMarshaler.GetNativeSize() => Marshal.SizeOf(GetType());
SafeAllocatedMemoryHandle IVanaraMarshaler.MarshalManagedToNative(object obj) => new SafeAnysizeStruct<DRIVE_LAYOUT_INFORMATION>((DRIVE_LAYOUT_INFORMATION)obj, nameof(PartitionCount));
object IVanaraMarshaler.MarshalNativeToManaged(IntPtr p, SizeT s) => p != IntPtr.Zero ? new SafeAnysizeStruct<DRIVE_LAYOUT_INFORMATION>(p, s, nameof(PartitionCount)).Value : default;
}
/// <summary>Contains extended information about a drive's partitions.</summary>
@ -1070,7 +1071,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")]
[StructLayout(LayoutKind.Explicit)]
public struct DRIVE_LAYOUT_INFORMATION_EX : IMarshalDirective
public struct DRIVE_LAYOUT_INFORMATION_EX : IVanaraMarshaler
{
/// <summary>
/// <para>The style of the partitions on the drive enumerated by the PARTITION_STYLE enumeration.</para>
@ -1122,8 +1123,9 @@ namespace Vanara.PInvoke
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public PARTITION_INFORMATION_EX[] PartitionEntry;
MarshalDirectiveActivator IMarshalDirective.GetActivator() => (p, s) => p != IntPtr.Zero ? new SafeAnysizeStruct<DRIVE_LAYOUT_INFORMATION_EX>(p, s, nameof(PartitionCount)).Value : default;
SafeAllocatedMemoryHandle IMarshalDirective.ToNative() => new SafeAnysizeStruct<DRIVE_LAYOUT_INFORMATION_EX>(this, nameof(PartitionCount));
SizeT IVanaraMarshaler.GetNativeSize() => Marshal.SizeOf(GetType());
SafeAllocatedMemoryHandle IVanaraMarshaler.MarshalManagedToNative(object obj) => new SafeAnysizeStruct<DRIVE_LAYOUT_INFORMATION_EX>((DRIVE_LAYOUT_INFORMATION_EX)obj, nameof(PartitionCount));
object IVanaraMarshaler.MarshalNativeToManaged(IntPtr p, SizeT s) => p != IntPtr.Zero ? new SafeAnysizeStruct<DRIVE_LAYOUT_INFORMATION_EX>(p, s, nameof(PartitionCount)).Value : default;
}
/// <summary>Contains information about a drive's GUID partition table (GPT) partitions.</summary>
@ -3882,7 +3884,7 @@ namespace Vanara.PInvoke
// RemainingExtents; WORD NumberOfExtents; WORD ExtentSize; USN_RECORD_EXTENT Extents[1]; } USN_RECORD_V4, *PUSN_RECORD_V4;
[PInvokeData("winioctl.h", MSDNShortId = "2636D1A1-6FD1-4F84-954C-499DCCE6E390")]
[StructLayout(LayoutKind.Sequential, Size = 80)]
public struct USN_RECORD_V4 : IMarshalDirective
public struct USN_RECORD_V4 : IVanaraMarshaler
{
/// <summary>
/// A USN_RECORD_COMMON_HEADER structure that describes the record length, major version, and minor version for the record.
@ -4103,8 +4105,9 @@ namespace Vanara.PInvoke
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public USN_RECORD_EXTENT[] Extents;
MarshalDirectiveActivator IMarshalDirective.GetActivator() => (p, s) => p != IntPtr.Zero ? new SafeAnysizeStruct<USN_RECORD_V4>(p, s, nameof(NumberOfExtents)).Value : default;
SafeAllocatedMemoryHandle IMarshalDirective.ToNative() => new SafeAnysizeStruct<USN_RECORD_V4>(this, nameof(NumberOfExtents));
SizeT IVanaraMarshaler.GetNativeSize() => Marshal.SizeOf(GetType());
SafeAllocatedMemoryHandle IVanaraMarshaler.MarshalManagedToNative(object obj) => new SafeAnysizeStruct<USN_RECORD_V4>((USN_RECORD_V4)obj, nameof(NumberOfExtents));
object IVanaraMarshaler.MarshalNativeToManaged(IntPtr p, SizeT s) => p != IntPtr.Zero ? new SafeAnysizeStruct<USN_RECORD_V4>(p, s, nameof(NumberOfExtents)).Value : default;
}
/// <summary>

View File

@ -5090,7 +5090,7 @@ namespace Vanara.PInvoke
// dwStructureSize; DWORD dwRecordType; DWORD dwItems; UCHAR RawBytes[1]; } PDH_RAW_LOG_RECORD, *PPDH_RAW_LOG_RECORD;
[PInvokeData("pdh.h", MSDNShortId = "ae96515f-ea3f-4578-a249-fb8f41cdfa69")]
[StructLayout(LayoutKind.Sequential)]
public struct PDH_RAW_LOG_RECORD : IMarshalDirective
public struct PDH_RAW_LOG_RECORD : IVanaraMarshaler
{
/// <summary>
/// Size of this structure, in bytes. The size includes this structure and the <c>RawBytes</c> appended to the end of this structure.
@ -5135,8 +5135,9 @@ namespace Vanara.PInvoke
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public byte[] RawBytes;
MarshalDirectiveActivator IMarshalDirective.GetActivator() => (p, s) => p != IntPtr.Zero ? new SafeAnysizeStruct<PDH_RAW_LOG_RECORD>(p, s, nameof(dwItems)).Value : default;
SafeAllocatedMemoryHandle IMarshalDirective.ToNative() => new SafeAnysizeStruct<PDH_RAW_LOG_RECORD>(this, nameof(dwItems));
SizeT IVanaraMarshaler.GetNativeSize() => Marshal.SizeOf(GetType());
SafeAllocatedMemoryHandle IVanaraMarshaler.MarshalManagedToNative(object obj) => new SafeAnysizeStruct<PDH_RAW_LOG_RECORD>((PDH_RAW_LOG_RECORD)obj, nameof(dwItems));
object IVanaraMarshaler.MarshalNativeToManaged(IntPtr p, SizeT s) => p != IntPtr.Zero ? new SafeAnysizeStruct<PDH_RAW_LOG_RECORD>(p, s, nameof(dwItems)).Value : default;
}
/// <summary>

View File

@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Runtime.InteropServices;
using Vanara.InteropServices;
using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME;
@ -48,6 +49,36 @@ namespace Vanara.PInvoke
DOMAIN_NO_LM_OWF_CHANGE = 0x00000040
}
/// <summary>Auditing options for an audit event type.</summary>
[PInvokeData("ntsecapi.h")]
[Flags]
public enum POLICY_AUDIT_EVENT_OPTIONS : uint
{
/// <summary>
/// Do not change auditing options for the specified event type.
/// <para>This value is valid for the AuditSetSystemPolicy and AuditQuerySystemPolicy functions.</para>
/// </summary>
POLICY_AUDIT_EVENT_UNCHANGED = 0x00000000,
/// <summary>
/// Audit successful occurrences of the specified event type.
/// <para>This value is valid for the AuditSetSystemPolicy and AuditQuerySystemPolicy functions.</para>
/// </summary>
POLICY_AUDIT_EVENT_SUCCESS = 0x00000001,
/// <summary>
/// Audit failed attempts to cause the specified event type.
/// <para>This value is valid for the AuditSetSystemPolicy and AuditQuerySystemPolicy functions.</para>
/// </summary>
POLICY_AUDIT_EVENT_FAILURE = 0x00000002,
/// <summary>
/// Do not audit the specified event type.
/// <para>This value is valid for the AuditSetSystemPolicy and AuditQuerySystemPolicy functions.</para>
/// </summary>
POLICY_AUDIT_EVENT_NONE = 0x00000004,
}
/// <summary>The <c>POLICY_DOMAIN_INFORMATION_CLASS</c> enumeration defines the type of policy domain information.</summary>
// https://docs.microsoft.com/en-us/windows/desktop/api/ntsecapi/ne-ntsecapi-_policy_domain_information_class typedef enum
// _POLICY_DOMAIN_INFORMATION_CLASS { PolicyDomainQualityOfServiceInformation, PolicyDomainEfsInformation,
@ -515,7 +546,7 @@ namespace Vanara.PInvoke
// } POLICY_AUDIT_EVENTS_INFO, *PPOLICY_AUDIT_EVENTS_INFO;
[PInvokeData("ntsecapi.h", MSDNShortId = "3442e5e5-78cf-4bda-ba11-0f51ee40df16")]
[StructLayout(LayoutKind.Sequential)]
public struct POLICY_AUDIT_EVENTS_INFO
public struct POLICY_AUDIT_EVENTS_INFO : IVanaraMarshaler
{
/// <summary>
/// <para>Indicates whether auditing is enabled.</para>
@ -528,8 +559,7 @@ namespace Vanara.PInvoke
/// auditing options as specified in the <c>EventAuditingOptions</c> member even when <c>AuditingMode</c> is <c>FALSE</c>.
/// </para>
/// </summary>
[MarshalAs(UnmanagedType.U1)]
public bool AuditingMode;
public BOOLEAN AuditingMode;
/// <summary>
/// <para>
@ -572,14 +602,44 @@ namespace Vanara.PInvoke
/// </item>
/// </list>
/// </summary>
public IntPtr EventAuditingOptions;
public POLICY_AUDIT_EVENT_OPTIONS[] EventAuditingOptions;
/// <summary>
/// Specifies the number of elements in the <c>EventAuditingOptions</c> array. For set operations, if this value is less than the
/// number of audit event types supported by the system, the system does not change the auditing options for event types with
/// indexes equal to or higher than the value specified in <c>MaximumAuditEventCount</c>.
/// </summary>
public uint MaximumAuditEventCount;
public int MaximumAuditEventCount => EventAuditingOptions?.Length ?? 0;
SizeT IVanaraMarshaler.GetNativeSize() => 8 + IntPtr.Size;
SafeAllocatedMemoryHandle IVanaraMarshaler.MarshalManagedToNative(object obj)
{
var i = (POLICY_AUDIT_EVENTS_INFO)obj;
var mem = new SafeHGlobalHandle(64);
using (var ret = new NativeMemoryStream(mem))
{
ret.Write(i.AuditingMode);
ret.Position = 4;
ret.Write(i.EventAuditingOptions, true);
ret.Write(i.MaximumAuditEventCount);
}
return mem;
}
object IVanaraMarshaler.MarshalNativeToManaged(IntPtr ptr, SizeT size)
{
using var str = new NativeMemoryStream(ptr, size);
var mode = str.Read<BOOLEAN>();
str.Position = 4 + IntPtr.Size;
var cnt = str.Read<int>();
str.Position = 4;
return new POLICY_AUDIT_EVENTS_INFO
{
AuditingMode = mode,
EventAuditingOptions = str.ReadArray<POLICY_AUDIT_EVENT_OPTIONS>(cnt, true).ToArray()
};
}
}
/// <summary>

View File

@ -3787,7 +3787,7 @@ namespace Vanara.PInvoke
/// <summary>The TOKEN_GROUPS structure contains information about the group security identifiers (SIDs) in an access token.</summary>
[StructLayout(LayoutKind.Sequential)]
public struct TOKEN_GROUPS : IMarshalDirective
public struct TOKEN_GROUPS : IVanaraMarshaler
{
/// <summary>Specifies the number of groups in the access token.</summary>
public uint GroupCount;
@ -3820,8 +3820,9 @@ namespace Vanara.PInvoke
Groups[0] = new SID_AND_ATTRIBUTES(sid, attributes);
}
MarshalDirectiveActivator IMarshalDirective.GetActivator() => (p, s) => p != IntPtr.Zero ? new SafeAnysizeStruct<TOKEN_GROUPS>(p, s, nameof(GroupCount)).Value : default;
SafeAllocatedMemoryHandle IMarshalDirective.ToNative() => new SafeAnysizeStruct<TOKEN_GROUPS>(this);
SizeT IVanaraMarshaler.GetNativeSize() => Marshal.SizeOf(GetType());
SafeAllocatedMemoryHandle IVanaraMarshaler.MarshalManagedToNative(object obj) => new SafeAnysizeStruct<TOKEN_GROUPS>((TOKEN_GROUPS)obj, nameof(GroupCount));
object IVanaraMarshaler.MarshalNativeToManaged(IntPtr p, SizeT s) => p != IntPtr.Zero ? new SafeAnysizeStruct<TOKEN_GROUPS>(p, s, nameof(GroupCount)).Value : default;
}
/// <summary>
@ -3972,7 +3973,7 @@ namespace Vanara.PInvoke
// PrivilegeCount; LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY]; } TOKEN_PRIVILEGES, *PTOKEN_PRIVILEGES;
[PInvokeData("winnt.h", MSDNShortId = "c9016511-740f-44f3-92ed-17cc518c6612")]
[StructLayout(LayoutKind.Sequential)]
public struct TOKEN_PRIVILEGES : IMarshalDirective
public struct TOKEN_PRIVILEGES : IVanaraMarshaler
{
/// <summary>This must be set to the number of entries in the <c>Privileges</c> array.</summary>
public uint PrivilegeCount;
@ -4034,8 +4035,9 @@ namespace Vanara.PInvoke
Privileges = (LUID_AND_ATTRIBUTES[])values?.Clone() ?? new LUID_AND_ATTRIBUTES[0];
}
MarshalDirectiveActivator IMarshalDirective.GetActivator() => (p, s) => p != IntPtr.Zero ? new SafeAnysizeStruct<TOKEN_PRIVILEGES>(p, s, nameof(PrivilegeCount)).Value : default;
SafeAllocatedMemoryHandle IMarshalDirective.ToNative() => new SafeAnysizeStruct<TOKEN_PRIVILEGES>(this);
SizeT IVanaraMarshaler.GetNativeSize() => Marshal.SizeOf(GetType());
SafeAllocatedMemoryHandle IVanaraMarshaler.MarshalManagedToNative(object obj) => new SafeAnysizeStruct<TOKEN_PRIVILEGES>((TOKEN_PRIVILEGES)obj, nameof(PrivilegeCount));
object IVanaraMarshaler.MarshalNativeToManaged(IntPtr p, SizeT s) => p != IntPtr.Zero ? new SafeAnysizeStruct<TOKEN_PRIVILEGES>(p, s, nameof(PrivilegeCount)).Value : default;
}
/// <summary>The TOKEN_SOURCE structure identifies the source of an access token.</summary>

View File

@ -957,7 +957,7 @@ namespace Vanara.PInvoke
// CM_PARTIAL_RESOURCE_LIST, *PCM_PARTIAL_RESOURCE_LIST;
[PInvokeData("wdm.h", MSDNShortId = "f16b26f5-1f32-4c2e-83ec-0a0f79a4be85")]
[StructLayout(LayoutKind.Sequential)]
public struct CM_PARTIAL_RESOURCE_LIST : IMarshalDirective
public struct CM_PARTIAL_RESOURCE_LIST : IVanaraMarshaler
{
/// <summary>The version number of this structure. This value should be 1.</summary>
public ushort Version;
@ -972,8 +972,9 @@ namespace Vanara.PInvoke
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public CM_PARTIAL_RESOURCE_DESCRIPTOR[] PartialDescriptors;
MarshalDirectiveActivator IMarshalDirective.GetActivator() => (p, s) => p != IntPtr.Zero ? new SafeAnysizeStruct<CM_PARTIAL_RESOURCE_LIST>(p, s, nameof(Count)).Value : default;
SafeAllocatedMemoryHandle IMarshalDirective.ToNative() => new SafeAnysizeStruct<CM_PARTIAL_RESOURCE_LIST>(this, nameof(Count));
SizeT IVanaraMarshaler.GetNativeSize() => Marshal.SizeOf(GetType());
SafeAllocatedMemoryHandle IVanaraMarshaler.MarshalManagedToNative(object obj) => new SafeAnysizeStruct<CM_PARTIAL_RESOURCE_LIST>((CM_PARTIAL_RESOURCE_LIST)obj, nameof(Count));
object IVanaraMarshaler.MarshalNativeToManaged(IntPtr p, SizeT s) => p != IntPtr.Zero ? new SafeAnysizeStruct<CM_PARTIAL_RESOURCE_LIST>(p, s, nameof(Count)).Value : default;
}
/// <summary>The <c>CM_RESOURCE_LIST</c> structure specifies all of the system hardware resources assigned to a device.</summary>
@ -1017,7 +1018,7 @@ namespace Vanara.PInvoke
// ULONG Count; CM_FULL_RESOURCE_DESCRIPTOR List[1]; } CM_RESOURCE_LIST, *PCM_RESOURCE_LIST;
[PInvokeData("wdm.h", MSDNShortId = "01f31255-a4f7-4a16-9238-a7391bb850d1")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct CM_RESOURCE_LIST : IMarshalDirective
public struct CM_RESOURCE_LIST : IVanaraMarshaler
{
/// <summary>
/// The number of full resource descriptors that are specified by this <c>CM_RESOURCE_LIST</c> structure. The <c>List</c> member is
@ -1034,7 +1035,8 @@ namespace Vanara.PInvoke
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public CM_FULL_RESOURCE_DESCRIPTOR[] List;
MarshalDirectiveActivator IMarshalDirective.GetActivator() => (p, s) => p != IntPtr.Zero ? new SafeAnysizeStruct<CM_RESOURCE_LIST>(p, s, nameof(Count)).Value : default;
SafeAllocatedMemoryHandle IMarshalDirective.ToNative() => new SafeAnysizeStruct<CM_RESOURCE_LIST>(this, nameof(Count));
SizeT IVanaraMarshaler.GetNativeSize() => Marshal.SizeOf(GetType());
SafeAllocatedMemoryHandle IVanaraMarshaler.MarshalManagedToNative(object obj) => new SafeAnysizeStruct<CM_RESOURCE_LIST>((CM_RESOURCE_LIST)obj, nameof(Count));
object IVanaraMarshaler.MarshalNativeToManaged(IntPtr p, SizeT s) => p != IntPtr.Zero ? new SafeAnysizeStruct<CM_RESOURCE_LIST>(p, s, nameof(Count)).Value : default;
}
}