using System; using System.Linq; using System.Runtime.InteropServices; namespace Vanara.PInvoke { public static partial class SetupAPI { /// /// In Windows Vista and later versions of Windows, the DEVPROPKEY structure represents a device property key for a device property /// in the unified device property model. /// /// /// The DEVPROPKEY structure is part of the unified device property model. /// The basic set of system-supplied device property keys are defined in Devpkey.h. /// The DEFINE_DEVPROPKEY macro creates an instance of a DEVPROPKEY structure that represents a device property key. /// // https://docs.microsoft.com/en-us/windows-hardware/drivers/install/devpropkey struct DEVPROPKEY { DEVPROPGUID fmtid; DEVPROPID // pid; }; [PInvokeData("Devpropdef.h")] [StructLayout(LayoutKind.Sequential)] public struct DEVPROPKEY : IEquatable { /// /// A DEVPROPGUID-typed value that specifies a property category. /// The DEVPROPGUID data type is defined as: /// public Guid fmtid; /// /// /// pid A DEVPROPID-typed value that uniquely identifies the property within the property category. For internal system /// reasons, a property identifier must be greater than or equal to two. /// /// The DEVPROPID data type is defined as: /// public uint pid; /// Initializes a new instance of the struct. /// Guid value. /// Guid value. /// Guid value. /// Guid value. /// Guid value. /// Guid value. /// Guid value. /// Guid value. /// Guid value. /// Guid value. /// Guid value. /// The pid. public DEVPROPKEY(uint a, ushort b, ushort c, byte d, byte e, byte f, byte g, byte h, byte i, byte j, byte k, uint pid) { fmtid = new Guid(a, b, c, d, e, f, g, h, i, j, k); this.pid = pid; } /// Determines whether the specified , is equal to this instance. /// The to compare with this instance. /// /// if the specified is equal to this instance; otherwise, . /// public override bool Equals(object obj) => obj is DEVPROPKEY pk && Equals(pk); /// Determines whether the specified , is equal to this instance. /// The property key. /// /// if the specified is equal to this instance; otherwise, . /// public bool Equals(DEVPROPKEY pk) => pk.pid == pid && pk.fmtid == fmtid; /// Returns a hash code for this instance. /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. public override int GetHashCode() => (pid, fmtid).GetHashCode(); /// Performs a lookup of this against defined values in this assembly to find a name. /// The name, if found, otherwise . public string LookupName() { var dpkType = GetType(); var lthis = this; return dpkType.DeclaringType.GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static). Where(fi => fi.FieldType == dpkType && lthis.Equals(fi.GetValue(null))).Select(fi => fi.Name).FirstOrDefault(); } /// public override string ToString() => LookupName() ?? $"{fmtid}:{pid}"; } } }