diff --git a/PInvoke/CfgMgr32/CfgMgr32.Structs.cs b/PInvoke/CfgMgr32/CfgMgr32.Structs.cs new file mode 100644 index 00000000..3aea421a --- /dev/null +++ b/PInvoke/CfgMgr32/CfgMgr32.Structs.cs @@ -0,0 +1,1511 @@ +using Microsoft.Win32.SafeHandles; +using System; +using System.Runtime.InteropServices; +using System.Text; +using Vanara.InteropServices; +using static Vanara.PInvoke.AdvApi32; +using static Vanara.PInvoke.SetupAPI; + +namespace Vanara.PInvoke +{ + /// Items from the CfgMgr32.dll + public static partial class CfgMgr32 + { + /// + public static readonly uint BusNumberType_Range = (uint)Marshal.SizeOf(typeof(BUSNUMBER_RANGE)); + + /// + public static readonly uint DType_Range = (uint)Marshal.SizeOf(typeof(DMA_RANGE)); + + /// + public static readonly uint IOType_Range = (uint)Marshal.SizeOf(typeof(IO_RANGE)); + + /// + public static readonly uint IRQType_Range = (uint)Marshal.SizeOf(typeof(IRQ_RANGE)); + + /// + public static readonly uint MType_Range = (uint)Marshal.SizeOf(typeof(MEM_RANGE)); + + /// + /// The BUSNUMBER_DES structure is used for specifying either a resource list or a resource requirements list that describes bus + /// number usage for a device instance. For more information about resource lists and resource requirements lists, see Hardware Resources. + /// + /// The BUSNUMBER_DES structure is included as a member of the BUSNUMBER_RESOURCE structure. + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/ns-cfgmgr32-busnumber_des typedef struct BusNumber_Des_s { DWORD + // BUSD_Count; DWORD BUSD_Type; DWORD BUSD_Flags; ULONG BUSD_Alloc_Base; ULONG BUSD_Alloc_End; } BUSNUMBER_DES, *PBUSNUMBER_DES; + [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32.BusNumber_Des_s")] + [StructLayout(LayoutKind.Sequential)] + public struct BUSNUMBER_DES + { + /// + /// For a resource list: + /// Zero. + /// For a resource requirements list: + /// The number of elements in the BUSNUMBER_RANGE array that is included in the BUSNUMBER_RESOURCE structure. + /// + public uint BUSD_Count; + + /// Must be set to the constant value . + public uint BUSD_Type; + + /// Not used. + public uint BUSD_Flags; + + /// + /// For a resource list: + /// The lowest-numbered of a range of contiguous bus numbers allocated to the device. + /// For a resource requirements list: + /// Zero. + /// + public uint BUSD_Alloc_Base; + + /// + /// For a resource list: + /// The highest-numbered of a range of contiguous bus numbers allocated to the device. + /// For a resource requirements list: + /// Zero. + /// + public uint BUSD_Alloc_End; + } + + /// + /// The BUSNUMBER_RANGE structure specifies a resource requirements list that describes bus number usage for a device instance. For + /// more information about resource requirements lists, see Hardware Resources. + /// + /// The BUSNUMBER_RANGE structure is included as a member of the BUSNUMBER_RESOURCE structure. + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/ns-cfgmgr32-busnumber_range typedef struct BusNumber_Range_s { ULONG + // BUSR_Min; ULONG BUSR_Max; ULONG BUSR_nBusNumbers; ULONG BUSR_Flags; } BUSNUMBER_RANGE, *PBUSNUMBER_RANGE; + [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32.BusNumber_Range_s")] + [StructLayout(LayoutKind.Sequential)] + public struct BUSNUMBER_RANGE + { + /// The lowest-numbered of a range of contiguous bus numbers that can be allocated to the device. + public uint BUSR_Min; + + /// The highest-numbered of a range of contiguous bus numbers that can be allocated to the device. + public uint BUSR_Max; + + /// The number of contiguous bus numbers required by the device. + public uint BUSR_nBusNumbers; + + /// Not used. + public uint BUSR_Flags; + } + + /// + /// The BUSNUMBER_RESOURCE structure specifies either a resource list or a resource requirements list that describes bus number + /// usage for a device instance. For more information about resource lists and resource requirements lists, see Hardware Resources. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/ns-cfgmgr32-busnumber_resource typedef struct BusNumber_Resource_s { + // BUSNUMBER_DES BusNumber_Header; BUSNUMBER_RANGE BusNumber_Data[ANYSIZE_ARRAY]; } BUSNUMBER_RESOURCE, *PBUSNUMBER_RESOURCE; + [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32.BusNumber_Resource_s")] + [StructLayout(LayoutKind.Sequential)] + [VanaraMarshaler(typeof(SafeAnysizeStructMarshaler), "*")] + public struct BUSNUMBER_RESOURCE + { + /// A BUSNUMBER_DES structure. + public BUSNUMBER_DES BusNumber_Header; + + /// + /// For a resource list: + /// Zero. + /// For a resource requirements list: + /// A BUSNUMBER_RANGE array. + /// + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] + public BUSNUMBER_RANGE[] BusNumber_Data; + } + + /// This is a device notification event data structure. + /// + /// The notification callback supplied to CM_Register_Notification receives a pointer to a structure of type + /// CM_NOTIFY_EVENT_DATA in the callback's EventData parameter. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/ns-cfgmgr32-cm_notify_event_data typedef struct _CM_NOTIFY_EVENT_DATA + // { CM_NOTIFY_FILTER_TYPE FilterType; DWORD Reserved; union { struct { GUID ClassGuid; WCHAR SymbolicLink[ANYSIZE_ARRAY]; } + // DeviceInterface; struct { GUID EventGuid; LONG NameOffset; DWORD DataSize; BYTE Data[ANYSIZE_ARRAY]; } DeviceHandle; struct { + // WCHAR InstanceId[ANYSIZE_ARRAY]; } DeviceInstance; } u; } CM_NOTIFY_EVENT_DATA, *PCM_NOTIFY_EVENT_DATA; + [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32._CM_NOTIFY_EVENT_DATA")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] + public struct CM_NOTIFY_EVENT_DATA + { + /// + /// The CM_NOTIFY_FILTER_TYPE from the CM_NOTIFY_FILTER structure that was used in the registration that generated this + /// notification event data. + /// + public CM_NOTIFY_FILTER_TYPE FilterType; + + /// Reserved. Must be 0. + public uint Reserved; + + /// + /// A union that contains information about the notification event data. To determine which member of the union to examine, + /// check the FilterType of the event data. + /// + public UNION u; + + /// + /// A union that contains information about the notification event data. To determine which member of the union to examine, + /// check the FilterType of the event data. + /// + [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode)] + public struct UNION + { + /// Examine this part of the union when the FilterType is CM_NOTIFY_FILTER_TYPE_DEVICEINTERFACE. + [FieldOffset(0)] + public DEVICEINTERFACE DeviceInterface; + + /// + /// Examine this part of the union when the FilterType is CM_NOTIFY_FILTER_TYPE_DEVICEHANDLE and the + /// notification action is CM_NOTIFY_ACTION_DEVICECUSTOMEVENT. + /// + [FieldOffset(0)] + public DEVICEHANDLE DeviceHandle; + + /// Examine this part of the union when the FilterType is CM_NOTIFY_FILTER_TYPE_DEVICEINSTANCE. + [FieldOffset(0)] + public DEVICEINSTANCE DeviceInstance; + + /// Examine this part of the union when the FilterType is CM_NOTIFY_FILTER_TYPE_DEVICEINTERFACE. + public unsafe struct DEVICEINTERFACE + { + /// + /// The GUID of the device interface class for the device interface to which the notification event data pertains. + /// + public Guid ClassGuid; + + /// The symbolic link path of the device interface to which the notification event data pertains. + public fixed char SymbolicLink[1]; + } + + /// + /// Examine this part of the union when the FilterType is CM_NOTIFY_FILTER_TYPE_DEVICEHANDLE and the + /// notification action is CM_NOTIFY_ACTION_DEVICECUSTOMEVENT. + /// + public unsafe struct DEVICEHANDLE + { + /// The GUID for the custom event. + public Guid EventGuid; + + /// The offset of an optional string buffer. Usage depends on the contract for the EventGuid. + public int NameOffset; + + /// The number of bytes that can be read from the Data member. + public uint DataSize; + + /// Optional binary data. Usage depends on the contract for the EventGuid. + public fixed byte Data[1]; + } + + /// Examine this part of the union when the FilterType is CM_NOTIFY_FILTER_TYPE_DEVICEINSTANCE. + public unsafe struct DEVICEINSTANCE + { + /// The device instance ID of the device to which the notification event data pertains. + public fixed char InstanceId[1]; + } + } + } + + /// Device notification filter structure + /// + /// When the driver calls the CM_Register_Notificationfunction, it supplies a pointer to a CM_NOTIFY_FILTER structure in the + /// pFilter parameter. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/ns-cfgmgr32-cm_notify_filter typedef struct _CM_NOTIFY_FILTER { DWORD + // cbSize; DWORD Flags; CM_NOTIFY_FILTER_TYPE FilterType; DWORD Reserved; union { struct { GUID ClassGuid; } DeviceInterface; struct + // { HANDLE hTarget; } DeviceHandle; struct { WCHAR InstanceId[MAX_DEVICE_ID_LEN]; } DeviceInstance; } u; } CM_NOTIFY_FILTER, *PCM_NOTIFY_FILTER; + [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32._CM_NOTIFY_FILTER")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 4)] + public struct CM_NOTIFY_FILTER + { + /// Initializes a new instance of the struct. + /// The GUID of the device interface class for which to receive notifications. + public CM_NOTIFY_FILTER(Guid deviceInterfaceClassGuid) : this() + { + cbSize = (uint)Marshal.SizeOf(typeof(CM_NOTIFY_FILTER)); + FilterType = CM_NOTIFY_FILTER_TYPE.CM_NOTIFY_FILTER_TYPE_DEVICEINTERFACE; + u.DeviceInterface_ClassGuid = deviceInterfaceClassGuid; + } + + /// Initializes a new instance of the struct. + /// A handle to the device for which to receive notifications. + public CM_NOTIFY_FILTER(IntPtr hTargetDevice) : this() + { + cbSize = (uint)Marshal.SizeOf(typeof(CM_NOTIFY_FILTER)); + FilterType = CM_NOTIFY_FILTER_TYPE.CM_NOTIFY_FILTER_TYPE_DEVICEHANDLE; + u.DeviceHandle_hTarget = hTargetDevice; + } + + /// Initializes a new instance of the struct. + /// The device instance ID for the device for which to receive notifications. + public CM_NOTIFY_FILTER(string deviceInstanceId) : this() + { + cbSize = (uint)Marshal.SizeOf(typeof(CM_NOTIFY_FILTER)); + FilterType = CM_NOTIFY_FILTER_TYPE.CM_NOTIFY_FILTER_TYPE_DEVICEINTERFACE; + u.DeviceInstance_InstanceId = deviceInstanceId; + } + + /// The size of the structure. + public uint cbSize; + + /// + /// A combination of zero or more of the following flags: + /// CM_NOTIFY_FILTER_FLAG_ALL_INTERFACE_CLASSES + /// + /// Register to receive notifications for PnP events for all device interface classes. The memory at + /// pFilter->u.DeviceInterface.ClassGuid must be zeroes. Do not use this flag with + /// CM_NOTIFY_FILTER_FLAG_ALL_DEVICE_INSTANCES. This flag is only valid if pFilter->FilterType is CM_NOTIFY_FILTER_TYPE_DEVICEINTERFACE. + /// + /// CM_NOTIFY_FILTER_FLAG_ALL_DEVICE_INSTANCES + /// + /// Register to receive notifications for PnP events for all devices. pFilter->u.DeviceInstance.InstanceId must be an + /// empty string. Do not use this flag with CM_NOTIFY_FILTER_FLAG_ALL_INTERFACE_CLASSES. This flag is only valid if + /// pFilter->FilterType is CM_NOTIFY_FILTER_TYPE_DEVICEINSTANCE. + /// + /// + public CM_NOTIFY_FILTER_FLAG Flags; + + /// + /// Must be one of the following values: + /// CM_NOTIFY_FILTER_TYPE_DEVICEINTERFACE + /// + /// Register for notifications for device interface events. pFilter->u.DeviceInterface.ClassGuid should be filled in + /// with the GUID of the device interface class to receive notifications for. + /// + /// CM_NOTIFY_FILTER_TYPE_DEVICEHANDLE + /// + /// Register for notifications for device handle events. pFilter->u.DeviceHandle.hTarget must be filled in with a + /// handle to the device to receive notifications for. + /// + /// CM_NOTIFY_FILTER_TYPE_DEVICEINSTANCE + /// + /// Register for notifications for device instance events. pFilter->u.DeviceInstance.InstanceId should be filled in + /// with the device instance ID of the device to receive notifications for. + /// + /// + public CM_NOTIFY_FILTER_TYPE FilterType; + + /// Set to 0. + public uint Reserved; + + /// A union that contains information about the device to receive notifications for. + public UNION u; + + /// Gets an instance of this structure set to filter all devices. + public static readonly CM_NOTIFY_FILTER AllDevices = new() + { + cbSize = (uint)Marshal.SizeOf(typeof(CM_NOTIFY_FILTER)), + Flags = CM_NOTIFY_FILTER_FLAG.CM_NOTIFY_FILTER_FLAG_ALL_DEVICE_INSTANCES, + FilterType = CM_NOTIFY_FILTER_TYPE.CM_NOTIFY_FILTER_TYPE_DEVICEINSTANCE + }; + + /// Gets an instance of this structure set to filter all device interface classes. + public static readonly CM_NOTIFY_FILTER AllInterfaces = new() + { + cbSize = (uint)Marshal.SizeOf(typeof(CM_NOTIFY_FILTER)), + Flags = CM_NOTIFY_FILTER_FLAG.CM_NOTIFY_FILTER_FLAG_ALL_INTERFACE_CLASSES, + FilterType = CM_NOTIFY_FILTER_TYPE.CM_NOTIFY_FILTER_TYPE_DEVICEINTERFACE + }; + + /// A union that contains information about the device to receive notifications for. + [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode)] + public unsafe struct UNION + { + /// The GUID of the device interface class for which to receive notifications. + [FieldOffset(0)] + public Guid DeviceInterface_ClassGuid; + + /// A handle to the device for which to receive notifications. + [FieldOffset(0)] + public IntPtr DeviceHandle_hTarget; + + [FieldOffset(0)] + private fixed char iid[MAX_DEVICE_ID_LEN]; + + /// The device instance ID for the device for which to receive notifications. + public string DeviceInstance_InstanceId + { + get + { + fixed (char* p = iid) + return new string(p); + } + set + { + if (value is null) throw new ArgumentNullException(nameof(DeviceInstance_InstanceId)); + if (value.Length >= MAX_DEVICE_ID_LEN) throw new ArgumentException($"String length exceeds maximum of {MAX_DEVICE_ID_LEN - 1} characters.", nameof(DeviceInstance_InstanceId)); + for (int i = 0; i < value.Length; i++) + iid[i] = value[i]; + iid[value.Length] = '\0'; + } + } + } + } + + /// The CONFLICT_DETAILS structure is used as a parameter to the CM_Get_Resource_Conflict_Details function. + /// + /// Note + /// + /// The cfgmgr32.h header defines CONFLICT_DETAILS as an alias which automatically selects the ANSI or Unicode version of this + /// function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that + /// not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions + /// for Function Prototypes. + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/ns-cfgmgr32-conflict_details_a typedef struct _CONFLICT_DETAILS_A { + // ULONG CD_ulSize; ULONG CD_ulMask; DEVINST CD_dnDevInst; RES_DES CD_rdResDes; ULONG CD_ulFlags; CHAR CD_szDescription[MAX_PATH]; } + // CONFLICT_DETAILS_A, *PCONFLICT_DETAILS_A; + [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32._CONFLICT_DETAILS_A")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + public struct CONFLICT_DETAILS + { + /// Size, in bytes, of the CONFLICT_DETAILS structure. + public uint CD_ulSize; + + /// + /// + /// One or more bit flags supplied by the caller of CM_Get_Resource_Conflict_Details. The bit flags are described in the + /// following table. + /// + /// + /// + /// Flag + /// Description + /// + /// + /// CM_CDMASK_DEVINST + /// If set, CM_Get_Resource_Conflict_Details supplies a value for the CD_dnDevInst member. + /// + /// + /// CM_CDMASK_RESDES + /// Not used. + /// + /// + /// CM_CDMASK_FLAGS + /// If set, CM_Get_Resource_Conflict_Details supplies a value for the CD_ulFlags member. + /// + /// + /// CM_CDMASK_DESCRIPTION + /// If set, CM_Get_Resource_Conflict_Details supplies a value for the CD_szDescription member. + /// + /// + /// + public CM_CDMASK CD_ulMask; + + /// + /// If CM_CDMASK_DEVINST is set in CD_ulMask, this member will receive a handle to a device instance that has conflicting + /// resources. If a handle is not obtainable, the member receives -1. + /// + public uint CD_dnDevInst; + + /// Not used. + public RES_DES CD_rdResDes; + + /// + /// If CM_CDMASK_FLAGS is set in CD_ulMask, this member can receive bit flags listed in the following table. + /// + /// + /// Flag + /// Description + /// + /// + /// CM_CDFLAGS_DRIVER + /// + /// If set, the string contained in the CD_szDescription member represents a driver name instead of a device name, and + /// CD_dnDevInst is -1. + /// + /// + /// + /// CM_CDFLAGS_ROOT_OWNED + /// If set, the conflicting resources are owned by the root device (that is, the HAL), and CD_dnDevInst is -1. + /// + /// + /// CM_CDFLAGS_RESERVED + /// If set, the owner of the conflicting resources cannot be determined, and CD_dnDevInst is -1. + /// + /// + /// + public CM_CDFLAGS CD_ulFlags; + + /// + /// If CM_CDMASK_DESCRIPTION is set in CD_ulMask, this member will receive a NULL-terminated text string representing a + /// description of the device that owns the resources. If CM_CDFLAGS_DRIVER is set in CD_ulFlags, this string represents + /// a driver name. If CM_CDFLAGS_ROOT_OWNED or CM_CDFLAGS_RESERVED is set, the string value is NULL. + /// + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260 /*MAX_PATH*/)] + public string CD_szDescription; + + /// Gets a default value for the structure with the size field set. + public static readonly CONFLICT_DETAILS Default = new() { CD_ulSize = (uint)Marshal.SizeOf(typeof(CONFLICT_DETAILS)) }; + } + + /// + /// The CS_DES structure is used for specifying a resource list that describes device class-specific resource usage for a device + /// instance. For more information about resource lists, see Hardware Resources. + /// + /// + /// + /// The data block identified by CSD_LegacyDataSize and CSD_LegacyDataOffset can contain legacy, class-specific data, + /// as stored in the DeviceSpecificData member of a CM_PARTIAL_RESOURCE_DESCRIPTOR structure, if the structure's Type + /// member is CmResourceTypeDeviceSpecific. + /// + /// + /// The class-specific signature identified by CSD_SignatureLength and CSD_Signature can contain additional + /// class-specific device identification information. + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/ns-cfgmgr32-cs_des typedef struct CS_Des_s { DWORD + // CSD_SignatureLength; DWORD CSD_LegacyDataOffset; DWORD CSD_LegacyDataSize; DWORD CSD_Flags; GUID CSD_ClassGuid; BYTE + // CSD_Signature[ANYSIZE_ARRAY]; } CS_DES, *PCS_DES; + [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32.CS_Des_s")] + [VanaraMarshaler(typeof(SafeAnysizeStructMarshaler), nameof(CSD_SignatureLength))] + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public struct CS_DES + { + /// The number of elements in the byte array specified by CSD_Signature. + public uint CSD_SignatureLength; + + /// + /// Offset, in bytes, from the beginning of the CSD_Signature array to the beginning of a block of data. For example, if + /// the data block follows the signature array, and if the signature array length is 16 bytes, then the value for + /// CSD_LegacyDataOffset should be 16. + /// + public uint CSD_LegacyDataOffset; + + /// Length, in bytes, of the data block whose offset is specified by CSD_LegacyDataOffset. + public uint CSD_LegacyDataSize; + + /// Not used. + public uint CSD_Flags; + + /// + /// A globally unique identifier (GUID) identifying a device setup class. If both CSD_SignatureLength and + /// CSD_LegacyDataSize are zero, the GUID is null. + /// + public Guid CSD_ClassGuid; + + /// A byte array containing a class-specific signature. + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] + public byte[] CSD_Signature; + } + + /// + /// The CS_RESOURCE structure is used for specifying a resource list that describes device class-specific resource usage for a + /// device instance. For more information about resource lists, see Hardware Resources. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/ns-cfgmgr32-cs_resource typedef struct CS_Resource_s { CS_DES + // CS_Header; } CS_RESOURCE, *PCS_RESOURCE; + [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32.CS_Resource_s")] + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public struct CS_RESOURCE + { + /// A CS_DES structure. + public CS_DES CS_Header; + } + + /// + /// The DMA_DES structure is used for specifying either a resource list or a resource requirements list that describes direct memory + /// access (DMA) channel usage for a device instance. For more information about resource lists and resource requirements lists, see + /// Hardware Resources. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/ns-cfgmgr32-dma_des typedef struct DMA_Des_s { DWORD DD_Count; DWORD + // DD_Type; DWORD DD_Flags; ULONG DD_Alloc_Chan; } DMA_DES, *PDMA_DES; + [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32.DMA_Des_s")] + [StructLayout(LayoutKind.Sequential)] + public struct DMA_DES + { + /// + /// For a resource list: + /// Zero. + /// For a resource requirements list: + /// The number of elements in the DMA_RESOURCE structure. + /// + public uint DD_Count; + + /// Must be set to the constant value DType_Range. + public uint DD_Type; + + /// + /// One bit flag from each of the flag sets described in the following table. + /// + /// + /// + /// Flag + /// Definition + /// + /// + /// Channel Width Flags + /// + /// + /// + /// + /// fDD_BYTE + /// 8-bit DMA channel. + /// + /// + /// + /// fDD_WORD + /// 16-bit DMA channel. + /// + /// + /// + /// fDD_DWORD + /// 32-bit DMA channel. + /// + /// + /// + /// fDD_BYTE_AND_WORD + /// 8-bit and 16-bit DMA channel. + /// + /// + /// + /// mDD_Width + /// Bitmask for the bits within DD_Flags that specify the channel width value. + /// + /// + /// Bus Mastering Flags + /// + /// + /// + /// + /// fDD_NoBusMaster + /// No bus mastering. + /// + /// + /// + /// fDD_BusMaster + /// Bus mastering. + /// + /// + /// + /// mDD_BusMaster + /// Bitmask for the bits within DD_Flags that specify the bus mastering value. + /// + /// + /// DMA Type Flags + /// + /// + /// + /// + /// fDD_TypeStandard + /// Standard DMA. + /// + /// + /// + /// fDD_TypeA + /// Type A DMA. + /// + /// + /// + /// fDD_TypeB + /// Type B DMA. + /// + /// + /// + /// fDD_TypeF + /// Type F DMA. + /// + /// + /// + /// mDD_Type + /// Bitmask for the bits within DD_Flags that specify the DMA type value. + /// + /// + /// + public DMA_DES_FLAGS DD_Flags; + + /// + /// For a resource list: + /// The DMA channel allocated to the device. + /// For a resource requirements list: + /// Not used. + /// + public uint DD_Alloc_Chan; + } + + /// + /// The DMA_RANGE structure specifies a resource requirements list that describes DMA channel usage for a device instance. For more + /// information about resource requirements lists, see Hardware Resources. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/ns-cfgmgr32-dma_range typedef struct DMA_Range_s { ULONG DR_Min; + // ULONG DR_Max; ULONG DR_Flags; } DMA_RANGE, *PDMA_RANGE; + [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32.DMA_Range_s")] + [StructLayout(LayoutKind.Sequential)] + public struct DMA_RANGE + { + /// The lowest-numbered DMA channel that can be allocated to the device. + public uint DR_Min; + + /// The highest-numbered DMA channel that can be allocated to the device. + public uint DR_Max; + + /// One bit flag from DMA_DES structure. + public uint DR_Flags; + } + + /// + /// The DMA_RESOURCE structure is used for specifying either a resource list or a resource requirements list that describes DMA + /// channel usage for a device instance. For more information about resource list and resource requirements lists, see Hardware Resources. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/ns-cfgmgr32-dma_resource typedef struct DMA_Resource_s { DMA_DES + // DMA_Header; DMA_RANGE DMA_Data[ANYSIZE_ARRAY]; } DMA_RESOURCE, *PDMA_RESOURCE; + [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32.DMA_Resource_s")] + [VanaraMarshaler(typeof(SafeAnysizeStructMarshaler), "*")] + [StructLayout(LayoutKind.Sequential)] + public struct DMA_RESOURCE + { + /// A DMA_DES structure. + public DMA_DES DMA_Header; + + /// + /// For a resource list: + /// Zero. + /// For a resource requirements list: + /// A DMA_RANGE array. + /// + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] + public DMA_RANGE[] DMA_Data; + } + + /// + /// The IO_DES structure is used for specifying either a resource list or a resource requirements list that describes I/O port usage + /// for a device instance. For more information about resource lists and resource requirements lists, see Hardware Resources. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/ns-cfgmgr32-io_des typedef struct IO_Des_s { DWORD IOD_Count; DWORD + // IOD_Type; DWORDLONG IOD_Alloc_Base; DWORDLONG IOD_Alloc_End; DWORD IOD_DesFlags; } IO_DES, *PIO_DES; + [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32.IO_Des_s")] + [StructLayout(LayoutKind.Sequential, Pack = 4)] + public struct IO_DES + { + /// + /// For a resource list: + /// Zero. + /// For a resource requirements list: + /// The number of elements in the IO_RANGE array that is included in the IO_RESOURCE structure. + /// + public uint IOD_Count; + + /// Must be set to the constant value IOType_Range. + public uint IOD_Type; + + /// + /// For a resource list: + /// The lowest-numbered of a range of contiguous I/O port addresses allocated to the device. + /// For a resource requirements list: + /// Zero. + /// + public ulong IOD_Alloc_Base; + + /// + /// For a resource list: + /// The highest-numbered of a range of contiguous I/O port addresses allocated to the device. + /// For a resource requirements list: + /// Zero. + /// + public ulong IOD_Alloc_End; + + /// + /// One bit flag from each of the flag sets described in the following table. + /// + /// + /// + /// Flag + /// Definition + /// + /// + /// Port Type Flags + /// + /// + /// + /// + /// fIOD_IO + /// The device is accessed in I/O address space. + /// + /// + /// + /// fIOD_Memory + /// The device is accessed in memory address space. + /// + /// + /// + /// fIOD_PortType + /// Bitmask for the bits within IOD_DesFlags that specify the port type value. + /// + /// + /// Decode Flags + /// + /// + /// + /// + /// fIOD_10_BIT_DECODE + /// The device decodes 10 bits of the port address. + /// + /// + /// + /// fIOD_12_BIT_DECODE + /// The device decodes 12 bits of the port address. + /// + /// + /// + /// fIOD_16_BIT_DECODE + /// The device decodes 16 bits of the port address. + /// + /// + /// + /// fIOD_POSITIVE_DECODE + /// The device uses "positive decode" instead of "subtractive decode." + /// + /// + /// + /// fIOD_DECODE + /// Bitmask for the bits within IOD_DesFlags that specify the decode value. + /// + /// + /// + public IO_DES_FLAGS IOD_DesFlags; + } + + /// + /// The IO_RANGE structure specifies a resource requirements list that describes I/O port usage for a device instance. For more + /// information about resource requirements lists, see Hardware Resources. + /// + /// + /// The flags specified for IOR_Alias have the same interpretation as the address decoding flags specified for + /// IOD_DesFlags. (However, the two sets of flags are not equivalent in assigned values and cannot be used interchangeably.) + /// A resource requirements list can be specified using either set of flags, but using decode flags in IOD_DesFlags is + /// recommended. If address decoding flags are specified using both IOD_DesFlags and IOR_Alias, contents of the latter + /// overrides the former. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/ns-cfgmgr32-io_range typedef struct IO_Range_s { DWORDLONG IOR_Align; + // DWORD IOR_nPorts; DWORDLONG IOR_Min; DWORDLONG IOR_Max; DWORD IOR_RangeFlags; DWORDLONG IOR_Alias; } IO_RANGE, *PIO_RANGE; + [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32.IO_Range_s")] + [StructLayout(LayoutKind.Sequential, Pack = 4)] + public struct IO_RANGE + { + /// Mask used to specify the port address boundary on which the first allocated I/O port address must be aligned. + public ulong IOR_Align; + + /// The number of I/O port addresses required by the device. + public uint IOR_nPorts; + + /// The lowest-numbered of a range of contiguous I/O port addresses that can be allocated to the device. + public ulong IOR_Min; + + /// The highest-numbered of a range of contiguous I/O port addresses that can be allocated to the device. + public ulong IOR_Max; + + /// One bit flag from IO_DES structure. For more information, see the following Remarks section. + public uint IOR_RangeFlags; + + /// + /// One of the bit flags described in the following table. + /// + /// + /// Flag + /// Definition + /// + /// + /// IO_ALIAS_10_BIT_DECODE + /// The device decodes 10 bits of the port address. + /// + /// + /// IO_ALIAS_12_BIT_DECODE + /// The device decodes 12 bits of the port address. + /// + /// + /// IO_ALIAS_16_BIT_DECODE + /// The device decodes 16 bits of the port address. + /// + /// + /// IO_ALIAS_POSITIVE_DECODE + /// The device uses "positive decode" instead of "subtractive decode." + /// + /// + /// For more information, see the following Remarks section. + /// + public ulong IOR_Alias; + } + + /// + /// The IO_RESOURCE structure is used for specifying either a resource list or a resource requirements list that describes I/O port + /// usage for a device instance. For more information about resource lists and resource requirements lists, see Hardware Resources. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/ns-cfgmgr32-io_resource typedef struct IO_Resource_s { IO_DES + // IO_Header; IO_RANGE IO_Data[ANYSIZE_ARRAY]; } IO_RESOURCE, *PIO_RESOURCE; + [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32.IO_Resource_s")] + [VanaraMarshaler(typeof(SafeAnysizeStructMarshaler), "*")] + [StructLayout(LayoutKind.Sequential, Pack = 4)] + public struct IO_RESOURCE + { + /// An IO_DES structure. + public IO_DES IO_Header; + + /// + /// For a resource list: + /// Zero. + /// For a resource requirements list: + /// An IO_RANGE array. + /// + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] + public IO_RANGE[] IO_Data; + } + + /// + /// The IRQ_DES structure is used for specifying either a resource list or a resource requirements list that describes IRQ line + /// usage for a device instance. For more information about resource lists and resource requirements lists, see Hardware Resources. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/ns-cfgmgr32-irq_des_32 typedef struct IRQ_Des_32_s { DWORD + // IRQD_Count; DWORD IRQD_Type; #if ... USHORT IRQD_Flags; USHORT IRQD_Group; #else DWORD IRQD_Flags; #endif ULONG IRQD_Alloc_Num; + // ULONG32 IRQD_Affinity; } IRQ_DES_32, *PIRQ_DES_32; + [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32.IRQ_Des_32_s")] + [StructLayout(LayoutKind.Sequential)] + public struct IRQ_DES_32 + { + /// + /// For a resource list: + /// Zero. + /// For a resource requirements list: + /// The number of elements in the IRQ_RANGE array that is included in the IRQ_RESOURCE structure. + /// + public uint IRQD_Count; + + /// Must be set to the constant value IRQType_Range. + public uint IRQD_Type; + + /// + /// One bit flag from each of the flag sets described in the following table. + /// + /// + /// + /// Flag + /// Definition + /// + /// + /// Sharing Flags + /// + /// + /// + /// + /// fIRQD_Exclusive + /// The IRQ line cannot be shared. + /// + /// + /// + /// fIRQD_Share + /// The IRQ line can be shared. + /// + /// + /// + /// mIRQD_Share + /// Bitmask for the bits within IRQD_Flags that specify the sharing value. + /// + /// + /// Triggering Flags + /// + /// + /// + /// + /// fIRQD_Level + /// The IRQ line is level-triggered. + /// + /// + /// + /// fIRQD_Edge + /// The IRQ line is edge-triggered. + /// + /// + /// + /// mIRQD_Edge_Level + /// Bitmask for the bits within IRQD_Flags that specify the triggering value. + /// + /// + /// + public IRQD_FLAGS IRQD_Flags; + + /// Group number of interrupt target. + public ushort IRQD_Group; + + /// + /// For a resource list: + /// The number of the IRQ line that is allocated to the device. + /// For a resource requirements list: + /// Not used. + /// + public uint IRQD_Alloc_Num; + + /// + /// For a resource list: + /// + /// A bitmask representing the processor affinity of the IRQ line that is allocated to the device. Bit zero represents the first + /// processor, bit two the second, and so on. Set this value to -1 to represent all processors. + /// + /// For a resource requirements list: + /// Not used. + /// + public uint IRQD_Affinity; + } + + /// + /// The IRQ_DES structure is used for specifying either a resource list or a resource requirements list that describes IRQ line + /// usage for a device instance. For more information about resource lists and resource requirements lists, see Hardware Resources. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/ns-cfgmgr32-irq_des_64 typedef struct IRQ_Des_64_s { DWORD + // IRQD_Count; DWORD IRQD_Type; #if ... USHORT IRQD_Flags; USHORT IRQD_Group; #else DWORD IRQD_Flags; #endif ULONG IRQD_Alloc_Num; + // ULONG64 IRQD_Affinity; } IRQ_DES_64, *PIRQ_DES_64; + [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32.IRQ_Des_64_s")] + [StructLayout(LayoutKind.Sequential)] + public struct IRQ_DES_64 + { + /// + /// For a resource list: + /// Zero. + /// For a resource requirements list: + /// The number of elements in the IRQ_RESOURCE structure. + /// + public uint IRQD_Count; + + /// Must be set to the constant value IRQType_Range. + public uint IRQD_Type; + + /// + /// One bit flag from each of the flag sets described in the following table. + /// + /// + /// + /// Flag + /// Definition + /// + /// + /// Sharing Flags + /// + /// + /// + /// + /// fIRQD_Exclusive + /// The IRQ line cannot be shared. + /// + /// + /// + /// fIRQD_Share + /// The IRQ line can be shared. + /// + /// + /// + /// mIRQD_Share + /// Bitmask for the bits within IRQD_Flags that specify the sharing value. + /// + /// + /// Triggering Flags + /// + /// + /// + /// + /// fIRQD_Level + /// The IRQ line is level-triggered. + /// + /// + /// + /// fIRQD_Edge + /// The IRQ line is edge-triggered. + /// + /// + /// + /// mIRQD_Edge_Level + /// Bitmask for the bits within IRQD_Flags that specify the triggering value. + /// + /// + /// + public IRQD_FLAGS IRQD_Flags; + + /// Group number of interrupt target. + public ushort IRQD_Group; + + /// + /// For a resource list: + /// The number of the IRQ line that is allocated to the device. + /// For a resource requirements list: + /// Not used. + /// + public uint IRQD_Alloc_Num; + + /// + /// For a resource list: + /// + /// A bitmask representing the processor affinity of the IRQ line that is allocated to the device. Bit zero represents the first + /// processor, bit two the second, and so on. Set this value to -1 to represent all processors. + /// + /// For a resource requirements list: + /// Not used. + /// + public ulong IRQD_Affinity; + } + + /// + /// The IRQ_RANGE structure specifies a resource requirements list that describes IRQ line usage for a device instance. For more + /// information about resource requirements lists, see Hardware Resources. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/ns-cfgmgr32-irq_range typedef struct IRQ_Range_s { ULONG IRQR_Min; + // ULONG IRQR_Max; #if ... USHORT IRQR_Flags; USHORT IRQR_Rsvdz; #else ULONG IRQR_Flags; #endif } IRQ_RANGE, *PIRQ_RANGE; + [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32.IRQ_Range_s")] + [StructLayout(LayoutKind.Sequential)] + public struct IRQ_RANGE + { + /// The lowest-numbered of a range of contiguous IRQ lines that can be allocated to the device. + public uint IRQR_Min; + + /// The highest-numbered of a range of contiguous IRQ lines that can be allocated to the device. + public uint IRQR_Max; + + /// One bit flag from IRQ_DES structure. + public IRQD_FLAGS IRQR_Flags; + + /// + public ushort IRQR_Rsvdz; + } + + /// + /// The IRQ_RESOURCE structure is used for specifying either a resource list or a resource requirements list that describes IRQ line + /// usage for a device instance. For more information about resource lists and resource requirements lists, see Hardware Resources. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/ns-cfgmgr32-irq_resource_32 typedef struct IRQ_Resource_32_s { + // IRQ_DES_32 IRQ_Header; IRQ_RANGE IRQ_Data[ANYSIZE_ARRAY]; } IRQ_RESOURCE_32, *PIRQ_RESOURCE_32; + [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32.IRQ_Resource_32_s")] + [VanaraMarshaler(typeof(SafeAnysizeStructMarshaler), "*")] + [StructLayout(LayoutKind.Sequential)] + public struct IRQ_RESOURCE_32 + { + /// An IRQ_DES structure. + public IRQ_DES_32 IRQ_Header; + + /// + /// For a resource list: + /// Zero. + /// For a resource requirements list: + /// An IRQ_RANGE array. + /// + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] + public IRQ_RANGE[] IRQ_Data; + } + + /// + /// The IRQ_RESOURCE structure is used for specifying either a resource list or a resource requirements list that describes IRQ line + /// usage for a device instance. For more information about resource lists and resource requirements lists, see Hardware Resources. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/ns-cfgmgr32-irq_resource_64 typedef struct IRQ_Resource_64_s { + // IRQ_DES_64 IRQ_Header; IRQ_RANGE IRQ_Data[ANYSIZE_ARRAY]; } IRQ_RESOURCE_64, *PIRQ_RESOURCE_64; + [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32.IRQ_Resource_64_s")] + [VanaraMarshaler(typeof(SafeAnysizeStructMarshaler), "*")] + [StructLayout(LayoutKind.Sequential, Pack = 4)] + public struct IRQ_RESOURCE_64 + { + /// An IRQ_DES structure. + public IRQ_DES_64 IRQ_Header; + + /// + /// For a resource list: + /// Zero. + /// For a resource requirements list: + /// An IRQ_RANGE array. + /// + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] + public IRQ_RANGE[] IRQ_Data; + } + + /// + /// The MEM_DES structure is used for specifying either a resource list or a resource requirements list that describes memory usage + /// for a device instance. For more information about resource lists and resource requirements lists, see Hardware Resources. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/ns-cfgmgr32-mem_des typedef struct Mem_Des_s { DWORD MD_Count; DWORD + // MD_Type; DWORDLONG MD_Alloc_Base; DWORDLONG MD_Alloc_End; DWORD MD_Flags; DWORD MD_Reserved; } MEM_DES, *PMEM_DES; + [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32.Mem_Des_s")] + [StructLayout(LayoutKind.Sequential)] + public struct MEM_DES + { + /// + /// For a resource list: + /// Zero. + /// For a resource requirements list: + /// The number of elements in the MEM_RANGE array that is included in the MEM_RESOURCE structure. + /// + public uint MD_Count; + + /// Must be set to the constant value MType_Range. + public uint MD_Type; + + /// + /// For a resource list: + /// The lowest-numbered of a range of contiguous physical memory addresses allocated to the device. + /// For a resource requirements list: + /// Zero. + /// + public ulong MD_Alloc_Base; + + /// + /// For a resource list: + /// The highest-numbered of a range of contiguous physical memory addresses allocated to the device. + /// For a resource requirements list: + /// Zero. + /// + public ulong MD_Alloc_End; + + /// + /// One bit flag from each of the flag sets described in the following table. + /// + /// + /// + /// Flag + /// Definition + /// + /// + /// Read-Only Flags + /// + /// + /// + /// + /// fMD_ROM + /// The specified memory range is read-only. + /// + /// + /// + /// fMD_RAM + /// The specified memory range is not read-only. + /// + /// + /// + /// mMD_MemoryType + /// Bitmask for the bit within MD_Flags that specifies the read-only attribute. + /// + /// + /// Write-Only Flags + /// + /// + /// + /// + /// fMD_ReadDisallowed + /// The specified memory range is write-only. + /// + /// + /// + /// fMD_ReadAllowed + /// The specified memory range is not write-only. + /// + /// + /// + /// mMD_Readable + /// Bitmask for the bit within MD_Flags that specifies the write-only attribute. + /// + /// + /// Address Size Flags + /// + /// + /// + /// + /// fMD_24 + /// 24-bit addressing (not used). + /// + /// + /// + /// fMD_32 + /// 32-bit addressing. + /// + /// + /// + /// mMD_32_24 + /// Bitmask for the bit within MD_Flags that specifies the address size. + /// + /// + /// Prefetch Flags + /// + /// + /// + /// + /// fMD_PrefetchAllowed + /// The specified memory range can be prefetched. + /// + /// + /// + /// fMD_PrefetchDisallowed + /// The specified memory range cannot be prefetched. + /// + /// + /// + /// mMD_Prefetchable + /// Bitmask for the bit within MD_Flags that specifies the prefetch ability. + /// + /// + /// Caching Flags + /// + /// + /// + /// + /// fMD_Cacheable + /// The specified memory range can be cached. + /// + /// + /// + /// fMD_NonCacheable + /// The specified memory range cannot be cached. + /// + /// + /// + /// mMD_Cacheable + /// Bitmask for the bit within MD_Flags that specifies the caching ability. + /// + /// + /// Combined-Write Caching Flags + /// + /// + /// + /// + /// fMD_CombinedWriteAllowed + /// Combined-write caching is allowed. + /// + /// + /// + /// fMD_CombinedWriteDisallowed + /// Combined-write caching is not allowed. + /// + /// + /// + /// mMD_CombinedWrite + /// Bitmask for the bit within MD_Flags that specifies the combine-write caching ability. + /// + /// + /// + public MEM_DES_FLAGS MD_Flags; + + /// For internal use only. + public uint MD_Reserved; + } + + /// + /// The MEM_RANGE structure specifies a resource requirements list that describes memory usage for a device instance. For more + /// information about resource requirements lists, see Hardware Resources. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/ns-cfgmgr32-mem_range typedef struct Mem_Range_s { DWORDLONG + // MR_Align; ULONG MR_nBytes; DWORDLONG MR_Min; DWORDLONG MR_Max; DWORD MR_Flags; DWORD MR_Reserved; } MEM_RANGE, *PMEM_RANGE; + [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32.Mem_Range_s")] + [StructLayout(LayoutKind.Sequential, Pack = 4)] + public struct MEM_RANGE + { + /// Mask used to specify the memory address boundary on which the first allocated memory address must be aligned. + public ulong MR_Align; + + /// The number of bytes of memory required by the device. + public uint MR_nBytes; + + /// The lowest-numbered of a range of contiguous memory addresses that can be allocated to the device. + public ulong MR_Min; + + /// The highest-numbered of a range of contiguous memory addresses that can be allocated to the device. + public ulong MR_Max; + + /// One bit flag from MEM_DES structure. + public MEM_DES_FLAGS MR_Flags; + + /// For internal use only. + public uint MR_Reserved; + } + + /// + /// The MEM_RESOURCE structure is used for specifying either a resource list or a resource requirements list that describes memory + /// usage for a device instance. For more information about resource lists and resource requirements lists, see Hardware Resources. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/ns-cfgmgr32-mem_resource typedef struct Mem_Resource_s { MEM_DES + // MEM_Header; MEM_RANGE MEM_Data[ANYSIZE_ARRAY]; } MEM_RESOURCE, *PMEM_RESOURCE; + [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32.Mem_Resource_s")] + [VanaraMarshaler(typeof(SafeAnysizeStructMarshaler), "*")] + [StructLayout(LayoutKind.Sequential, Pack = 4)] + public struct MEM_RESOURCE + { + /// A MEM_DES structure. + public MEM_DES MEM_Header; + + /// + /// For a resource list: + /// Zero. + /// For a resource requirements list: + /// A MEM_RANGE array. + /// + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] + public MEM_RANGE[] MEM_Data; + } + + /// + /// The MFCARD_DES structure is used for specifying either a resource list or a resource requirements list that describes resource + /// usage by one of the hardware functions provided by an instance of a multifunction device. For more information about resource + /// lists and resource requirements lists, see Hardware Resources. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/ns-cfgmgr32-mfcard_des typedef struct MfCard_Des_s { DWORD PMF_Count; + // DWORD PMF_Type; DWORD PMF_Flags; BYTE PMF_ConfigOptions; BYTE PMF_IoResourceIndex; BYTE PMF_Reserved[2]; DWORD + // PMF_ConfigRegisterBase; } MFCARD_DES, *PMFCARD_DES; + [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32.MfCard_Des_s")] + [StructLayout(LayoutKind.Sequential)] + public struct MFCARD_DES + { + /// Must be 1. + public uint PMF_Count; + + /// Not used. + public uint PMF_Type; + + /// + /// One bit flag is defined, as described in the following table. + /// + /// + /// Flag + /// Definition + /// + /// + /// fPMF_AUDIO_ENABLE + /// If set, audio is enabled. + /// + /// + /// + public uint PMF_Flags; + + /// Contents of the 8-bit PCMCIA Configuration Option Register. + public byte PMF_ConfigOptions; + + /// + /// Zero-based index indicating the IO_RESOURCE structure that describes the I/O resources for the hardware function being + /// described by this MFCARD_DES structure. + /// + public byte PMF_IoResourceIndex; + + /// Not used. + public ushort PMF_Reserved; + + /// Offset from the beginning of the card's attribute memory space to the base configuration register address. + public uint PMF_ConfigRegisterBase; + } + + /// + /// The MFCARD_RESOURCE structure is used for specifying either a resource list or a resource requirements list that describes + /// resource usage by one of the hardware functions provided by an instance of a multifunction device. For more information about + /// resource lists and resource requirements lists, see Hardware Resources. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/ns-cfgmgr32-mfcard_resource typedef struct MfCard_Resource_s { + // MFCARD_DES MfCard_Header; } MFCARD_RESOURCE, *PMFCARD_RESOURCE; + [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32.MfCard_Resource_s")] + [StructLayout(LayoutKind.Sequential)] + public struct MFCARD_RESOURCE + { + /// A MFCARD_DES structure. + public MFCARD_DES MfCard_Header; + } + + /// + /// The PCCARD_DES structure is used for specifying either a resource list or a resource requirements list that describes resource + /// usage by a PC Card instance. For more information about resource lists and resource requirements lists, see Hardware Resources. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/ns-cfgmgr32-pccard_des typedef struct PcCard_Des_s { DWORD PCD_Count; + // DWORD PCD_Type; DWORD PCD_Flags; BYTE PCD_ConfigIndex; BYTE PCD_Reserved[3]; DWORD PCD_MemoryCardBase1; DWORD + // PCD_MemoryCardBase2; DWORD PCD_MemoryCardBase[PCD_MAX_MEMORY]; WORD PCD_MemoryFlags[PCD_MAX_MEMORY]; BYTE + // PCD_IoFlags[PCD_MAX_IO]; } PCCARD_DES, *PPCCARD_DES; + [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32.PcCard_Des_s")] + [StructLayout(LayoutKind.Sequential, Pack = 2)] + public struct PCCARD_DES + { + private const int PCD_MAX_MEMORY = 2; + private const int PCD_MAX_IO = 2; + + /// Must be 1. + public uint PCD_Count; + + /// Not used. + public uint PCD_Type; + + /// + /// One bit flag from each of the flag sets described in the following table. + /// + /// + /// + /// Flag + /// Definition + /// + /// + /// I/O Addressing Flags + /// + /// + /// + /// + /// fPCD_IO_8 + /// The device uses 8-bit I/O addressing. + /// + /// + /// + /// fPCD_IO_16 + /// The device uses 16-bit I/O addressing. + /// + /// + /// + /// mPCD_IO_8_16 + /// Bitmask for the bit within PCD_Flags that specifies 8-bit or 16-bit I/O addressing. + /// + /// + /// Memory Addressing Flags + /// + /// + /// + /// + /// fPCD_MEM_8 + /// The device uses 8-bit memory addressing. + /// + /// + /// + /// fPCD_MEM_16 + /// The device uses 16-bit memory addressing. + /// + /// + /// + /// mPCD_MEM_8_16 + /// Bitmask for the bit within PCD_Flags that specifies 8-bit or 16-bit memory addressing. + /// + /// + /// + public PCD_FLAGS PCD_Flags; + + /// The 8-bit index value used to locate the device's configuration. + public byte PCD_ConfigIndex; + + /// Not used. + public byte PCD_Reserved1; + + /// Not used. + public ushort PCD_Reserved2; + + /// Optional, card base address of the first memory window. + public uint PCD_MemoryCardBase1; + + /// Optional, card base address of the second memory window. + public uint PCD_MemoryCardBase2; + + /// This member is currently unused. + [MarshalAs(UnmanagedType.ByValArray, SizeConst = PCD_MAX_MEMORY)] + public uint[] PCD_MemoryCardBase; + + /// This member is currently unused. + [MarshalAs(UnmanagedType.ByValArray, SizeConst = PCD_MAX_MEMORY)] + public ushort[] PCD_MemoryFlags; + + /// This member is currently unused. + [MarshalAs(UnmanagedType.ByValArray, SizeConst = PCD_MAX_IO)] + public byte[] PCD_IoFlags; + } + + /// + /// The PCCARD_RESOURCE structure is used for specifying either a resource list or a resource requirements list that describes + /// resource usage by a PC Card instance. For more information about resource lists and resource requirements lists, see Hardware Resources. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/ns-cfgmgr32-pccard_resource typedef struct PcCard_Resource_s { + // PCCARD_DES PcCard_Header; } PCCARD_RESOURCE, *PPCCARD_RESOURCE; + [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32.PcCard_Resource_s")] + [StructLayout(LayoutKind.Sequential, Pack = 2)] + public struct PCCARD_RESOURCE + { + /// A PCCARD_DES structure. + public PCCARD_DES PcCard_Header; + } + } +} \ No newline at end of file diff --git a/PInvoke/CfgMgr32/CfgMgr32.cs b/PInvoke/CfgMgr32/CfgMgr32.cs index 4d6a1380..c1144893 100644 --- a/PInvoke/CfgMgr32/CfgMgr32.cs +++ b/PInvoke/CfgMgr32/CfgMgr32.cs @@ -1,14 +1,23 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Runtime.InteropServices; using System.Text; +using Vanara.Extensions; +using Vanara.InteropServices; using static Vanara.PInvoke.SetupAPI; namespace Vanara.PInvoke { - /// Items from the CfgMgr32.dll + /// + /// Items from the CfgMgr32.dll + /// public static partial class CfgMgr32 { + // Win95 compatibility--not applicable to 32-bit ConfigMgr Win95 compatibility--not applicable to 32-bit ConfigMgr Win95 + // compatibility--not applicable to 32-bit ConfigMgr + private const string Lib_Cfgmgr32 = "CfgMgr32.dll"; + #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member public const int CONFIGMG_VERSION = 0x0400; public const int MAX_CLASS_NAME_LEN = 32; @@ -24,10 +33,6 @@ namespace Vanara.PInvoke public const int MAX_PROFILE_LEN = 80; #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member - // Win95 compatibility--not applicable to 32-bit ConfigMgr Win95 compatibility--not applicable to 32-bit ConfigMgr Win95 - // compatibility--not applicable to 32-bit ConfigMgr - private const string Lib_Cfgmgr32 = "CfgMgr32.dll"; - /// Caller-supplied flag constant that specifies the list onto which the supplied device ID should be appended. [PInvokeData("cfgmgr32.h")] public enum CM_ADD_ID @@ -50,6 +55,34 @@ namespace Vanara.PInvoke CM_CLASS_PROPERTY_INTERFACE = 0x00000001, } + /// + /// A value of type ULONG that identifies the property to be retrieved. + /// + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Get_Class_Registry_PropertyW")] + public enum CM_CRP + { + /// UpperFilters REG_MULTI_SZ property (RW) + CM_CRP_UPPERFILTERS = CM_DRP.CM_DRP_UPPERFILTERS, + + /// LowerFilters REG_MULTI_SZ property (RW) + CM_CRP_LOWERFILTERS = CM_DRP.CM_DRP_LOWERFILTERS, + + /// Class default security (RW) + CM_CRP_SECURITY = CM_DRP.CM_DRP_SECURITY, + + /// Class default security (RW) + CM_CRP_SECURITY_SDS = CM_DRP.CM_DRP_SECURITY_SDS, + + /// Class default Device-type (RW) + CM_CRP_DEVTYPE = CM_DRP.CM_DRP_DEVTYPE, + + /// Class default (RW) + CM_CRP_EXCLUSIVE = CM_DRP.CM_DRP_EXCLUSIVE, + + /// Class default (RW) + CM_CRP_CHARACTERISTICS = CM_DRP.CM_DRP_CHARACTERISTICS, + } + /// Delete class key flags [PInvokeData("cfgmgr32.h")] public enum CM_DELETE_CLASS @@ -479,21 +512,27 @@ namespace Vanara.PInvoke ResType_None = 0x00000000, /// Physical address resource + [CorrespondingType(typeof(MEM_RESOURCE))] ResType_Mem = 0x00000001, /// Physical I/O address resource + [CorrespondingType(typeof(IO_RESOURCE))] ResType_IO = 0x00000002, /// DMA channels resource + [CorrespondingType(typeof(DMA_RESOURCE))] ResType_DMA = 0x00000003, /// IRQ resource + [CorrespondingType(typeof(IRQ_RESOURCE_32))] + [CorrespondingType(typeof(IRQ_RESOURCE_64))] ResType_IRQ = 0x00000004, /// Used as spacer to sync subsequent ResTypes w/NT ResType_DoNotUse = 0x00000005, /// bus number resource + [CorrespondingType(typeof(BUSNUMBER_RESOURCE))] ResType_BusNumber = 0x00000006, /// Memory resources >= 4GB @@ -506,18 +545,22 @@ namespace Vanara.PInvoke ResType_Ignored_Bit = 0x00008000, /// class-specific resource + [CorrespondingType(typeof(CS_RESOURCE))] ResType_ClassSpecific = 0x0000FFFF, /// reserved for internal use ResType_Reserved = 0x00008000, /// device private data + //[CorrespondingType(typeof(DEVPRIVATE_RESOURCE))] ResType_DevicePrivate = 0x00008001, /// PC Card configuration data + [CorrespondingType(typeof(PCCARD_RESOURCE))] ResType_PcCardConfig = 0x00008002, /// MF Card configuration data + [CorrespondingType(typeof(MFCARD_RESOURCE))] ResType_MfCardConfig = 0x00008003, } @@ -939,6 +982,48 @@ namespace Vanara.PInvoke [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Add_Res_Des")] public static extern CONFIGRET CM_Add_Res_Des(out SafeRES_DES prdResDes, LOG_CONF lcLogConf, RESOURCEID ResourceID, IntPtr ResourceData, uint ResourceLen, uint ulFlags = 0); + /// The CM_Add_Res_Des function adds a resource descriptor to a logical configuration. + /// The type of the data. + /// + /// + /// Caller-supplied handle to the logical configuration to which the resource descriptor should be added. This handle must have been + /// previously obtained by calling one of the following functions: + /// + /// CM_Add_Empty_Log_Conf + /// CM_Add_Empty_Log_Conf_Ex + /// CM_Get_First_Log_Conf + /// CM_Get_First_Log_Conf_Ex + /// CM_Get_Next_Log_Conf + /// CM_Get_Next_Log_Conf_Ex + /// + /// Caller-supplied resource structure. + /// + /// Caller-supplied resource type identifier, which identifies the type of structure supplied by ResourceData. If this value is 0, + /// the method will attempt to determine the value using . + /// + /// + /// Pointer to a location to receive a handle to the new resource descriptor. + /// + /// Note Starting with Windows 8, CM_Add_Res_Des throws CR_CALL_NOT_IMPLEMENTED when used in a Wow64 scenario. To + /// request information about the hardware resources on a local machine it is necessary implement an architecture-native version of + /// the application using the hardware resource APIs. For example: An AMD64 application for AMD64 systems. + /// + /// + /// + /// + /// Callers of this function must have SeLoadDriverPrivilege. (Privileges are described in the Microsoft Windows SDK documentation.) + /// + /// + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Add_Res_Des")] + public static SafeRES_DES CM_Add_Res_Des(LOG_CONF lcLogConf, T data, RESOURCEID ResourceID = 0) where T : struct + { + if (ResourceID == 0 && !CorrespondingTypeAttribute.CanSet(out ResourceID)) + throw new ArgumentException("Unable to determine RESOURCEID from type.", nameof(T)); + using var mem = new SafeAnysizeStruct(data); + CM_Add_Res_Des(out var hRD, lcLogConf, ResourceID, mem, mem.Size).ThrowIfFailed(); + return hRD; + } + /// /// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated. Please use CM_Add_Res_Des instead.] /// @@ -1211,7 +1296,7 @@ namespace Vanara.PInvoke // DEVINST dnDevInst, ULONG ulFlags ); [DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)] [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Disable_DevNode")] - public static extern CONFIGRET CM_Disable_DevNode(uint dnDevInst, CM_DISABLE ulFlags); + public static extern CONFIGRET CM_Disable_DevNode(uint dnDevInst, CM_DISABLE ulFlags = 0); /// /// @@ -1309,12 +1394,15 @@ namespace Vanara.PInvoke public static IEnumerable CM_Enumerate_Classes(CM_ENUMERATE_CLASSES ulFlags) { var i = 0U; - CONFIGRET cr; - while ((cr = CM_Enumerate_Classes(i, out var guid, ulFlags)) == CONFIGRET.CR_SUCCESS) + var cr = CM_Enumerate_Classes(i, out var guid, ulFlags); + while (cr == CONFIGRET.CR_SUCCESS || cr == CONFIGRET.CR_INVALID_DATA) { - yield return guid; - i++; + if (cr == CONFIGRET.CR_SUCCESS) + yield return guid; + cr = CM_Enumerate_Classes(++i, out guid, ulFlags); } + if (cr != CONFIGRET.CR_NO_SUCH_VALUE && cr != CONFIGRET.CR_SUCCESS && cr != CONFIGRET.CR_INVALID_DATA) + throw cr.GetException(); } /// @@ -1421,6 +1509,8 @@ namespace Vanara.PInvoke i++; sbCap = sb.Capacity; } + if (cr != CONFIGRET.CR_NO_SUCH_VALUE && cr != CONFIGRET.CR_SUCCESS) + throw cr.GetException(); } /// @@ -2077,7 +2167,7 @@ namespace Vanara.PInvoke [DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)] [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Get_Class_Property_Keys")] public static extern CONFIGRET CM_Get_Class_Property_Keys(in Guid ClassGUID, [In, Out, Optional, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] DEVPROPKEY[] PropertyKeyArray, - ref uint PropertyKeyCount, CM_CLASS_PROPERTY ulFlags); + ref int PropertyKeyCount, CM_CLASS_PROPERTY ulFlags); /// /// @@ -2199,7 +2289,7 @@ namespace Vanara.PInvoke // ulFlags, HMACHINE hMachine ); [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Get_Class_Registry_PropertyW")] - public static extern CONFIGRET CM_Get_Class_Registry_Property(in Guid ClassGuid, uint ulProperty, out REG_VALUE_TYPE pulRegDataType, [Out, Optional] IntPtr Buffer, + public static extern CONFIGRET CM_Get_Class_Registry_Property(in Guid ClassGuid, CM_DRP ulProperty, out REG_VALUE_TYPE pulRegDataType, [Out, Optional] IntPtr Buffer, ref uint pulLength, [In, Optional] uint ulFlags, [In, Optional] HMACHINE hMachine); /// @@ -2424,8 +2514,58 @@ namespace Vanara.PInvoke // CM_Get_Device_ID_ListA( PCSTR pszFilter, PZZSTR Buffer, ULONG BufferLen, ULONG ulFlags ); [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Get_Device_ID_ListA")] - public static extern CONFIGRET CM_Get_Device_ID_List([MarshalAs(UnmanagedType.LPTStr)] string pszFilter, [MarshalAs(UnmanagedType.LPTStr)] StringBuilder Buffer, - uint BufferLen, CM_GETIDLIST ulFlags); + public static extern CONFIGRET CM_Get_Device_ID_List([In, Optional, MarshalAs(UnmanagedType.LPTStr)] string pszFilter, [Out] IntPtr Buffer, + uint BufferLen, CM_GETIDLIST ulFlags = 0); + + /// + /// The CM_Get_Device_ID_List function retrieves a list of device instance IDs for the local computer's device instances. + /// + /// Bit flags that specifies search filters + /// + /// Caller-supplied string that is either set to a subset of the computer's device instance identifiers + /// (IDs), or to . See the description of ulFlags. + /// + /// A sequence of device instance identifier strings. + /// + /// + /// Starting with Windows 7, a device that supports multiple transport paths for packet-based data is referred to as a composite + /// device and is represented by a composite devnode. A composite devnode logically represents the composite device to the user and + /// applications as a single device, even though the composite devnode can have multiple paths to the physical device. + /// + /// + /// Each active transport path to the physical device is represented by a transport devnode and is referred to as a transport + /// relation for the composite device. + /// + /// + /// The composite devnode (but not the related transport devnodes) exposes device interfaces to applications and the system. When an + /// application uses these public device interfaces, the composite device routes the packet-based data to one or more of these + /// transport devnodes, which then transport the data to the physical device. + /// + /// + /// For example, if a physical cell phone is simultaneously connected to the computer on the USB and the Bluetooth buses, each bus + /// enumerates a child transport devnode on that bus to represent the device's physical connection. + /// + /// + /// In this case, if you set the CM_GETIDLIST_FILTER_TRANSPORTRELATIONS flags in ulFlags and specify the device instance ID of the + /// cell phone's composite devnode in pszFilter, the function returns the device instance IDs for the two transport devnodes in the + /// Buffer parameter. + /// + /// For more information about device instance IDs, see Device Identification Strings. + /// + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Get_Device_ID_ListA")] + public static IEnumerable CM_Get_Device_ID_List(CM_GETIDLIST ulFlags = 0, string pszFilter = null) + { + while (true) + { + CM_Get_Device_ID_List_Size(out var len, pszFilter, ulFlags).ThrowIfFailed(); + using var mem = new SafeCoTaskMemHandle(len * StringHelper.GetCharSize()); + var ret = CM_Get_Device_ID_List(pszFilter, mem, len, ulFlags); + if (ret == CONFIGRET.CR_SUCCESS) + return mem.ToStringEnum().ToArray(); + else if (ret != CONFIGRET.CR_BUFFER_SMALL) + ret.ThrowIfFailed(); + } + } /// /// @@ -2470,8 +2610,8 @@ namespace Vanara.PInvoke // CM_Get_Device_ID_List_ExW( PCWSTR pszFilter, PZZWSTR Buffer, ULONG BufferLen, ULONG ulFlags, HMACHINE hMachine ); [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Get_Device_ID_List_ExW")] - public static extern CONFIGRET CM_Get_Device_ID_List_Ex([In, Optional, MarshalAs(UnmanagedType.LPTStr)] string pszFilter, [MarshalAs(UnmanagedType.LPTStr)] StringBuilder Buffer, - uint BufferLen, CM_GETIDLIST ulFlags, [In, Optional] HMACHINE hMachine); + public static extern CONFIGRET CM_Get_Device_ID_List_Ex([In, Optional, MarshalAs(UnmanagedType.LPTStr)] string pszFilter, [Out] IntPtr Buffer, + uint BufferLen, [In, Optional] CM_GETIDLIST ulFlags, [In, Optional] HMACHINE hMachine); /// /// The CM_Get_Parent function obtains a device instance handle to the parent node of a specified device node (devnode) in @@ -2493,60 +2633,6 @@ namespace Vanara.PInvoke [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Get_Parent")] public static extern CONFIGRET CM_Get_Parent(out uint pdnDevInst, uint dnDevInst, uint ulFlags = 0); - /// - /// The CM_Request_Device_Eject function prepares a local device instance for safe removal, if the device is removable. If - /// the device can be physically ejected, it will be. - /// - /// Caller-supplied device instance handle that is bound to the local machine. - /// - /// (Optional.) If not NULL, this points to a location that, if the removal request fails, receives a PNP_VETO_TYPE-typed - /// value indicating the reason for the failure. - /// - /// - /// (Optional.) If not NULL, this is a caller-supplied pointer to a string buffer that receives a text string. The type of - /// information this string provides is dependent on the value received by pVetoType. For information about these strings, see PNP_VETO_TYPE. - /// - /// - /// (Optional.) Caller-supplied value representing the length of the string buffer supplied by pszVetoName. This should be set to MAX_PATH. - /// - /// Not used. - /// - /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h. - /// - /// - /// - /// If pszVetoName is NULL, the PnP manager displays a message to the user indicating the device was removed or, if the - /// request failed, identifying the reason for the failure. If pszVetoName is not NULL, the PnP manager does not display a - /// message. (Note, however, that for Microsoft Windows 2000 only, the PnP manager displays a message even if pszVetoName is not - /// NULL, if the device's CM_DEVCAP_DOCKDEVICE capability is set.) - /// - /// - /// Callers of CM_Request_Device_Eject sometimes require SeUndockPrivilege or SeLoadDriverPrivilege, as follows: - /// - /// - /// - /// - /// If the device's CM_DEVCAP_DOCKDEVICE capability is set (the device is a "dock" device), callers must have - /// SeUndockPrivilege. ( SeLoadDriverPrivilege is not required.) - /// - /// - /// - /// - /// If the device's CM_DEVCAP_DOCKDEVICE capability is not set (the device is not a "dock" device), and if the calling process is - /// either not interactive or is running in a multi-user environment in a session not attached to the physical console (such as a - /// remote Terminal Services session), callers of this function must have SeLoadDriverPrivilege. - /// - /// - /// - /// Privileges are described in the Microsoft Windows SDK documentation. - /// For information about using device instance handles that are bound to the local machine, see CM_Get_Child. - /// - // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_request_device_ejectw CMAPI CONFIGRET - // CM_Request_Device_EjectW( DEVINST dnDevInst, PPNP_VETO_TYPE pVetoType, LPWSTR pszVetoName, ULONG ulNameLength, ULONG ulFlags ); - [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Auto)] - [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Request_Device_EjectW")] - public static extern CONFIGRET CM_Request_Device_Eject(uint dnDevInst, out PNP_VETO_TYPE pVetoType, [In, Out, Optional] StringBuilder pszVetoName, [Optional] uint ulNameLength, uint ulFlags = 0); - /// Provides a handle to a resource conflict list. [PInvokeData("cfgmgr32.h")] [StructLayout(LayoutKind.Sequential)] @@ -2596,6 +2682,54 @@ namespace Vanara.PInvoke public IntPtr DangerousGetHandle() => handle; } + /// Provides a handle to a notification context. + [StructLayout(LayoutKind.Sequential)] + public struct HCMNOTIFICATION : IHandle + { + private readonly IntPtr handle; + + /// Initializes a new instance of the struct. + /// An object that represents the pre-existing handle to use. + public HCMNOTIFICATION(IntPtr preexistingHandle) => handle = preexistingHandle; + + /// Returns an invalid handle by instantiating a object with . + public static HCMNOTIFICATION NULL => new(IntPtr.Zero); + + /// Gets a value indicating whether this instance is a null handle. + public bool IsNull => handle == IntPtr.Zero; + + /// Performs an explicit conversion from to . + /// The handle. + /// The result of the conversion. + public static explicit operator IntPtr(HCMNOTIFICATION h) => h.handle; + + /// Performs an implicit conversion from to . + /// The pointer to a handle. + /// The result of the conversion. + public static implicit operator HCMNOTIFICATION(IntPtr h) => new(h); + + /// Implements the operator !=. + /// The first handle. + /// The second handle. + /// The result of the operator. + public static bool operator !=(HCMNOTIFICATION h1, HCMNOTIFICATION h2) => !(h1 == h2); + + /// Implements the operator ==. + /// The first handle. + /// The second handle. + /// The result of the operator. + public static bool operator ==(HCMNOTIFICATION h1, HCMNOTIFICATION h2) => h1.Equals(h2); + + /// + public override bool Equals(object obj) => obj is HCMNOTIFICATION h && handle == h.handle; + + /// + public override int GetHashCode() => handle.GetHashCode(); + + /// + public IntPtr DangerousGetHandle() => handle; + } + /// Provides a handle to a device instance. [PInvokeData("cfgmgr32.h")] [StructLayout(LayoutKind.Sequential), System.Diagnostics.DebuggerDisplay("{handle}")] @@ -2743,6 +2877,50 @@ namespace Vanara.PInvoke public IntPtr DangerousGetHandle() => handle; } + /// Provides a for that is disposed using . + public class SafeCONFLICT_LIST : SafeHANDLE + { + /// Initializes a new instance of the class and assigns an existing handle. + /// An object that represents the pre-existing handle to use. + /// + /// to reliably release the handle during the finalization phase; otherwise, (not recommended). + /// + public SafeCONFLICT_LIST(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { } + + /// Initializes a new instance of the class. + private SafeCONFLICT_LIST() : base() { } + + /// Performs an implicit conversion from to . + /// The safe handle instance. + /// The result of the conversion. + public static implicit operator CONFLICT_LIST(SafeCONFLICT_LIST h) => h.handle; + + /// + protected override bool InternalReleaseHandle() => CM_Free_Resource_Conflict_Handle(handle) == 0; + } + + /// Provides a for that is disposed using . + public class SafeHCMNOTIFICATION : SafeHANDLE + { + /// Initializes a new instance of the class and assigns an existing handle. + /// An object that represents the pre-existing handle to use. + /// + /// to reliably release the handle during the finalization phase; otherwise, (not recommended). + /// + public SafeHCMNOTIFICATION(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { } + + /// Initializes a new instance of the class. + private SafeHCMNOTIFICATION() : base() { } + + /// Performs an implicit conversion from to . + /// The safe handle instance. + /// The result of the conversion. + public static implicit operator HCMNOTIFICATION(SafeHCMNOTIFICATION h) => h.handle; + + /// + protected override bool InternalReleaseHandle() => CM_Unregister_Notification(handle) == 0; + } + /// Provides a for that is disposed using . public class SafeHMACHINE : SafeHANDLE { diff --git a/PInvoke/CfgMgr32/CfgMgr32_2.cs b/PInvoke/CfgMgr32/CfgMgr32_2.cs index ffc64465..89015139 100644 --- a/PInvoke/CfgMgr32/CfgMgr32_2.cs +++ b/PInvoke/CfgMgr32/CfgMgr32_2.cs @@ -1,6 +1,9 @@ using System; +using System.Linq; using System.Runtime.InteropServices; using System.Text; +using Vanara.Extensions; +using Vanara.InteropServices; using static Vanara.PInvoke.SetupAPI; namespace Vanara.PInvoke @@ -102,15 +105,9 @@ namespace Vanara.PInvoke /// UpperFilters REG_MULTI_SZ property (RW) CM_DRP_UPPERFILTERS = 0x00000012, - /// UpperFilters REG_MULTI_SZ property (RW) - CM_CRP_UPPERFILTERS = CM_DRP_UPPERFILTERS, - /// LowerFilters REG_MULTI_SZ property (RW) CM_DRP_LOWERFILTERS = 0x00000013, - /// LowerFilters REG_MULTI_SZ property (RW) - CM_CRP_LOWERFILTERS = CM_DRP_LOWERFILTERS, - /// Bus Type Guid, GUID, (R) CM_DRP_BUSTYPEGUID = 0x00000014, @@ -126,33 +123,18 @@ namespace Vanara.PInvoke /// Security - Device override (RW) CM_DRP_SECURITY = 0x00000018, - /// Class default security (RW) - CM_CRP_SECURITY = CM_DRP_SECURITY, - /// Security - Device override (RW) CM_DRP_SECURITY_SDS = 0x00000019, - /// Class default security (RW) - CM_CRP_SECURITY_SDS = CM_DRP_SECURITY_SDS, - /// Device Type - Device override (RW) CM_DRP_DEVTYPE = 0x0000001A, - /// Class default Device-type (RW) - CM_CRP_DEVTYPE = CM_DRP_DEVTYPE, - /// Exclusivity - Device override (RW) CM_DRP_EXCLUSIVE = 0x0000001B, - /// Class default (RW) - CM_CRP_EXCLUSIVE = CM_DRP_EXCLUSIVE, - /// Characteristics - Device Override (RW) CM_DRP_CHARACTERISTICS = 0x0000001C, - /// Class default (RW) - CM_CRP_CHARACTERISTICS = CM_DRP_CHARACTERISTICS, - /// Device Address (R) CM_DRP_ADDRESS = 0x0000001D, @@ -430,7 +412,7 @@ namespace Vanara.PInvoke // CM_Get_Device_ID_List_SizeA( PULONG pulLen, PCSTR pszFilter, ULONG ulFlags ); [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Get_Device_ID_List_SizeA")] - public static extern CONFIGRET CM_Get_Device_ID_List_Size(out uint pulLen, [Optional, MarshalAs(UnmanagedType.LPTStr)] string pszFilter, CM_GETIDLIST ulFlags); + public static extern CONFIGRET CM_Get_Device_ID_List_Size(out uint pulLen, [Optional, MarshalAs(UnmanagedType.LPTStr)] string pszFilter, CM_GETIDLIST ulFlags = 0); /// /// @@ -479,7 +461,7 @@ namespace Vanara.PInvoke // CM_Get_Device_ID_List_Size_ExW( PULONG pulLen, PCWSTR pszFilter, ULONG ulFlags, HMACHINE hMachine ); [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Get_Device_ID_List_Size_ExW")] - public static extern CONFIGRET CM_Get_Device_ID_List_Size_Ex(out uint pulLen, [Optional, MarshalAs(UnmanagedType.LPTStr)] string pszFilter, CM_GETIDLIST ulFlags, [In, Optional] HMACHINE hMachine); + public static extern CONFIGRET CM_Get_Device_ID_List_Size_Ex(out uint pulLen, [Optional, MarshalAs(UnmanagedType.LPTStr)] string pszFilter, [In, Optional] CM_GETIDLIST ulFlags, [In, Optional] HMACHINE hMachine); /// /// The CM_Get_Device_ID_Size function retrieves the buffer size required to hold a device instance ID for a device instance @@ -572,7 +554,7 @@ namespace Vanara.PInvoke // DEVINST dnDevInst, PWSTR Buffer, ULONG BufferLen, ULONG ulFlags ); [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Unicode)] [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Get_Device_IDW")] - public static extern CONFIGRET CM_Get_Device_IDW(uint dnDevInst, StringBuilder Buffer, uint BufferLen, uint ulFlags = 0); + public static extern CONFIGRET CM_Get_Device_ID(uint dnDevInst, StringBuilder Buffer, uint BufferLen, uint ulFlags = 0); /// /// The CM_Get_Device_Interface_Alias function returns the alias of the specified device interface instance, if the alias exists. @@ -723,7 +705,45 @@ namespace Vanara.PInvoke [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Get_Device_Interface_ListA")] public static extern CONFIGRET CM_Get_Device_Interface_List(in Guid InterfaceClassGuid, [Optional, MarshalAs(UnmanagedType.LPTStr)] string pDeviceID, - [MarshalAs(UnmanagedType.LPTStr)] StringBuilder Buffer, uint BufferLen, CM_GET_DEVICE_INTERFACE_LIST ulFlags); + IntPtr Buffer, uint BufferLen, CM_GET_DEVICE_INTERFACE_LIST ulFlags); + + /// + /// The CM_Get_Device_Interface_List function retrieves a list of device interface instances that belong to a specified + /// device interface class. + /// + /// Supplies a GUID that identifies a device interface class. + /// + /// Contains one of the following caller-supplied flags: + /// CM_GET_DEVICE_INTERFACE_LIST_ALL_DEVICES + /// + /// The function provides a list containing device interfaces associated with all devices that match the specified GUID and device + /// instance ID, if any. + /// + /// CM_GET_DEVICE_INTERFACE_LIST_PRESENT + /// + /// The function provides a list containing device interfaces associated with devices that are currently active, and which match the + /// specified GUID and device instance ID, if any. + /// + /// + /// + /// Caller-supplied string that represents a device instance ID. If specified, the function retrieves device interfaces that are + /// supported by the device for the specified class. If this value is , or if it is a zero-length string, the + /// function retrieves all interfaces that belong to the specified class. + /// + /// An array of strings, each representing the symbolic link name of an interface instance. + public static string[] CM_Get_Device_Interface_List(in Guid InterfaceClassGuid, CM_GET_DEVICE_INTERFACE_LIST ulFlags, string pDeviceID = null) + { + while (true) + { + CM_Get_Device_Interface_List_Size(out var len, InterfaceClassGuid, pDeviceID, ulFlags).ThrowIfFailed(); + using var mem = new SafeCoTaskMemHandle(len * StringHelper.GetCharSize()); + var ret = CM_Get_Device_Interface_List(InterfaceClassGuid, pDeviceID, mem, len, ulFlags); + if (ret == CONFIGRET.CR_SUCCESS) + return mem.ToStringEnum().ToArray(); + else if (ret != CONFIGRET.CR_BUFFER_SMALL) + ret.ThrowIfFailed(); + } + } /// /// The CM_Get_Device_Interface_List_Size function retrieves the buffer size that must be passed to the @@ -2237,102 +2257,5 @@ namespace Vanara.PInvoke [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Get_Resource_Conflict_DetailsW")] public static extern CONFIGRET CM_Get_Resource_Conflict_Details(CONFLICT_LIST clConflictList, uint ulIndex, ref CONFLICT_DETAILS pConflictDetails); - - /// The CONFLICT_DETAILS structure is used as a parameter to the CM_Get_Resource_Conflict_Details function. - /// - /// Note - /// - /// The cfgmgr32.h header defines CONFLICT_DETAILS as an alias which automatically selects the ANSI or Unicode version of this - /// function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that - /// not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions - /// for Function Prototypes. - /// - /// - // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/ns-cfgmgr32-conflict_details_a typedef struct _CONFLICT_DETAILS_A { - // ULONG CD_ulSize; ULONG CD_ulMask; DEVINST CD_dnDevInst; RES_DES CD_rdResDes; ULONG CD_ulFlags; CHAR CD_szDescription[MAX_PATH]; } - // CONFLICT_DETAILS_A, *PCONFLICT_DETAILS_A; - [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32._CONFLICT_DETAILS_A")] - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] - public struct CONFLICT_DETAILS - { - /// Size, in bytes, of the CONFLICT_DETAILS structure. - public uint CD_ulSize; - - /// - /// - /// One or more bit flags supplied by the caller of CM_Get_Resource_Conflict_Details. The bit flags are described in the - /// following table. - /// - /// - /// - /// Flag - /// Description - /// - /// - /// CM_CDMASK_DEVINST - /// If set, CM_Get_Resource_Conflict_Details supplies a value for the CD_dnDevInst member. - /// - /// - /// CM_CDMASK_RESDES - /// Not used. - /// - /// - /// CM_CDMASK_FLAGS - /// If set, CM_Get_Resource_Conflict_Details supplies a value for the CD_ulFlags member. - /// - /// - /// CM_CDMASK_DESCRIPTION - /// If set, CM_Get_Resource_Conflict_Details supplies a value for the CD_szDescription member. - /// - /// - /// - public CM_CDMASK CD_ulMask; - - /// - /// If CM_CDMASK_DEVINST is set in CD_ulMask, this member will receive a handle to a device instance that has conflicting - /// resources. If a handle is not obtainable, the member receives -1. - /// - public uint CD_dnDevInst; - - /// Not used. - public RES_DES CD_rdResDes; - - /// - /// If CM_CDMASK_FLAGS is set in CD_ulMask, this member can receive bit flags listed in the following table. - /// - /// - /// Flag - /// Description - /// - /// - /// CM_CDFLAGS_DRIVER - /// - /// If set, the string contained in the CD_szDescription member represents a driver name instead of a device name, and - /// CD_dnDevInst is -1. - /// - /// - /// - /// CM_CDFLAGS_ROOT_OWNED - /// If set, the conflicting resources are owned by the root device (that is, the HAL), and CD_dnDevInst is -1. - /// - /// - /// CM_CDFLAGS_RESERVED - /// If set, the owner of the conflicting resources cannot be determined, and CD_dnDevInst is -1. - /// - /// - /// - public CM_CDFLAGS CD_ulFlags; - - /// - /// If CM_CDMASK_DESCRIPTION is set in CD_ulMask, this member will receive a NULL-terminated text string representing a - /// description of the device that owns the resources. If CM_CDFLAGS_DRIVER is set in CD_ulFlags, this string represents - /// a driver name. If CM_CDFLAGS_ROOT_OWNED or CM_CDFLAGS_RESERVED is set, the string value is NULL. - /// - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260 /*MAX_PATH*/)] - public string CD_szDescription; - - /// Gets a default value for the structure with the size field set. - public static readonly CONFLICT_DETAILS Default = new() { CD_ulSize = (uint)Marshal.SizeOf(typeof(CONFLICT_DETAILS)) }; - } } } \ No newline at end of file diff --git a/PInvoke/CfgMgr32/CfgMgr32_3.cs b/PInvoke/CfgMgr32/CfgMgr32_3.cs index 9208c23e..74532417 100644 --- a/PInvoke/CfgMgr32/CfgMgr32_3.cs +++ b/PInvoke/CfgMgr32/CfgMgr32_3.cs @@ -1,6 +1,8 @@ +using Microsoft.Win32.SafeHandles; using System; using System.Runtime.InteropServices; using System.Text; +using static Vanara.PInvoke.AdvApi32; using static Vanara.PInvoke.SetupAPI; namespace Vanara.PInvoke @@ -8,80 +10,2857 @@ namespace Vanara.PInvoke /// Items from the CfgMgr32.dll public static partial class CfgMgr32 { - /* - CM_Get_Sibling - CM_Get_Sibling_Ex - CM_Get_Version - CM_Get_Version_Ex - CM_Is_Dock_Station_Present - CM_Is_Dock_Station_Present_Ex - CM_Is_Version_Available - CM_Is_Version_Available_Ex - CM_Locate_DevNode_ExW - CM_Locate_DevNodeA - CM_Locate_DevNodeW - CM_MapCrToWin32Err - CM_Modify_Res_Des - CM_Modify_Res_Des_Ex - CM_Open_Class_KeyW - CM_Open_Device_Interface_Key_ExA - CM_Open_Device_Interface_Key_ExW - CM_Open_Device_Interface_KeyA - CM_Open_Device_Interface_KeyW - CM_Open_DevNode_Key - CM_Query_And_Remove_SubTree_ExW - CM_Query_And_Remove_SubTreeW - CM_Query_Resource_Conflict_List - CM_Reenumerate_DevNode - CM_Reenumerate_DevNode_Ex - CM_Register_Notification - CM_Request_Device_Eject_ExW - CM_Request_Device_EjectW - CM_Request_Eject_PC - CM_Request_Eject_PC_Ex - CM_Set_Class_Property_ExW - CM_Set_Class_PropertyW - CM_Set_Class_Registry_PropertyW - CM_Set_Device_Interface_Property_ExW - CM_Set_Device_Interface_PropertyW - CM_Set_DevNode_Problem - CM_Set_DevNode_Problem_Ex - CM_Set_DevNode_Property_ExW - CM_Set_DevNode_PropertyW - CM_Set_DevNode_Registry_PropertyW - CM_Setup_DevNode - CM_Uninstall_DevNode - CM_Unregister_Notification - CM_WaitNoPendingInstallEvents + /// The callback routine invoked by the Configuration Manager when listening for events. + /// The handle of the notification context which invoked the callback. + /// A user-provided callback context. + /// The device action which triggered the callback. + /// The callback data. + /// The size of the callback data struct. + /// + /// If responding to a notification, the callback should return either or , as appropriate. Otherwise, the callback should return . The callback should not return any other values. + /// + [UnmanagedFunctionPointer(CallingConvention.Winapi)] + public delegate Win32Error CM_NOTIFY_CALLBACK(HCMNOTIFICATION notify, [Optional] IntPtr context, CM_NOTIFY_ACTION action, in CM_NOTIFY_EVENT_DATA eventData, uint eventDataSize); - BUSNUMBER_DES - BUSNUMBER_RANGE - BUSNUMBER_RESOURCE - CM_NOTIFY_EVENT_DATA - CM_NOTIFY_FILTER - CS_DES - CS_RESOURCE - DMA_DES - DMA_RANGE - DMA_RESOURCE - IO_DES - IO_RANGE - IO_RESOURCE - IRQ_DES_32 - IRQ_DES_64 - IRQ_RANGE - IRQ_RESOURCE_32 - IRQ_RESOURCE_64 - MEM_DES - MEM_RANGE - MEM_RESOURCE - MFCARD_DES - MFCARD_RESOURCE - PCCARD_DES - PCCARD_RESOURCE + /// + /// A variable of ULONG type that supplies one of the following flag values that apply if the caller supplies a device instance identifier + /// + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Locate_DevNodeA")] + [Flags] + public enum CM_LOCATE_DEVINST : uint + { + /// + CM_LOCATE_DEVINST_NORMAL = CM_LOCATE_DEVNODE.CM_LOCATE_DEVNODE_NORMAL, - CM_NOTIFY_ACTION + /// + CM_LOCATE_DEVINST_PHANTOM = CM_LOCATE_DEVNODE.CM_LOCATE_DEVNODE_PHANTOM, - */ + /// + CM_LOCATE_DEVINST_CANCELREMOVE = CM_LOCATE_DEVNODE.CM_LOCATE_DEVNODE_CANCELREMOVE, + + /// + CM_LOCATE_DEVINST_NOVALIDATION = CM_LOCATE_DEVNODE.CM_LOCATE_DEVNODE_NOVALIDATION, + } + + /// + /// A variable of ULONG type that supplies one of the following flag values that apply if the caller supplies a device instance identifier + /// + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Locate_DevNodeA")] + [Flags] + public enum CM_LOCATE_DEVNODE : uint + { + /// + /// The function retrieves the device instance handle for the specified device only if the device is currently configured in the + /// device tree. + /// + CM_LOCATE_DEVNODE_NORMAL = 0x00000000, + + /// + /// The function retrieves a device instance handle for the specified device if the device is currently configured in the device + /// tree or the device is a nonpresent device that is not currently configured in the device tree. + /// + CM_LOCATE_DEVNODE_PHANTOM = 0x00000001, + + /// + /// The function retrieves a device instance handle for the specified device if the device is currently configured in the device + /// tree or in the process of being removed from the device tree. If the device is in the process of being removed, the function + /// cancels the removal of the device. + /// + CM_LOCATE_DEVNODE_CANCELREMOVE = 0x00000002, + + /// Not used. + CM_LOCATE_DEVNODE_NOVALIDATION = 0x00000004, + } + + /// This enumeration identifies Plug and Play device event types. + /// + /// When a driver calls the CM_Register_Notification function, the pCallback parameter contains a pointer to a routine to be called + /// when a specified PnP event occurs. The callback routine's Action parameter is a value from the CM_NOTIFY_ACTION enumeration. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/ne-cfgmgr32-cm_notify_action typedef enum _CM_NOTIFY_ACTION { + // CM_NOTIFY_ACTION_DEVICEINTERFACEARRIVAL, CM_NOTIFY_ACTION_DEVICEINTERFACEREMOVAL, CM_NOTIFY_ACTION_DEVICEQUERYREMOVE, + // CM_NOTIFY_ACTION_DEVICEQUERYREMOVEFAILED, CM_NOTIFY_ACTION_DEVICEREMOVEPENDING, CM_NOTIFY_ACTION_DEVICEREMOVECOMPLETE, + // CM_NOTIFY_ACTION_DEVICECUSTOMEVENT, CM_NOTIFY_ACTION_DEVICEINSTANCEENUMERATED, CM_NOTIFY_ACTION_DEVICEINSTANCESTARTED, + // CM_NOTIFY_ACTION_DEVICEINSTANCEREMOVED, CM_NOTIFY_ACTION_MAX } CM_NOTIFY_ACTION, *PCM_NOTIFY_ACTION; + [PInvokeData("cfgmgr32.h", MSDNShortId = "NE:cfgmgr32._CM_NOTIFY_ACTION")] + public enum CM_NOTIFY_ACTION + { + /// + /// For this value, set the FilterType member of the CM_NOTIFY_FILTER structure to CM_NOTIFY_FILTER_TYPE_DEVICEINTERFACE. This + /// action indicates that a device interface that meets your filter criteria has been enabled. + /// + CM_NOTIFY_ACTION_DEVICEINTERFACEARRIVAL = 0, + + /// + /// For this value, set the FilterType member of the CM_NOTIFY_FILTER structure to CM_NOTIFY_FILTER_TYPE_DEVICEINTERFACE. This + /// action indicates that a device interface that meets your filter criteria has been disabled. + /// + CM_NOTIFY_ACTION_DEVICEINTERFACEREMOVAL, + + /// + /// For this value, set the FilterType member of the CM_NOTIFY_FILTER structure to CM_NOTIFY_FILTER_TYPE_DEVICEHANDLE. This + /// action indicates that the device is being query removed. In order to allow the query remove to succeed, call CloseHandle to + /// close any handles you have open to the device. If you do not do this, your open handle prevents the query remove of this + /// device from succeeding. See Registering for Notification of Device Interface Arrival and Device Removal for more + /// information.To veto the query remove, return ERROR_CANCELLED. However, it is recommended that you do not veto the query + /// remove and allow it to happen by closing any handles you have open to the device. + /// + CM_NOTIFY_ACTION_DEVICEQUERYREMOVE, + + /// + /// For this value, set the FilterType member of the CM_NOTIFY_FILTER structure to CM_NOTIFY_FILTER_TYPE_DEVICEHANDLE. This + /// action indicates that the query remove of a device was failed. If you closed the handle to this device during a previous + /// notification of CM_NOTIFY_ACTION_DEVICEQUERYREMOVE, open a new handle to the device to continue sending I/O requests to it. + /// See Registering for Notification of Device Interface Arrival and Device Removal for more information. + /// + CM_NOTIFY_ACTION_DEVICEQUERYREMOVEFAILED, + + /// + /// For this value, set the FilterType member of the CM_NOTIFY_FILTER structure to CM_NOTIFY_FILTER_TYPE_DEVICEHANDLE.The device + /// will be removed. If you still have an open handle to the device, call CloseHandle to close the device handle. See + /// Registering for Notification of Device Interface Arrival and Device Removal for more information. The system may send a + /// CM_NOTIFY_ACTION_DEVICEREMOVEPENDING notification without sending a corresponding CM_NOTIFY_ACTION_DEVICEQUERYREMOVE + /// message. In such cases, the applications and drivers must recover from the loss of the device as best they can. + /// + CM_NOTIFY_ACTION_DEVICEREMOVEPENDING, + + /// + /// For this value, set the FilterType member of the CM_NOTIFY_FILTER structure to CM_NOTIFY_FILTER_TYPE_DEVICEHANDLE.The device + /// has been removed. If you still have an open handle to the device, call CloseHandle to close the device handle. See + /// Registering for Notification of Device Interface Arrival and Device Removal for more information. The system may send a + /// CM_NOTIFY_ACTION_DEVICEREMOVECOMPLETE notification without sending corresponding CM_NOTIFY_ACTION_DEVICEQUERYREMOVE or + /// CM_NOTIFY_ACTION_DEVICEREMOVEPENDING messages. In such cases, the applications and drivers must recover from the loss of the + /// device as best they can. + /// + CM_NOTIFY_ACTION_DEVICEREMOVECOMPLETE, + + /// + /// For this value, set the FilterType member of the CM_NOTIFY_FILTER structure to CM_NOTIFY_FILTER_TYPE_DEVICEHANDLE. This + /// action is sent when a driver-defined custom event has occurred. + /// + CM_NOTIFY_ACTION_DEVICECUSTOMEVENT, + + /// + /// For this value, set the FilterType member of the CM_NOTIFY_FILTER structure to CM_NOTIFY_FILTER_TYPE_DEVICEINSTANCE. This + /// action is sent when a new device instance that meets your filter criteria has been enumerated. + /// + CM_NOTIFY_ACTION_DEVICEINSTANCEENUMERATED, + + /// + /// For this value, set the FilterType member of the CM_NOTIFY_FILTER structure to CM_NOTIFY_FILTER_TYPE_DEVICEINSTANCE. This + /// action is sent when a device instance that meets your filter criteria becomes started. + /// + CM_NOTIFY_ACTION_DEVICEINSTANCESTARTED, + + /// + /// For this value, set the FilterType member of the CM_NOTIFY_FILTER structure to CM_NOTIFY_FILTER_TYPE_DEVICEINSTANCE. This + /// action is sent when a device instance that meets your filter criteria is no longer present. + /// + CM_NOTIFY_ACTION_DEVICEINSTANCEREMOVED, + } + + /// Flags for + [Flags] + public enum CM_NOTIFY_FILTER_FLAG : uint + { + /// + /// Register to receive notifications for PnP events for all device interface classes. The memory at + /// pFilter->u.DeviceInterface.ClassGuid must be zeroes. Do not use this flag with + /// CM_NOTIFY_FILTER_FLAG_ALL_DEVICE_INSTANCES. This flag is only valid if pFilter->FilterType is CM_NOTIFY_FILTER_TYPE_DEVICEINTERFACE. + /// + CM_NOTIFY_FILTER_FLAG_ALL_INTERFACE_CLASSES = 0x00000001, + + /// + /// Register to receive notifications for PnP events for all devices. pFilter->u.DeviceInstance.InstanceId must be an + /// empty string. Do not use this flag with CM_NOTIFY_FILTER_FLAG_ALL_INTERFACE_CLASSES. This flag is only valid if + /// pFilter->FilterType is CM_NOTIFY_FILTER_TYPE_DEVICEINSTANCE. + /// + CM_NOTIFY_FILTER_FLAG_ALL_DEVICE_INSTANCES = 0x00000002, + } + + /// Options for + [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32._CM_NOTIFY_FILTER")] + public enum CM_NOTIFY_FILTER_TYPE + { + /// + /// Register for notifications for device interface events. pFilter->u.DeviceInterface.ClassGuid should be filled in + /// with the GUID of the device interface class to receive notifications for. + /// + CM_NOTIFY_FILTER_TYPE_DEVICEINTERFACE = 0, + + /// + /// Register for notifications for device handle events. pFilter->u.DeviceHandle.hTarget must be filled in with a + /// handle to the device to receive notifications for. + /// + CM_NOTIFY_FILTER_TYPE_DEVICEHANDLE, + + /// + /// Register for notifications for device instance events. pFilter->u.DeviceInstance.InstanceId should be filled in + /// with the device instance ID of the device to receive notifications for. + /// + CM_NOTIFY_FILTER_TYPE_DEVICEINSTANCE, + } + + /// Open class key flags + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Open_Class_KeyW")] + public enum CM_OPEN_CLASS_KEY + { + /// The key to be opened is for a device setup class. + CM_OPEN_CLASS_KEY_INSTALLER = 0x00000000, + + /// The key to be opened is for a device interface class. + CM_OPEN_CLASS_KEY_INTERFACE = 0x00000001, + } + + /// Caller-supplied flags that specify how reenumeration should occur. + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Reenumerate_DevNode")] + [Flags] + public enum CM_REENUMERATE : uint + { + /// + /// Specifies default reenumeration behavior, in which reenumeration occurs synchronously. This flag is functionally equivalent + /// to CM_REENUMERATE_SYNCHRONOUS. + /// + CM_REENUMERATE_NORMAL = 0x00000000, + + /// + /// Reenumeration should occur synchronously. The call to this function returns when all devices in the specified subtree have + /// been reenumerated. If this flag is set, the CM_REENUMERATE_ASYNCHRONOUS flag should not also be set. This flag is + /// functionally equivalent to CM_REENUMERATE_NORMAL. + /// + CM_REENUMERATE_SYNCHRONOUS = 0x00000001, + + /// + /// + /// Specifies that Plug and Play should make another attempt to install any devices in the specified subtree that have been + /// detected but are not yet configured, or are marked as needing reinstallation, or for which installation must be completed. + /// This flag can be set along with either the CM_REENUMERATE_SYNCHRONOUS flag or the CM_REENUMERATE_ASYNCHRONOUS flag. + /// + /// + /// This flag must be used with extreme caution, because it can cause the PnP manager to prompt the user to perform installation + /// of any such devices. Currently, only components such as Device Manager and Hardware Wizard use this flag, to allow the user + /// to retry installation of devices that might already have been detected but are not currently installed. + /// + /// + CM_REENUMERATE_RETRY_INSTALLATION = 0x00000002, + + /// + /// Reenumeration should occur asynchronously. The call to this function returns immediately after the PnP manager receives the + /// reenumeration request. If this flag is set, the CM_REENUMERATE_SYNCHRONOUS flag should not also be set. + /// + CM_REENUMERATE_ASYNCHRONOUS = 0x00000004, + } + + /// A bitwise OR of the caller-supplied flag constants + [Flags] + public enum CM_REMOVE : uint + { + /// + CM_REMOVE_UI_OK = 0x00000000, + + /// + CM_REMOVE_UI_NOT_OK = 0x00000001, + + /// + CM_REMOVE_NO_RESTART = 0x00000002, + } + + /// Flags for . + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Setup_DevNode")] + public enum CM_SETUP_DEVNODE + { + /// Configure devinst without (re)starting + CM_SETUP_DEVNODE_CONFIG = 0x00000005, + + /// Configure devinst class without (re)starting + CM_SETUP_DEVNODE_CONFIG_CLASS = 0x00000006, + + /// Configure devinst extensions without (re)starting + CM_SETUP_DEVNODE_CONFIG_EXTENSIONS = 0x00000007, + + /// Reset devinst configuration without (re)starting + CM_SETUP_DEVNODE_CONFIG_RESET = 0x00000008, + + /// Restarts a device instance that is not running because of a problem with the device configuration. + CM_SETUP_DEVNODE_READY = 0x00000000, + + /// + /// Resets a device instance that has the no restart device status flag set. The no restart device status flag is set if a + /// device is removed by calling CM_Query_And_Remove_SubTree or CM_Query_And_Remove_SubTree_Ex and specifying the + /// CM_REMOVE_NO_RESTART flag. + /// + CM_SETUP_DEVNODE_RESET = 0x00000004, + } + + /// Flags for . + [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32.DMA_Des_s")] + [Flags] + public enum DMA_DES_FLAGS : uint + { + /// Bitmask for the bits within DD_Flags that specify the channel width value. + mDD_Width = 0x3, + + /// 8-bit DMA channel + fDD_BYTE = 0x0, + + /// 16-bit DMA channel + fDD_WORD = 0x1, + + /// 32-bit DMA channel + fDD_DWORD = 0x2, + + /// 8-bit and 16-bit DMA channel + fDD_BYTE_AND_WORD = 0x3, + + /// Bitmask for the bits within DD_Flags that specify the bus mastering value. + mDD_BusMaster = 0x4, + + /// No bus mastering + fDD_NoBusMaster = 0x0, + + /// Bus mastering + fDD_BusMaster = 0x4, + + /// Bitmask for the bits within DD_Flags that specify the DMA type value. + mDD_Type = 0x18, + + /// Standard DMA + fDD_TypeStandard = 0x00, + + /// Type-A DMA + fDD_TypeA = 0x08, + + /// Type-B DMA + fDD_TypeB = 0x10, + + /// Type-F DMA + fDD_TypeF = 0x18, + } + + /// Flags for . + [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32.IO_Des_s")] + [Flags] + public enum IO_DES_FLAGS : uint + { + /// Bitmask for the bits within IOD_DesFlags that specify the port type value. + fIOD_PortType = 0x1, + + /// The device is accessed in memory address space. + fIOD_Memory = 0x0, + + /// The device is accessed in I/O address space. + fIOD_IO = 0x1, + + /// Bitmask for the bits within IOD_DesFlags that specify the decode value. + fIOD_DECODE = 0x00fc, + + /// The device decodes 10 bits of the port address. + fIOD_10_BIT_DECODE = 0x0004, + + /// The device decodes 12 bits of the port address. + fIOD_12_BIT_DECODE = 0x0008, + + /// The device decodes 16 bits of the port address. + fIOD_16_BIT_DECODE = 0x0010, + + /// The device uses "positive decode" instead of "subtractive decode." + fIOD_POSITIVE_DECODE = 0x0020, + + /// + fIOD_PASSIVE_DECODE = 0x0040, + + /// + fIOD_WINDOW_DECODE = 0x0080, + + /// + fIOD_PORT_BAR = 0x0100, + } + + /// Flags for + [Flags] + public enum IRQD_FLAGS : ushort + { + /// Bitmask,whether the IRQ may be shared: + mIRQD_Share = 0x1, + + /// The IRQ may not be shared + fIRQD_Exclusive = 0x0, + + /// The IRQ may be shared + fIRQD_Share = 0x1, + + /// Bitmask,whether edge or level triggered: + mIRQD_Edge_Level = 0x2, + + /// The IRQ is level-sensitive + fIRQD_Level = 0x0, + + /// The IRQ is edge-sensitive + fIRQD_Edge = 0x2, + } + + /// Flags for + [PInvokeData("cfgmgr32.h", MSDNShortId = "NS:cfgmgr32.Mem_Des_s")] + [Flags] + public enum MEM_DES_FLAGS : uint + { + /// Bitmask, whether memory is writable + mMD_MemoryType = 0x1, + + /// Memory range is read-only + fMD_ROM = 0x0, + + /// Memory range may be written to + fMD_RAM = 0x1, + + /// Bitmask, memory is 24 or 32-bit + mMD_32_24 = 0x2, + + /// Memory range is 24-bit + fMD_24 = 0x0, + + /// Memory range is 32-bit + fMD_32 = 0x2, + + /// Bitmask,whether memory prefetchable + mMD_Prefetchable = 0x4, + + /// Memory range is not prefetchable + fMD_PrefetchDisallowed = 0x0, + + /// Memory range is prefetchable + fMD_PrefetchAllowed = 0x4, + + /// Bitmask,whether memory is readable + mMD_Readable = 0x8, + + /// Memory range is readable + fMD_ReadAllowed = 0x0, + + /// Memory range is write-only + fMD_ReadDisallowed = 0x8, + + /// Bitmask,supports write-behind + mMD_CombinedWrite = 0x10, + + /// no combined-write caching + fMD_CombinedWriteDisallowed = 0x0, + + /// supports combined-write caching + fMD_CombinedWriteAllowed = 0x10, + + /// Bitmask,whether memory is cacheable + mMD_Cacheable = 0x20, + + /// Memory range is non-cacheable + fMD_NonCacheable = 0x0, + + /// Memory range is cacheable + fMD_Cacheable = 0x20, + + /// Memory range is bridge window decode. + fMD_WINDOW_DECODE = 0x40, + + /// Memory BAR resource. + fMD_MEMORY_BAR = 0x80, + } + + /// Flags for + [Flags] + public enum MFCARD_DES_FLAGS : uint + { + /// Bitmask, whether audio is enabled or not + mPMF_AUDIO_ENABLE = 0x8, + + /// Audio is enabled + fPMF_AUDIO_ENABLE = 0x8, + } + + /// Flags for . + [Flags] + public enum PCD_FLAGS : uint + { + /// Bitmask, whether I/O is 8 or 16 bits + mPCD_IO_8_16 = 0x1, + + /// I/O is 8-bit + fPCD_IO_8 = 0x0, + + /// I/O is 16-bit + fPCD_IO_16 = 0x1, + + /// Bitmask, whether MEM is 8 or 16 bits + mPCD_MEM_8_16 = 0x2, + + /// MEM is 8-bit + fPCD_MEM_8 = 0x0, + + /// MEM is 16-bit + fPCD_MEM_16 = 0x2, + + /// Bitmask, whether MEMx is Attribute or Common + mPCD_MEM_A_C = 0xC, + + /// MEM1 is Attribute + fPCD_MEM1_A = 0x4, + + /// MEM2 is Attribute + fPCD_MEM2_A = 0x8, + + /// zero wait on 8 bit I/O + fPCD_IO_ZW_8 = 0x10, + + /// iosrc 16 + fPCD_IO_SRC_16 = 0x20, + + /// wait states on 16 bit io + fPCD_IO_WS_16 = 0x40, + + /// Bitmask, for additional wait states on memory windows + mPCD_MEM_WS = 0x300, + + /// 1 wait state + fPCD_MEM_WS_ONE = 0x100, + + /// 2 wait states + fPCD_MEM_WS_TWO = 0x200, + + /// 3 wait states + fPCD_MEM_WS_THREE = 0x300, + + /// MEM is Attribute + fPCD_MEM_A = 0x4, + + /// + fPCD_ATTRIBUTES_PER_WINDOW = 0x8000, + + /// I/O window 1 is 16-bit + fPCD_IO1_16 = 0x00010000, + + /// I/O window 1 zero wait on 8 bit I/O + fPCD_IO1_ZW_8 = 0x00020000, + + /// I/O window 1 iosrc 16 + fPCD_IO1_SRC_16 = 0x00040000, + + /// I/O window 1 wait states on 16 bit io + fPCD_IO1_WS_16 = 0x00080000, + + /// I/O window 2 is 16-bit + fPCD_IO2_16 = 0x00100000, + + /// I/O window 2 zero wait on 8 bit I/O + fPCD_IO2_ZW_8 = 0x00200000, + + /// I/O window 2 iosrc 16 + fPCD_IO2_SRC_16 = 0x00400000, + + /// I/O window 2 wait states on 16 bit io + fPCD_IO2_WS_16 = 0x00800000, + + /// MEM window 1 Bitmask, for additional wait states on memory windows + mPCD_MEM1_WS = 0x03000000, + + /// MEM window 1, 1 wait state + fPCD_MEM1_WS_ONE = 0x01000000, + + /// MEM window 1, 2 wait states + fPCD_MEM1_WS_TWO = 0x02000000, + + /// MEM window 1, 3 wait states + fPCD_MEM1_WS_THREE = 0x03000000, + + /// MEM window 1 is 16-bit + fPCD_MEM1_16 = 0x04000000, + + /// MEM window 2 Bitmask, for additional wait states on memory windows + mPCD_MEM2_WS = 0x30000000, + + /// MEM window 2, 1 wait state + fPCD_MEM2_WS_ONE = 0x10000000, + + /// MEM window 2, 2 wait states + fPCD_MEM2_WS_TWO = 0x20000000, + + /// MEM window 2, 3 wait states + fPCD_MEM2_WS_THREE = 0x30000000, + + /// MEM window 2 is 16-bit + fPCD_MEM2_16 = 0x40000000, + } + + /// Specifies how the registry key is to be opened. + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Open_Class_KeyW")] + public enum REGDISPOSITION + { + /// Open the key if it exists. Otherwise, create the key. + RegDisposition_OpenAlways = 0x00000000, + + /// Open the key only if it exists. + RegDisposition_OpenExisting = 0x00000001, + } + + /// + /// The CM_Get_Sibling function obtains a device instance handle to the next sibling node of a specified device node + /// (devnode) in the local machine's device tree. + /// + /// + /// Caller-supplied pointer to the device instance handle to the sibling node that this function retrieves. The retrieved handle is + /// bound to the local machine. + /// + /// Caller-supplied device instance handle that is bound to the local machine. + /// Not used, must be zero. + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h. + /// + /// + /// + /// To enumerate all children of a devnode in the local machine's device tree, first call CM_Get_Child to obtain a handle to the + /// first child node, then call CM_Get_Sibling to obtain handles for the rest of the children. + /// + /// For information about using device instance handles that are bound to the local machine, see CM_Get_Child. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_get_sibling CMAPI CONFIGRET CM_Get_Sibling( PDEVINST + // pdnDevInst, DEVINST dnDevInst, ULONG ulFlags ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Get_Sibling")] + public static extern CONFIGRET CM_Get_Sibling(out uint pdnDevInst, uint dnDevInst, uint ulFlags = 0); + + /// + /// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated. Please use CM_Get_Sibling instead.] + /// + /// The CM_Get_Sibling_Ex function obtains a device instance handle to the next sibling node of a specified device node, in a + /// local or a remote machine's device tree. + /// + /// + /// + /// Caller-supplied pointer to the device instance handle to the sibling node that this function retrieves. The retrieved handle is + /// bound to the machine handle specified by hMachine. + /// + /// Caller-supplied device instance handle that is bound to the machine handle specified by hMachine. + /// Not used, must be zero. + /// + /// Caller-supplied machine handle to which the caller-supplied device instance handle is bound. + /// + /// Note Using this function to access remote machines is not supported beginning with Windows 8 and Windows Server 2012, as + /// this functionality has been removed. + /// + /// + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h. + /// + /// + /// + /// To enumerate all children of a device node in the local machine's device tree, first call CM_Get_Child_Ex to obtain a handle to + /// the first child node, then call CM_Get_Sibling_Ex to obtain handles for the rest of the children. + /// + /// For information about using device instance handles that are bound to a local or a remote machine, see CM_Get_Child_Ex. + /// + /// Functionality to access remote machines has been removed in Windows 8 and Windows Server 2012 and later operating systems thus + /// you cannot access remote machines when running on these versions of Windows. + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_get_sibling_ex CMAPI CONFIGRET CM_Get_Sibling_Ex( + // PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Get_Sibling_Ex")] + public static extern CONFIGRET CM_Get_Sibling_Ex(out uint pdnDevInst, uint dnDevInst, [In, Optional] uint ulFlags, [In, Optional] HMACHINE hMachine); + + /// + /// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated and should not be used.] + /// + /// The CM_Get_Version function returns version 4.0 of the Plug and Play (PnP) Configuration Manager DLL (Cfgmgr32.dll) for a + /// local machine. + /// + /// + /// + /// If the function succeeds, it returns the major revision number in the high-order byte, and the minor revision number in the + /// low-order byte. Version 4.0 is returned as 0x0400. By default, version 4.0 is supported by Microsoft Windows 2000 and later + /// versions of Windows. If an internal error occurs, the function returns 0x0000. Call GetLastError to obtain the error code for + /// the failure. + /// + /// + /// + /// This function returns version 4.0 of the configuration manager to ensure compatibility with version 4.0 and all later versions + /// of the configuration manager, and to ensure compatibility with all applications that require version 4.0 of the configuration manager. + /// + /// + /// To determine if a specific version of the configuration manager is available on a machine, use CM_Is_Version_Available or CM_Is_Version_Available_Ex. + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_get_version CMAPI WORD CM_Get_Version(); + [DllImport(Lib_Cfgmgr32, SetLastError = true, ExactSpelling = true)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Get_Version")] + public static extern ushort CM_Get_Version(); + + /// + /// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated and should not be used.] + /// + /// The CM_Get_Version_Ex function returns version 4.0 of the Plug and Play (PnP) Configuration Manager DLL (Cfgmgr32.dll) + /// for a local or a remote machine. + /// + /// + /// + /// Supplies a machine handle that is returned by CM_Connect_Machine. + /// + /// Note Using this function to access remote machines is not supported beginning with Windows 8 and Windows Server 2012, as + /// this functionality has been removed. + /// + /// + /// + /// If the function succeeds, it returns the major revision number in the high-order byte and the minor revision number in the + /// low-order byte. Version 4.0 is returned as 0x0400. By default, version 4.0 is supported by Microsoft Windows 2000 and later + /// versions of Windows. If an internal error occurs, the function returns 0x0000. Call GetLastError to obtain the error code for + /// the failure. + /// + /// + /// + /// This function returns version 4.0 of the configuration manager to ensure compatibility with version 4.0 and all later versions + /// of the configuration manager, and to ensure compatibility with all applications that require version 4.0 of the configuration manager. + /// + /// + /// To determine if a specific version of the configuration manager is available on a machine, use CM_Is_Version_Available or CM_Is_Version_Available_Ex. + /// + /// + /// Functionality to access remote machines has been removed in Windows 8 and Windows Server 2012 and later operating systems thus + /// you cannot access remote machines when running on these versions of Windows. + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_get_version_ex CMAPI WORD CM_Get_Version_Ex( HMACHINE + // hMachine ); + [DllImport(Lib_Cfgmgr32, SetLastError = true, ExactSpelling = true)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Get_Version_Ex")] + public static extern ushort CM_Get_Version_Ex([In, Optional] HMACHINE hMachine); + + /// The CM_Is_Dock_Station_Present function identifies whether a docking station is present in a local machine. + /// + /// Pointer to a Boolean value that indicates whether a docking station is present in a local machine. The function sets *pbPresent + /// to TRUE if a docking station is present. Otherwise, the function sets *pbPresent to FALSE. + /// + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, the function returns one of the CR_-prefixed error codes + /// that are defined in Cfgmgr32.h. + /// + /// + /// + /// Use this function to determine whether a docking station is present in a local machine. You can also use the following related + /// functions with docking stations: + /// + /// + /// + /// + /// CM_Is_Dock_Station_Present_Ex identifies whether a docking station is present in a local or a remote machine. + /// + /// + /// + /// + /// CM_Request_Eject_PC requests that a portable PC, which is inserted in a local docking station, be ejected. + /// + /// + /// + /// + /// CM_Request_Eject_PC_Ex requests that a portable PC, which is inserted in a local or a remote docking station, be ejected. + /// + /// + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_is_dock_station_present CMAPI CONFIGRET + // CM_Is_Dock_Station_Present( PBOOL pbPresent ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Is_Dock_Station_Present")] + public static extern CONFIGRET CM_Is_Dock_Station_Present([MarshalAs(UnmanagedType.Bool)] out bool pbPresent); + + /// + /// + /// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated. Please use CM_Is_Dock_Station_Present instead.] + /// + /// + /// The CM_Is_Dock_Station_Present_Ex function identifies whether a docking station is present in a local or a remote machine. + /// + /// + /// + /// Pointer to a Boolean value that indicates whether a docking station is present in a local machine. The function sets *pbPresent + /// to TRUE if a docking station is present. The function sets *pbPresent to FALSE if the function cannot connect to + /// the specified machine or a docking station is not present. + /// + /// + /// Supplies a machine handle that is returned by CM_Connect_Machine. + /// + /// Note Using this function to access remote machines is not supported beginning with Windows 8 and Windows Server 2012, as + /// this functionality has been removed. + /// + /// + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, the function returns one of the CR_-prefixed error codes + /// that are defined in Cfgmgr32.h. + /// + /// + /// + /// Use this function to determine whether a docking station is present in a local or a remote machine. You can also use the + /// following related functions with docking stations: + /// + /// + /// + /// + /// CM_Is_Dock_Station_Present identifies whether a docking station is present in a local machine. + /// + /// + /// + /// + /// CM_Request_Eject_PC requests that a portable PC, which is inserted in a local docking station, be ejected. + /// + /// + /// + /// + /// CM_Request_Eject_PC_Ex requests that a portable PC, which is inserted in a local or a remote docking station, be ejected. + /// + /// + /// + /// + /// Functionality to access remote machines has been removed in Windows 8 and Windows Server 2012 and later operating systems thus + /// you cannot access remote machines when running on these versions of Windows. + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_is_dock_station_present_ex CMAPI CONFIGRET + // CM_Is_Dock_Station_Present_Ex( PBOOL pbPresent, HMACHINE hMachine ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Is_Dock_Station_Present_Ex")] + public static extern CONFIGRET CM_Is_Dock_Station_Present_Ex([MarshalAs(UnmanagedType.Bool)] out bool pbPresent, [In, Optional] HMACHINE hMachine); + + /// + /// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated and should not be used.] + /// + /// The CM_Is_Version_Available function indicates whether a specified version of the Plug and Play (PnP) Configuration + /// Manager DLL (Cfgmgr32.dll) is supported by a local machine. + /// + /// + /// + /// + /// Identifies a version of the configuration manager. The supported version of the configuration manager corresponds directly to + /// the operating system version. The major version is specified by the high-order byte and the minor version is specified by the + /// low-order byte. + /// + /// + /// For example, 0x0400 specifies version 4.0, which is supported by default by Microsoft Windows 2000 and later versions of + /// Windows. 0x0501 specifies version 5.1, which is supported by Windows XP and later versions of Windows. + /// + /// + /// + /// The function returns TRUE if the local machine supports the specified version of the configuration manager. Otherwise, + /// the function returns FALSE. + /// + /// + /// Use this function to determine whether a specified version of the configuration manager is supported by a local machine. If the + /// specified version is supported, all versions earlier and including this version are supported by the machine. You can also use + /// CM_Is_Version_Available_Ex to determine if a local or a remote machine supports a specific version of the configuration manager. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_is_version_available CMAPI BOOL + // CM_Is_Version_Available( WORD wVersion ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Is_Version_Available")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool CM_Is_Version_Available(ushort wVersion); + + /// + /// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated and should not be used.] + /// + /// The CM_Is_Version_Available_Ex function indicates whether a specified version of the Plug and Play (PNP) Configuration + /// Manager DLL (Cfgmgr32.dll) is supported by a local or a remote machine. + /// + /// + /// + /// Identifies a version of the configuration manager. The supported version of the configuration manager corresponds directly to + /// the operating system version. The major version is specified by the high-order byte and the minor version is specified by the + /// low-order byte. For example, 0x0400 specifies version 4.0, which is supported by default by Microsoft Windows NT 4.0 and later + /// versions of Windows. Version 0x0501 specifies version 5.1, which is supported by Windows XP and later versions of Windows. + /// + /// + /// Supplies a machine handle that is returned by CM_Connect_Machine. + /// + /// Note Using this function to access remote machines is not supported beginning with Windows 8 and Windows Server 2012, as + /// this functionality has been removed. + /// + /// + /// + /// The function returns TRUE if the function can connect to the specified machine and if the machine supports the specified + /// version. Otherwise, the function returns FALSE. + /// + /// + /// + /// Use this function to determine whether a specified version of the configuration manager is supported by a local or a remote + /// machine. If the specified version is supported, all versions earlier and including this version are supported by the machine. + /// You can also use CM_Is_Version_Available to determine if the local machine supports a specific version of the configuration manager. + /// + /// + /// Functionality to access remote machines has been removed in Windows 8 and Windows Server 2012 and later operating systems thus + /// you cannot access remote machines when running on these versions of Windows. + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_is_version_available_ex CMAPI BOOL + // CM_Is_Version_Available_Ex( WORD wVersion, HMACHINE hMachine ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Is_Version_Available_Ex")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool CM_Is_Version_Available_Ex(ushort wVersion, [In, Optional] HMACHINE hMachine); + + /// + /// The CM_Locate_DevNode function obtains a device instance handle to the device node that is associated with a specified + /// device instance ID on the local machine. + /// + /// + /// A pointer to a device instance handle that CM_Locate_DevNode retrieves. The retrieved handle is bound to the local machine. + /// + /// + /// A pointer to a NULL-terminated string representing a device instance ID. If this value is NULL, or if it points to a + /// zero-length string, the function retrieves a device instance handle to the device at the root of the device tree. + /// + /// + /// + /// A variable of ULONG type that supplies one of the following flag values that apply if the caller supplies a device instance identifier: + /// + /// CM_LOCATE_DEVNODE_NORMAL + /// + /// The function retrieves the device instance handle for the specified device only if the device is currently configured in the + /// device tree. + /// + /// CM_LOCATE_DEVNODE_PHANTOM + /// + /// The function retrieves a device instance handle for the specified device if the device is currently configured in the device + /// tree or the device is a nonpresent device that is not currently configured in the device tree. + /// + /// CM_LOCATE_DEVNODE_CANCELREMOVE + /// + /// The function retrieves a device instance handle for the specified device if the device is currently configured in the device + /// tree or in the process of being removed from the device tree. If the device is in the process of being removed, the function + /// cancels the removal of the device. + /// + /// CM_LOCATE_DEVNODE_NOVALIDATION + /// Not used. + /// + /// + /// If the operation succeeds, CM_Locate_DevNode returns CR_SUCCESS. Otherwise, the function returns one of the CR_Xxx error + /// codes that are defined in Cfgmgr32.h. + /// + /// + /// For information about using device instance handles that are bound to the local machine, see CM_Get_Child. + /// + /// Note + /// + /// The cfgmgr32.h header defines CM_Locate_DevNode as an alias which automatically selects the ANSI or Unicode version of this + /// function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that + /// not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions + /// for Function Prototypes. + /// + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_locate_devnodea CMAPI CONFIGRET CM_Locate_DevNodeA( + // PDEVINST pdnDevInst, DEVINSTID_A pDeviceID, ULONG ulFlags ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Auto)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Locate_DevNodeA")] + public static extern CONFIGRET CM_Locate_DevNode(out uint pdnDevInst, [In, Optional, MarshalAs(UnmanagedType.LPTStr)] string pDeviceID, CM_LOCATE_DEVNODE ulFlags = CM_LOCATE_DEVNODE.CM_LOCATE_DEVNODE_NORMAL); + + /// + /// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated. Please use CM_Locate_DevNode instead.] + /// + /// The CM_Locate_DevNode_Ex function obtains a device instance handle to the device node that is associated with a specified + /// device instance ID, on a local machine or a remote machine. + /// + /// + /// + /// A pointer to the device instance handle that this function retrieves. The retrieved handle is bound to the machine handle + /// specified by hMachine. + /// + /// + /// A pointer to a NULL-terminated string representing a device instance ID. If this value is NULL, or if it points to a + /// zero-length string, the function supplies a device instance handle to the device at the root of the device tree. + /// + /// + /// + /// A variable of ULONG type that supplies one of the following flag values that apply if the caller supplies a device instance identifier: + /// + /// CM_LOCATE_DEVNODE_NORMAL + /// + /// The function retrieves the device instance handle for the specified device only if the device is currently configured in the + /// device tree. + /// + /// CM_LOCATE_DEVNODE_PHANTOM + /// + /// The function retrieves a device instance handle for the specified device if the device is currently configured in the device + /// tree or the device is a nonpresent device that is not currently configured in the device tree. + /// + /// CM_LOCATE_DEVNODE_CANCELREMOVE + /// + /// The function retrieves a device instance handle for the specified device if the device is currently configured in the device + /// tree or in the process of being removed for the device tree. If the device is in the process of being removed, the function + /// cancels the removal of the device. + /// + /// CM_LOCATE_DEVNODE_NOVALIDATION + /// Not used. + /// + /// + /// + /// A machine handle obtained from a call to CM_Connect_Machine, or a machine handle to which a device information set is bound. The + /// machine handle for a device information set is obtained from the RemoteMachineHandle member of the + /// SP_DEVINFO_LIST_DETAIL_DATA structure for the device information set. Call SetupDiGetDeviceInfoListDetail to obtain an + /// SP_DEVINFO_LIST_DETAIL_DATA structure. + /// + /// + /// Note Using this function to access remote machines is not supported beginning with Windows 8 and Windows Server 2012, as + /// this functionality has been removed. + /// + /// + /// + /// If the operation succeeds, CM_Locate_DevNode returns CR_SUCCESS. Otherwise, the function returns one of the CR_-prefixed + /// error codes that are defined in Cfgmgr32.h. + /// + /// + /// For information about using device instance handles that are bound to a local or a remote machine, see CM_Get_Child_Ex. + /// + /// Functionality to access remote machines has been removed in Windows 8 and Windows Server 2012 and later operating systems thus + /// you cannot access remote machines when running on these versions of Windows. + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_locate_devnode_exw CMAPI CONFIGRET + // CM_Locate_DevNode_ExW( PDEVINST pdnDevInst, DEVINSTID_W pDeviceID, ULONG ulFlags, HMACHINE hMachine ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Auto)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Locate_DevNode_ExW")] + public static extern CONFIGRET CM_Locate_DevNode_Ex(out uint pdnDevInst, [In, Optional, MarshalAs(UnmanagedType.LPTStr)] string pDeviceID, CM_LOCATE_DEVNODE ulFlags, [In, Optional] HMACHINE hMachine); + + /// Converts a specified CONFIGRET code to its equivalent system error code. + /// The CONFIGRET code to be converted. CONFIGRET error codes are defined in CfgMgr32.h. + /// + /// A default system error code to be returned when no system error code is mapped to the specified CONFIGRET code. + /// + /// + /// The system error code that corresponds to the CONFIGRET code. System error codes are defined in Winerror.h. + /// + /// When there is no mapping from the specified CONFIGRET code to a system error code, CM_MapCrToWin32Err returns the + /// value specified in the DefaultErr parameter. + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_mapcrtowin32err CMAPI DWORD CM_MapCrToWin32Err( + // CONFIGRET CmReturnCode, DWORD DefaultErr ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_MapCrToWin32Err")] + public static extern Win32Error CM_MapCrToWin32Err(CONFIGRET CmReturnCode, uint DefaultErr); + + /// The CM_Modify_Res_Des function modifies a specified resource descriptor on the local machine. + /// Pointer to a location to receive a handle to the modified resource descriptor. + /// + /// + /// Caller-supplied handle to the resource descriptor to be modified. This handle must have been previously obtained by calling one + /// of the following functions: + /// + /// CM_Add_Res_Des + /// CM_Add_Res_Des_Ex + /// CM_Get_Next_Res_Des + /// CM_Get_Next_Res_Des_Ex + /// CM_Modify_Res_Des + /// CM_Modify_Res_Des_Ex + /// + /// + /// Caller-supplied resource type identifier. This must be one of the ResType_-prefixed constants defined in Cfgmgr32.h. + /// + /// + /// Caller-supplied pointer to a resource descriptor, which can be one of the structures listed under the CM_Add_Res_Des function's + /// description of ResourceData. + /// + /// Caller-supplied length of the structure pointed to by ResourceData. + /// Not used, must be zero. + /// + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h. + /// + /// + /// Note Starting with Windows 8, CM_Modify_Res_Des returns CR_CALL_NOT_IMPLEMENTED when used in a Wow64 scenario. To + /// request information about the hardware resources on a local machine it is necessary implement an architecture-native version of + /// the application using the hardware resource APIs. For example: An AMD64 application for AMD64 systems. + /// + /// + /// + /// + /// The caller-supplied resource descriptor data replaces the existing data. The values specified for ResourceID and ResourceLen do + /// not have to match the existing resource descriptor. + /// + /// + /// If the value specified for ResourceID is ResType_ClassSpecific, then the specified resource descriptor must be the last + /// one associated with the logical configuration. + /// + /// + /// Callers of CM_Modify_Res_Des must call CM_Free_Res_Des_Handle to deallocate the resource descriptor handle, after it is + /// no longer needed. + /// + /// + /// Callers of this function must have SeLoadDriverPrivilege. (Privileges are described in the Microsoft Windows SDK documentation.) + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_modify_res_des CMAPI CONFIGRET CM_Modify_Res_Des( + // PRES_DES prdResDes, RES_DES rdResDes, RESOURCEID ResourceID, PCVOID ResourceData, ULONG ResourceLen, ULONG ulFlags ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Modify_Res_Des")] + public static extern CONFIGRET CM_Modify_Res_Des(out SafeRES_DES prdResDes, RES_DES rdResDes, RESOURCEID ResourceID, [In] IntPtr ResourceData, uint ResourceLen, uint ulFlags = 0); + + /// + /// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated. Please use CM_Modify_Res_Des instead.] + /// The CM_Modify_Res_Des_Ex function modifies a specified resource descriptor on a local or a remote machine. + /// + /// Pointer to a location to receive a handle to the modified resource descriptor. + /// + /// + /// Caller-supplied handle to the resource descriptor to be modified. This handle must have been previously obtained by calling one + /// of the following functions: + /// + /// CM_Add_Res_Des + /// CM_Add_Res_Des_Ex + /// CM_Get_Next_Res_Des + /// CM_Get_Next_Res_Des_Ex + /// CM_Modify_Res_Des + /// CM_Modify_Res_Des_Ex + /// + /// + /// Caller-supplied resource type identifier. This must be one of the ResType_-prefixed constants defined in Cfgmgr32.h. + /// + /// + /// Caller-supplied pointer to a resource descriptor, which can be one of the structures listed under the CM_Add_Res_Des_Ex + /// function's description of ResourceData. + /// + /// Caller-supplied length of the structure pointed to by ResourceData. + /// Not used, must be zero. + /// + /// Caller-supplied machine handle, obtained from a previous call to CM_Connect_Machine. + /// + /// Note Using this function to access remote machines is not supported beginning with Windows 8 and Windows Server 2012, as + /// this functionality has been removed. + /// + /// + /// + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h. + /// + /// + /// Note Starting with Windows 8, CM_Modify_Res_Des_Ex returns CR_CALL_NOT_IMPLEMENTED when used in a Wow64 scenario. + /// To request information about the hardware resources on a local machine it is necessary implement an architecture-native version + /// of the application using the hardware resource APIs. For example: An AMD64 application for AMD64 systems. + /// + /// + /// + /// + /// The caller-supplied resource descriptor data replaces the existing data. The values specified for ResourceID and ResourceLen do + /// not have to match the existing resource descriptor. + /// + /// + /// If the value specified for ResourceID is ResType_ClassSpecific, then the specified resource descriptor must be the last + /// one associated with the logical configuration. + /// + /// + /// Callers of CM_Modify_Res_Des_Ex must call CM_Free_Res_Des_Handle to deallocate the resource descriptor handle, after it + /// is no longer needed. + /// + /// + /// Callers of this function must have SeLoadDriverPrivilege. (Privileges are described in the Microsoft Windows SDK documentation.) + /// + /// + /// Functionality to access remote machines has been removed in Windows 8 and Windows Server 2012 and later operating systems thus + /// you cannot access remote machines when running on these versions of Windows. + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_modify_res_des_ex CMAPI CONFIGRET + // CM_Modify_Res_Des_Ex( PRES_DES prdResDes, RES_DES rdResDes, RESOURCEID ResourceID, PCVOID ResourceData, ULONG ResourceLen, ULONG + // ulFlags, HMACHINE hMachine ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Modify_Res_Des_Ex")] + public static extern CONFIGRET CM_Modify_Res_Des_Ex(out SafeRES_DES prdResDes, RES_DES rdResDes, RESOURCEID ResourceID, [In] IntPtr ResourceData, uint ResourceLen, [In, Optional] uint ulFlags, + [In, Optional] HMACHINE hMachine); + + /// + /// The CM_Open_Class_Key function opens the device setup class registry key, the device interface class registry key, or a + /// specific subkey of a class. + /// + /// + /// Pointer to the GUID of the class whose registry key is to be opened. This parameter is optional and can be NULL. If this + /// parameter is NULL, the root of the class tree is opened. + /// + /// Reserved. Must be set to NULL. + /// The registry security access for the key to be opened. + /// + /// Specifies how the registry key is to be opened. May be one of the following values: + /// RegDisposition_OpenAlways + /// Open the key if it exists. Otherwise, create the key. + /// RegDisposition_OpenExisting + /// Open the key only if it exists. + /// + /// Pointer to an HKEY that will receive the opened key upon success. + /// + /// Open class key flags: + /// CM_OPEN_CLASS_KEY_INSTALLER + /// The key to be opened is for a device setup class. + /// CM_OPEN_CLASS_KEY_INTERFACE + /// The key to be opened is for a device interface class. + /// + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h. + /// + /// Close the handle returned from this function by calling RegCloseKey. + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_open_class_keyw CMAPI CONFIGRET CM_Open_Class_KeyW( + // LPGUID ClassGuid, LPCWSTR pszClassName, REGSAM samDesired, REGDISPOSITION Disposition, PHKEY phkClass, ULONG ulFlags ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Auto)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Open_Class_KeyW")] + public static extern CONFIGRET CM_Open_Class_Key(in Guid ClassGuid, [Optional, MarshalAs(UnmanagedType.LPTStr)] string pszClassName, REGSAM samDesired, REGDISPOSITION Disposition, + out SafeRegistryHandle phkClass, CM_OPEN_CLASS_KEY ulFlags); + + /// + /// The CM_Open_Class_Key function opens the device setup class registry key, the device interface class registry key, or a + /// specific subkey of a class. + /// + /// + /// Pointer to the GUID of the class whose registry key is to be opened. This parameter is optional and can be NULL. If this + /// parameter is NULL, the root of the class tree is opened. + /// + /// Reserved. Must be set to NULL. + /// The registry security access for the key to be opened. + /// + /// Specifies how the registry key is to be opened. May be one of the following values: + /// RegDisposition_OpenAlways + /// Open the key if it exists. Otherwise, create the key. + /// RegDisposition_OpenExisting + /// Open the key only if it exists. + /// + /// Pointer to an HKEY that will receive the opened key upon success. + /// + /// Open class key flags: + /// CM_OPEN_CLASS_KEY_INSTALLER + /// The key to be opened is for a device setup class. + /// CM_OPEN_CLASS_KEY_INTERFACE + /// The key to be opened is for a device interface class. + /// + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h. + /// + /// Close the handle returned from this function by calling RegCloseKey. + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_open_class_keyw CMAPI CONFIGRET CM_Open_Class_KeyW( + // LPGUID ClassGuid, LPCWSTR pszClassName, REGSAM samDesired, REGDISPOSITION Disposition, PHKEY phkClass, ULONG ulFlags ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Auto)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Open_Class_KeyW")] + public static extern CONFIGRET CM_Open_Class_Key([In, Optional] InteropServices.GuidPtr ClassGuid, + [Optional, MarshalAs(UnmanagedType.LPTStr)] string pszClassName, REGSAM samDesired, REGDISPOSITION Disposition, + out SafeRegistryHandle phkClass, CM_OPEN_CLASS_KEY ulFlags); + + /// + /// The CM_Open_Device_Interface_Key function opens the registry subkey that is used by applications and drivers to store + /// information that is specific to a device interface. + /// + /// + /// Pointer to a string that identifies the device interface instance to open the registry subkey for. + /// + /// The requested registry security access to the registry subkey. + /// + /// Specifies how the registry key is to be opened. May be one of the following values: + /// RegDisposition_OpenAlways + /// Open the key if it exists. Otherwise, create the key. + /// RegDisposition_OpenExisting + /// Open the key only if it exists. + /// + /// Pointer to an HKEY that will receive the opened key upon success. + /// Reserved. Must be set to zero. + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h. + /// + /// + /// Close the handle returned from this function by calling RegCloseKey. + /// + /// Note + /// + /// The cfgmgr32.h header defines CM_Open_Device_Interface_Key as an alias which automatically selects the ANSI or Unicode version + /// of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with + /// code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see + /// Conventions for Function Prototypes. + /// + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_open_device_interface_keya CMAPI CONFIGRET + // CM_Open_Device_Interface_KeyA( LPCSTR pszDeviceInterface, REGSAM samDesired, REGDISPOSITION Disposition, PHKEY + // phkDeviceInterface, ULONG ulFlags ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Auto)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Open_Device_Interface_KeyA")] + public static extern CONFIGRET CM_Open_Device_Interface_Key([MarshalAs(UnmanagedType.LPTStr)] string pszDeviceInterface, REGSAM samDesired, REGDISPOSITION Disposition, + out SafeRegistryHandle phkDeviceInterface, uint ulFlags = 0); + + /// + /// + /// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated. Please use CM_Open_Device_Interface_Key instead.] + /// + /// + /// The CM_Open_Device_Interface_Key_ExA function opens the registry subkey that is used by applications and drivers to store + /// information that is specific to a device interface. + /// + /// + /// + /// Pointer to a string that identifies the device interface instance to open the registry subkey for. + /// + /// The requested registry security access to the registry subkey. + /// + /// Specifies how the registry key is to be opened. May be one of the following values: + /// RegDisposition_OpenAlways + /// Open the key if it exists. Otherwise, create the key. + /// RegDisposition_OpenExisting + /// Open the key only if it exists. + /// + /// Pointer to an HKEY that will receive the opened key upon success. + /// Reserved. Must be set to zero. + /// + /// Caller-supplied machine handle, obtained from a previous call to CM_Connect_Machine. + /// + /// Note Using this function to access remote machines is not supported beginning with Windows 8 and Windows Server 2012, as + /// this functionality has been removed. + /// + /// + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h. + /// + /// + /// Close the handle returned from this function by calling RegCloseKey. + /// + /// Note + /// + /// The cfgmgr32.h header defines CM_Open_Device_Interface_Key_Ex as an alias which automatically selects the ANSI or Unicode + /// version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral + /// alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more + /// information, see Conventions for Function Prototypes. + /// + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_open_device_interface_key_exa CMAPI CONFIGRET + // CM_Open_Device_Interface_Key_ExA( LPCSTR pszDeviceInterface, REGSAM samDesired, REGDISPOSITION Disposition, PHKEY + // phkDeviceInterface, ULONG ulFlags, HMACHINE hMachine ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Auto)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Open_Device_Interface_Key_ExA")] + public static extern CONFIGRET CM_Open_Device_Interface_Key_Ex([MarshalAs(UnmanagedType.LPTStr)] string pszDeviceInterface, REGSAM samDesired, REGDISPOSITION Disposition, + out SafeRegistryHandle phkDeviceInterface, [In, Optional] uint ulFlags, [In, Optional] HMACHINE hMachine); + + /// The CM_Open_DevNode_Key function opens a registry key for device-specific configuration information. + /// Caller-supplied device instance handle that is bound to the local machine + /// The registry security access that is required for the requested key. + /// + /// The hardware profile to open if ulFlags includes CM_REGISTRY_CONFIG. If this value is zero, the key for the current hardware + /// profile is opened. + /// + /// + /// Specifies how the registry key is to be opened. May be one of the following values: + /// RegDisposition_OpenAlways + /// Open the key if it exists. Otherwise, create the key. + /// RegDisposition_OpenExisting + /// Open the key only if it exists. + /// + /// Pointer to an HKEY that will receive the opened key upon success. + /// + /// + /// Open device node key flags. Indicates the scope and type of registry storage key to open. Can be a combination of the following flags: + /// + /// CM_REGISTRY_HARDWARE + /// Open the device’s hardware key. Do not combine with CM_REGISTRY_SOFTWARE. + /// CM_REGISTRY_SOFTWARE + /// Open the device’s software key. Do not combine with CM_REGISTRY_HARDWARE. + /// CM_REGISTRY_USER + /// Open the per-user key for the current user. Do not combine with CM_REGISTRY_CONFIG. + /// CM_REGISTRY_CONFIG + /// Open the key that stores hardware profile-specific configuration information. Do not combine with CM_REGISTRY_USER. + /// + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h. + /// + /// Close the handle returned from this function by calling RegCloseKey. + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_open_devnode_key CMAPI CONFIGRET CM_Open_DevNode_Key( + // DEVINST dnDevNode, REGSAM samDesired, ULONG ulHardwareProfile, REGDISPOSITION Disposition, PHKEY phkDevice, ULONG ulFlags ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Open_DevNode_Key")] + public static extern CONFIGRET CM_Open_DevNode_Key(uint dnDevNode, REGSAM samDesired, uint ulHardwareProfile, REGDISPOSITION Disposition, out SafeRegistryHandle phkDevice, CM_REGISTRY ulFlags); + + /// + /// The CM_Query_And_Remove_SubTree function checks whether a device instance and its children can be removed and, if so, it + /// removes them. + /// + /// + /// Caller-supplied device instance handle to the device at the root of the subtree to be removed. This device instance handle is + /// bound to the local machine. + /// + /// + /// (Optional) If the caller does not pass NULL and the removal request is vetoed (that is, the function returns + /// CR_REMOVE_VETOED), on return this points to a PNP_VETO_TYPE-typed value that indicates the reason for the veto. + /// + /// + /// (Optional) If the caller does not pass NULL and the removal request is vetoed (that is, the function returns + /// CR_REMOVE_VETOED), on return this points to a text string that is associated with the veto type. The type of information this + /// string provides is dependent on the value received by pVetoType. For information about these strings, see PNP_VETO_TYPE. + /// + /// + /// Caller-supplied value representing the length (number of characters) of the string buffer supplied by pszVetoName. This should + /// be set to MAX_PATH. + /// + /// A bitwise OR of the caller-supplied flag constants that are described in the Remarks section. + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the other CR_-prefixed error codes + /// defined in Cfgmgr32.h. + /// + /// + /// + /// The purpose of the CM_Query_And_Remove_SubTree function is to allow an application to prepare a device for safe removal + /// from the local machine. Use this function to remove devices only if a driver has not set the SurpriseRemovalOK member of + /// DEVICE_CAPABILITIES. If a driver has set SurpriseRemovalOK, the application should call CM_Request_Device_Eject instead + /// of CM_Query_And_Remove_SubTree. + /// + /// + /// CM_Query_And_Remove_SubTree supports setting the flags parameter ulFlags with one of the following two flags; these flags + /// apply only if Windows or an installer vetoes the removal of a device: + /// + /// + /// Beginning with Windows XP, CM_Query_And_Remove_SubTree also supports setting the following additional flag; this flag + /// applies only if the function successfully removes the device instance: + /// + /// + /// Windows applications that do not require the low-level operation CM_Query_And_Remove_SubTree should use the + /// DIF_PROPERTYCHANGE request to disable a device instead of using CM_Query_And_Remove_SubTree to remove a device. The + /// DIF_PROPERTYCHANGE request can be used to enable, disable, restart, stop, or change the properties of a device. + /// + /// + /// Callers of this function must have SeLoadDriverPrivilege. (Privileges are described in the Microsoft Windows SDK documentation.) + /// + /// For information about using device instance handles that are bound to the local machine, see CM_Get_Child. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_query_and_remove_subtreew CMAPI CONFIGRET + // CM_Query_And_Remove_SubTreeW( DEVINST dnAncestor, PPNP_VETO_TYPE pVetoType, LPWSTR pszVetoName, ULONG ulNameLength, ULONG ulFlags ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Auto)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Query_And_Remove_SubTreeW")] + public static extern CONFIGRET CM_Query_And_Remove_SubTree(uint dnAncestor, out PNP_VETO_TYPE pVetoType, [Optional] StringBuilder pszVetoName, uint ulNameLength, CM_REMOVE ulFlags); + + /// + /// The CM_Query_And_Remove_SubTree function checks whether a device instance and its children can be removed and, if so, it + /// removes them. + /// + /// + /// Caller-supplied device instance handle to the device at the root of the subtree to be removed. This device instance handle is + /// bound to the local machine. + /// + /// + /// (Optional) If the caller does not pass NULL and the removal request is vetoed (that is, the function returns + /// CR_REMOVE_VETOED), on return this points to a PNP_VETO_TYPE-typed value that indicates the reason for the veto. + /// + /// + /// (Optional) If the caller does not pass NULL and the removal request is vetoed (that is, the function returns + /// CR_REMOVE_VETOED), on return this points to a text string that is associated with the veto type. The type of information this + /// string provides is dependent on the value received by pVetoType. For information about these strings, see PNP_VETO_TYPE. + /// + /// + /// Caller-supplied value representing the length (number of characters) of the string buffer supplied by pszVetoName. This should + /// be set to MAX_PATH. + /// + /// A bitwise OR of the caller-supplied flag constants that are described in the Remarks section. + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the other CR_-prefixed error codes + /// defined in Cfgmgr32.h. + /// + /// + /// + /// The purpose of the CM_Query_And_Remove_SubTree function is to allow an application to prepare a device for safe removal + /// from the local machine. Use this function to remove devices only if a driver has not set the SurpriseRemovalOK member of + /// DEVICE_CAPABILITIES. If a driver has set SurpriseRemovalOK, the application should call CM_Request_Device_Eject instead + /// of CM_Query_And_Remove_SubTree. + /// + /// + /// CM_Query_And_Remove_SubTree supports setting the flags parameter ulFlags with one of the following two flags; these flags + /// apply only if Windows or an installer vetoes the removal of a device: + /// + /// + /// Beginning with Windows XP, CM_Query_And_Remove_SubTree also supports setting the following additional flag; this flag + /// applies only if the function successfully removes the device instance: + /// + /// + /// Windows applications that do not require the low-level operation CM_Query_And_Remove_SubTree should use the + /// DIF_PROPERTYCHANGE request to disable a device instead of using CM_Query_And_Remove_SubTree to remove a device. The + /// DIF_PROPERTYCHANGE request can be used to enable, disable, restart, stop, or change the properties of a device. + /// + /// + /// Callers of this function must have SeLoadDriverPrivilege. (Privileges are described in the Microsoft Windows SDK documentation.) + /// + /// For information about using device instance handles that are bound to the local machine, see CM_Get_Child. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_query_and_remove_subtreew CMAPI CONFIGRET + // CM_Query_And_Remove_SubTreeW( DEVINST dnAncestor, PPNP_VETO_TYPE pVetoType, LPWSTR pszVetoName, ULONG ulNameLength, ULONG ulFlags ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Auto)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Query_And_Remove_SubTreeW")] + public static extern CONFIGRET CM_Query_And_Remove_SubTree(uint dnAncestor, [In, Optional] IntPtr pVetoType, [Optional] StringBuilder pszVetoName, uint ulNameLength, CM_REMOVE ulFlags); + + /// + /// + /// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated. Please use CM_Query_And_Remove_SubTree instead.] + /// + /// + /// The CM_Query_And_Remove_SubTree_Ex function checks whether a device instance and its children can be removed and, if so, + /// it removes them. + /// + /// + /// + /// Caller-supplied device instance handle to the device at the root of the subtree to be removed. This device instance handle is + /// bound to the machine handle supplied by hMachine. + /// + /// + /// (Optional) If the caller does not pass NULL and the removal request is vetoed (that is, the function returns + /// CR_REMOVE_VETOED), on return this points to a PNP_VETO_TYPE-typed value that indicates the reason for the veto. + /// + /// + /// (Optional) If the caller does not pass NULL and the removal request is vetoed (that is, the function returns + /// CR_REMOVE_VETOED), on return this points to a text string that is associated with the veto type. The type of information this + /// string provides is dependent on the value received by pVetoType. For information about these strings, see PNP_VETO_TYPE. + /// + /// + /// (Optional.) Caller-supplied value representing the length (number of characters) of the string buffer supplied by pszVetoName. + /// This should be set to MAX_PATH. + /// + /// A bitwise OR of the caller-supplied flag constants that are described in the Remarks section. + /// + /// Caller-supplied machine handle to which the caller-supplied device instance handle is bound. + /// + /// Note Using this function to access remote machines is not supported beginning with Windows 8 and Windows Server 2012, as + /// this functionality has been removed. + /// + /// + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h. + /// + /// + /// + /// The purpose of the CM_Query_And_Remove_SubTree_Ex function is to allow an application to prepare a device for safe + /// removal from a remote machine. Use this function to remove devices only if a driver has not set the SurpriseRemovalOK + /// member of DEVICE_CAPABILITIES. If a driver has set SurpriseRemovalOK, the application should call + /// CM_Request_Device_Eject_Ex instead of CM_Query_And_Remove_SubTree_Ex. + /// + /// + /// CM_Query_And_Remove_SubTree_Ex supports setting the flags parameter ulFlags with one of the following two flags; these + /// flags apply only if Windows or an installer vetoes the removal of a device: + /// + /// + /// Beginning with Windows XP, CM_Query_And_Remove_SubTree_Ex also supports setting the following additional flag; this flag + /// applies only if the function successfully removes the device instance: + /// + /// + /// Device installation applications that do not require the low-level operation of CM_Query_And_Remove_SubTree_Ex should use + /// the DIF_PROPERTYCHANGE request to disable a device instead of using CM_Query_And_Remove_SubTree_Ex to remove a device. + /// The DIF_PROPERTYCHANGE request can be used to enable, disable, restart, stop, or change the properties of a device. + /// + /// + /// Callers of this function must have SeLoadDriverPrivilege. (Privileges are described in the Microsoft Windows SDK documentation.) + /// + /// For information about using device instance handles that are bound to a local or a remote machine, see CM_Get_Child_Ex. + /// + /// Functionality to access remote machines has been removed in Windows 8 and Windows Server 2012 and later operating systems thus + /// you cannot access remote machines when running on these versions of Windows. + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_query_and_remove_subtree_exw CMAPI CONFIGRET + // CM_Query_And_Remove_SubTree_ExW( DEVINST dnAncestor, PPNP_VETO_TYPE pVetoType, LPWSTR pszVetoName, ULONG ulNameLength, ULONG + // ulFlags, HMACHINE hMachine ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Auto)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Query_And_Remove_SubTree_ExW")] + public static extern CONFIGRET CM_Query_And_Remove_SubTree_Ex(uint dnAncestor, out PNP_VETO_TYPE pVetoType, [Optional] StringBuilder pszVetoName, uint ulNameLength, CM_REMOVE ulFlags, [In, Optional] HMACHINE hMachine); + + /// + /// + /// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated. Please use CM_Query_And_Remove_SubTree instead.] + /// + /// + /// The CM_Query_And_Remove_SubTree_Ex function checks whether a device instance and its children can be removed and, if so, + /// it removes them. + /// + /// + /// + /// Caller-supplied device instance handle to the device at the root of the subtree to be removed. This device instance handle is + /// bound to the machine handle supplied by hMachine. + /// + /// + /// (Optional) If the caller does not pass NULL and the removal request is vetoed (that is, the function returns + /// CR_REMOVE_VETOED), on return this points to a PNP_VETO_TYPE-typed value that indicates the reason for the veto. + /// + /// + /// (Optional) If the caller does not pass NULL and the removal request is vetoed (that is, the function returns + /// CR_REMOVE_VETOED), on return this points to a text string that is associated with the veto type. The type of information this + /// string provides is dependent on the value received by pVetoType. For information about these strings, see PNP_VETO_TYPE. + /// + /// + /// (Optional.) Caller-supplied value representing the length (number of characters) of the string buffer supplied by pszVetoName. + /// This should be set to MAX_PATH. + /// + /// A bitwise OR of the caller-supplied flag constants that are described in the Remarks section. + /// + /// Caller-supplied machine handle to which the caller-supplied device instance handle is bound. + /// + /// Note Using this function to access remote machines is not supported beginning with Windows 8 and Windows Server 2012, as + /// this functionality has been removed. + /// + /// + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h. + /// + /// + /// + /// The purpose of the CM_Query_And_Remove_SubTree_Ex function is to allow an application to prepare a device for safe + /// removal from a remote machine. Use this function to remove devices only if a driver has not set the SurpriseRemovalOK + /// member of DEVICE_CAPABILITIES. If a driver has set SurpriseRemovalOK, the application should call + /// CM_Request_Device_Eject_Ex instead of CM_Query_And_Remove_SubTree_Ex. + /// + /// + /// CM_Query_And_Remove_SubTree_Ex supports setting the flags parameter ulFlags with one of the following two flags; these + /// flags apply only if Windows or an installer vetoes the removal of a device: + /// + /// + /// Beginning with Windows XP, CM_Query_And_Remove_SubTree_Ex also supports setting the following additional flag; this flag + /// applies only if the function successfully removes the device instance: + /// + /// + /// Device installation applications that do not require the low-level operation of CM_Query_And_Remove_SubTree_Ex should use + /// the DIF_PROPERTYCHANGE request to disable a device instead of using CM_Query_And_Remove_SubTree_Ex to remove a device. + /// The DIF_PROPERTYCHANGE request can be used to enable, disable, restart, stop, or change the properties of a device. + /// + /// + /// Callers of this function must have SeLoadDriverPrivilege. (Privileges are described in the Microsoft Windows SDK documentation.) + /// + /// For information about using device instance handles that are bound to a local or a remote machine, see CM_Get_Child_Ex. + /// + /// Functionality to access remote machines has been removed in Windows 8 and Windows Server 2012 and later operating systems thus + /// you cannot access remote machines when running on these versions of Windows. + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_query_and_remove_subtree_exw CMAPI CONFIGRET + // CM_Query_And_Remove_SubTree_ExW( DEVINST dnAncestor, PPNP_VETO_TYPE pVetoType, LPWSTR pszVetoName, ULONG ulNameLength, ULONG + // ulFlags, HMACHINE hMachine ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Auto)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Query_And_Remove_SubTree_ExW")] + public static extern CONFIGRET CM_Query_And_Remove_SubTree_Ex(uint dnAncestor, [In, Optional] IntPtr pVetoType, [Optional] StringBuilder pszVetoName, uint ulNameLength, CM_REMOVE ulFlags, [In, Optional] HMACHINE hMachine); + + /// + /// The CM_Query_Resource_Conflict_List function identifies device instances having resource requirements that conflict with + /// a specified device instance's resource description. + /// + /// Caller-supplied address of a location to receive a handle to a conflict list. + /// Caller-supplied device instance handle that is bound to the machine handle supplied by hMachine. + /// + /// Caller-supplied resource type identifier. This must be one of the ResType_-prefixed constants defined in Cfgmgr32.h. + /// + /// + /// Caller-supplied pointer to a resource descriptor, which can be one of the structures listed under the CM_Add_Res_Des function's + /// description of ResourceData. + /// + /// Caller-supplied length of the structure pointed to by ResourceData. + /// Not used, must be zero. + /// Caller-supplied machine handle to which the caller-supplied device instance handle is bound. + /// + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h. + /// + /// + /// Note Starting with Windows 8, CM_Query_Resource_Conflict_List returns CR_CALL_NOT_IMPLEMENTED when used in a Wow64 + /// scenario. To request information about the hardware resources on a local machine it is necessary implement an + /// architecture-native version of the application using the hardware resource APIs. For example: An AMD64 application for AMD64 systems. + /// + /// + /// + /// + /// When calling CM_Query_Resource_Conflict_List, specify a device instance handle and resource descriptor. (Resource + /// descriptors for existing device nodes can be obtained by calling CM_Get_Res_Des_Data.) These parameters indicate the specific + /// resources you'd like a specific device to use. The resulting conflict list identifies devices that use the same resources, along + /// with resources reserved by the machine. + /// + /// + /// After calling CM_Query_Resource_Conflict_List, an application can call CM_Get_Resource_Conflict_Count to determine the + /// number of conflicts contained in the resource conflict list. (The number of conflicts can be zero.) Then the application can + /// call CM_Get_Resource_Conflict_Details for each entry in the conflict list. + /// + /// After an application has finished using the handle received for pclConflictList, it must call CM_Free_Resource_Conflict_Handle. + /// For information about using device instance handles that are bound to a local or a remote machine, see CM_Get_Child_Ex. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_query_resource_conflict_list CMAPI CONFIGRET + // CM_Query_Resource_Conflict_List( PCONFLICT_LIST pclConflictList, DEVINST dnDevInst, RESOURCEID ResourceID, PCVOID ResourceData, + // ULONG ResourceLen, ULONG ulFlags, HMACHINE hMachine ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Query_Resource_Conflict_List")] + public static extern CONFIGRET CM_Query_Resource_Conflict_List(out SafeCONFLICT_LIST pclConflictList, uint dnDevInst, RESOURCEID ResourceID, IntPtr ResourceData, + uint ResourceLen, uint ulFlags, [In, Optional] HMACHINE hMachine); + + /// + /// The CM_Reenumerate_DevNode function enumerates the devices identified by a specified device node and all of its children. + /// + /// Caller-supplied device instance handle that is bound to the local machine. + /// + /// + /// Caller-supplied flags that specify how reenumeration should occur. This parameter can be set to a combination of the following + /// flags, as noted: + /// + /// CM_REENUMERATE_ASYNCHRONOUS + /// + /// Reenumeration should occur asynchronously. The call to this function returns immediately after the PnP manager receives the + /// reenumeration request. If this flag is set, the CM_REENUMERATE_SYNCHRONOUS flag should not also be set. + /// + /// CM_REENUMERATE_NORMAL + /// + /// Specifies default reenumeration behavior, in which reenumeration occurs synchronously. This flag is functionally equivalent to CM_REENUMERATE_SYNCHRONOUS. + /// + /// CM_REENUMERATE_RETRY_INSTALLATION + /// + /// Specifies that Plug and Play should make another attempt to install any devices in the specified subtree that have been detected + /// but are not yet configured, or are marked as needing reinstallation, or for which installation must be completed. This flag can + /// be set along with either the CM_REENUMERATE_SYNCHRONOUS flag or the CM_REENUMERATE_ASYNCHRONOUS flag. + /// + /// + /// This flag must be used with extreme caution, because it can cause the PnP manager to prompt the user to perform installation of + /// any such devices. Currently, only components such as Device Manager and Hardware Wizard use this flag, to allow the user to + /// retry installation of devices that might already have been detected but are not currently installed. + /// + /// CM_REENUMERATE_SYNCHRONOUS + /// + /// Reenumeration should occur synchronously. The call to this function returns when all devices in the specified subtree have been + /// reenumerated. If this flag is set, the CM_REENUMERATE_ASYNCHRONOUS flag should not also be set. This flag is functionally + /// equivalent to CM_REENUMERATE_NORMAL. + /// + /// + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h. + /// + /// + /// + /// If the specified device node represents a hardware or software bus device, the PnP manager queries the device's drivers for a + /// list of children, then attempts to configure and start any child devices that were not previously configured. The PnP manager + /// also initiates surprise-removal of devices that are no longer present (see IRP_MN_SURPRISE_REMOVAL). + /// + /// + /// Callers of this function must have SeLoadDriverPrivilege. (Privileges are described in the Microsoft Windows SDK documentation.) + /// + /// For information about using device instance handles that are bound to the local machine, see CM_Get_Child. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_reenumerate_devnode CMAPI CONFIGRET + // CM_Reenumerate_DevNode( DEVINST dnDevInst, ULONG ulFlags ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Reenumerate_DevNode")] + public static extern CONFIGRET CM_Reenumerate_DevNode(uint dnDevInst, CM_REENUMERATE ulFlags); + + /// + /// + /// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated. Please use CM_Reenumerate_DevNode instead.] + /// + /// + /// The CM_Reenumerate_DevNode_Ex function enumerates the devices identified by a specified device node and all of its children. + /// + /// + /// Caller-supplied device instance handle that is bound to the machine handle supplied by hMachine. + /// + /// + /// Caller-supplied flags that specify how reenumeration should occur. This parameter can be set to a combination of the following + /// flags, as noted: + /// + /// CM_REENUMERATE_ASYNCHRONOUS + /// + /// Reenumeration should occur asynchronously. The call to this function returns immediately after the PnP manager receives the + /// reenumeration request. If this flag is set, the CM_REENUMERATE_SYNCHRONOUS flag should not also be set. + /// + /// CM_REENUMERATE_NORMAL + /// + /// Specifies default reenumeration behavior, in which reenumeration occurs synchronously. This flag is currently equivalent to CM_REENUMERATE_SYNCHRONOUS. + /// + /// CM_REENUMERATE_RETRY_INSTALLATION + /// + /// Specifies that Plug and Play should make another attempt to install any devices in the specified subtree that have been detected + /// but are not yet configured, or are marked as needing reinstallation, or for which installation must be completed. This flag can + /// be set along with either the CM_REENUMERATE_SYNCHRONOUS flag or the CM_REENUMERATE_ASYNCHRONOUS flag. + /// + /// + /// This flag must be used with extreme caution, because it can cause the PnP manager to prompt the user to perform installation of + /// any such devices. Currently, only components such as Device Manager and Hardware Wizard use this flag, to allow the user to + /// retry installation of devices that might already have been detected but are not currently installed. + /// + /// CM_REENUMERATE_SYNCHRONOUS + /// + /// Reenumeration should occur synchronously. The call to this function returns when all devices in the specified subtree have been + /// reenumerated. If this flag is set, the CM_REENUMERATE_ASYNCHRONOUS flag should not also be set. This flag is currently + /// equivalent to CM_REENUMERATE_NORMAL. + /// + /// + /// + /// Caller-supplied machine handle to which the caller-supplied device instance handle is bound. + /// + /// Note Using this function to access remote machines is not supported beginning with Windows 8 and Windows Server 2012, as + /// this functionality has been removed. + /// + /// + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h. + /// + /// + /// + /// If the specified device node represents a hardware or software bus device, the PnP manager queries the device's drivers for a + /// list of children, then attempts to configure and start any child devices that were not previously configured. The PnP manager + /// also initiates surprise-removal of devices that are no longer present (see IRP_MN_SURPRISE_REMOVAL). + /// + /// + /// Callers of this function must have SeLoadDriverPrivilege. (Privileges are described in the Microsoft Windows SDK documentation.) + /// + /// For information about using device instance handles that are bound to a local or a remote machine, see CM_Get_Child_Ex. + /// + /// Functionality to access remote machines has been removed in Windows 8 and Windows Server 2012 and later operating systems thus + /// you cannot access remote machines when running on these versions of Windows. + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_reenumerate_devnode_ex CMAPI CONFIGRET + // CM_Reenumerate_DevNode_Ex( DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Reenumerate_DevNode_Ex")] + public static extern CONFIGRET CM_Reenumerate_DevNode_Ex(uint dnDevInst, CM_REENUMERATE ulFlags, [In, Optional] HMACHINE hMachine); + + /// + /// + /// Use RegisterDeviceNotification instead of CM_Register_Notification if your code targets Windows 7 or earlier versions of + /// Windows. Kernel mode callers should use IoRegisterPlugPlayNotification instead. + /// + /// + /// The CM_Register_Notification function registers an application callback routine to be called when a PnP event of the + /// specified type occurs. + /// + /// + /// Pointer to a CM_NOTIFY_FILTER structure. + /// + /// Pointer to a caller-allocated buffer containing the context to be passed to the callback routine in pCallback. + /// + /// + /// + /// Pointer to the routine to be called when the specified PnP event occurs. See the Remarks section for the callback + /// function's prototype. + /// + /// The callback routine’s Action parameter will be a value from the CM_NOTIFY_ACTION enumeration. + /// + /// Upon receiving a notification, how the callback examines the notification will depend on the FilterType member of the + /// callback routine's EventData parameter: + /// + /// CM_NOTIFY_FILTER_TYPE_DEVICEINTERFACE + /// The callback should examine EventData->u.DeviceInterface. + /// CM_NOTIFY_FILTER_TYPE_DEVICEHANDLE + /// The callback should examine EventData->u.DeviceHandle. + /// CM_NOTIFY_FILTER_TYPE_DEVICEINSTANCE + /// The callback should examine EventData->u.DeviceInstance. + /// + /// Pointer to receive the HCMNOTIFICATION handle that corresponds to the registration call. + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h. + /// + /// + /// + /// Be sure to handle Plug and Play device events as quickly as possible. If your event handler performs any operation that may + /// block execution (such as I/O), it is best to start another thread to perform the operation asynchronously. + /// + /// + /// The CM_Register_Notification function does not provide notification of existing device interfaces. To retrieve existing + /// interfaces, first call CM_Register_Notification, and then call CM_Get_Device_Interface_List. If the interface is enabled + /// after your driver calls CM_Register_Notification, but before your driver calls CM_Get_Device_Interface_List, the + /// driver receives a notification for the interface arrival, and the interface also appears in the list of device interface + /// instances returned by CM_Get_Device_Interface_List. + /// + /// + /// HCMNOTIFICATION handles returned by CM_Register_Notification must be closed by calling the CM_Unregister_Notification + /// function when they are no longer needed. + /// + /// A callback routine uses the following function prototype: + /// + /// typedef __callback DWORD (CALLBACK *PCM_NOTIFY_CALLBACK)( _In_ HCMNOTIFICATION hNotify, _In_opt_ PVOID Context, _In_ CM_NOTIFY_ACTION Action, _In_reads_bytes_(EventDataSize) PCM_NOTIFY_EVENT_DATA EventData, _In_ DWORD EventDataSize ); + /// + /// + /// If responding to a CM_NOTIFY_ACTION_DEVICEQUERYREMOVE notification, the PCM_NOTIFY_CALLBACK callback should return either + /// ERROR_SUCCESS or ERROR_CANCELLED, as appropriate. Otherwise, the callback should return ERROR_SUCCESS. The callback should not + /// return any other values. For a description of other actions, please refer to the CM_NOTIFY_ACTION documentation. Also see + /// CM_NOTIFY_EVENT_DATA for information about the structure that this callback receives in the EventData parameter. + /// + /// Examples + /// For an example, see Registering for Notification of Device Interface Arrival and Device Removal. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_register_notification CMAPI CONFIGRET + // CM_Register_Notification( PCM_NOTIFY_FILTER pFilter, PVOID pContext, PCM_NOTIFY_CALLBACK pCallback, PHCMNOTIFICATION + // pNotifyContext ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Register_Notification")] + public static extern CONFIGRET CM_Register_Notification(in CM_NOTIFY_FILTER pFilter, [In, Optional] IntPtr pContext, CM_NOTIFY_CALLBACK pCallback, out SafeHCMNOTIFICATION pNotifyContext); + + /// + /// The CM_Request_Device_Eject function prepares a local device instance for safe removal, if the device is removable. If + /// the device can be physically ejected, it will be. + /// + /// Caller-supplied device instance handle that is bound to the local machine. + /// + /// (Optional.) If not NULL, this points to a location that, if the removal request fails, receives a PNP_VETO_TYPE-typed + /// value indicating the reason for the failure. + /// + /// + /// (Optional.) If not NULL, this is a caller-supplied pointer to a string buffer that receives a text string. The type of + /// information this string provides is dependent on the value received by pVetoType. For information about these strings, see PNP_VETO_TYPE. + /// + /// + /// (Optional.) Caller-supplied value representing the length of the string buffer supplied by pszVetoName. This should be set to MAX_PATH. + /// + /// Not used. + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h. + /// + /// + /// + /// If pszVetoName is NULL, the PnP manager displays a message to the user indicating the device was removed or, if the + /// request failed, identifying the reason for the failure. If pszVetoName is not NULL, the PnP manager does not display a + /// message. (Note, however, that for Microsoft Windows 2000 only, the PnP manager displays a message even if pszVetoName is not + /// NULL, if the device's CM_DEVCAP_DOCKDEVICE capability is set.) + /// + /// + /// Callers of CM_Request_Device_Eject sometimes require SeUndockPrivilege or SeLoadDriverPrivilege, as follows: + /// + /// + /// + /// + /// If the device's CM_DEVCAP_DOCKDEVICE capability is set (the device is a "dock" device), callers must have + /// SeUndockPrivilege. ( SeLoadDriverPrivilege is not required.) + /// + /// + /// + /// + /// If the device's CM_DEVCAP_DOCKDEVICE capability is not set (the device is not a "dock" device), and if the calling process is + /// either not interactive or is running in a multi-user environment in a session not attached to the physical console (such as a + /// remote Terminal Services session), callers of this function must have SeLoadDriverPrivilege. + /// + /// + /// + /// Privileges are described in the Microsoft Windows SDK documentation. + /// For information about using device instance handles that are bound to the local machine, see CM_Get_Child. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_request_device_ejectw CMAPI CONFIGRET + // CM_Request_Device_EjectW( DEVINST dnDevInst, PPNP_VETO_TYPE pVetoType, LPWSTR pszVetoName, ULONG ulNameLength, ULONG ulFlags ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Auto)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Request_Device_EjectW")] + public static extern CONFIGRET CM_Request_Device_Eject(uint dnDevInst, out PNP_VETO_TYPE pVetoType, [Out] StringBuilder pszVetoName, uint ulNameLength, uint ulFlags = 0); + + /// + /// The CM_Request_Device_Eject function prepares a local device instance for safe removal, if the device is removable. If + /// the device can be physically ejected, it will be. + /// + /// Caller-supplied device instance handle that is bound to the local machine. + /// + /// (Optional.) If not NULL, this points to a location that, if the removal request fails, receives a PNP_VETO_TYPE-typed + /// value indicating the reason for the failure. + /// + /// + /// (Optional.) If not NULL, this is a caller-supplied pointer to a string buffer that receives a text string. The type of + /// information this string provides is dependent on the value received by pVetoType. For information about these strings, see PNP_VETO_TYPE. + /// + /// + /// (Optional.) Caller-supplied value representing the length of the string buffer supplied by pszVetoName. This should be set to MAX_PATH. + /// + /// Not used. + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h. + /// + /// + /// + /// If pszVetoName is NULL, the PnP manager displays a message to the user indicating the device was removed or, if the + /// request failed, identifying the reason for the failure. If pszVetoName is not NULL, the PnP manager does not display a + /// message. (Note, however, that for Microsoft Windows 2000 only, the PnP manager displays a message even if pszVetoName is not + /// NULL, if the device's CM_DEVCAP_DOCKDEVICE capability is set.) + /// + /// + /// Callers of CM_Request_Device_Eject sometimes require SeUndockPrivilege or SeLoadDriverPrivilege, as follows: + /// + /// + /// + /// + /// If the device's CM_DEVCAP_DOCKDEVICE capability is set (the device is a "dock" device), callers must have + /// SeUndockPrivilege. ( SeLoadDriverPrivilege is not required.) + /// + /// + /// + /// + /// If the device's CM_DEVCAP_DOCKDEVICE capability is not set (the device is not a "dock" device), and if the calling process is + /// either not interactive or is running in a multi-user environment in a session not attached to the physical console (such as a + /// remote Terminal Services session), callers of this function must have SeLoadDriverPrivilege. + /// + /// + /// + /// Privileges are described in the Microsoft Windows SDK documentation. + /// For information about using device instance handles that are bound to the local machine, see CM_Get_Child. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_request_device_ejectw CMAPI CONFIGRET + // CM_Request_Device_EjectW( DEVINST dnDevInst, PPNP_VETO_TYPE pVetoType, LPWSTR pszVetoName, ULONG ulNameLength, ULONG ulFlags ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Auto)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Request_Device_EjectW")] + public static extern CONFIGRET CM_Request_Device_Eject(uint dnDevInst, [In, Optional] IntPtr pVetoType, [Out] StringBuilder pszVetoName, uint ulNameLength, uint ulFlags = 0); + + /// + /// + /// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated. Please use CM_Request_Device_Eject instead.] + /// + /// + /// The CM_Request_Device_Eject_Ex function prepares a local or a remote device instance for safe removal, if the device is + /// removable. If the device can be physically ejected, it will be. + /// + /// + /// Caller-supplied device instance handle that is bound to the machine handle supplied by hMachine. + /// + /// (Optional.) If not NULL, this points to a location that, if the removal request fails, receives a PNP_VETO_TYPE-typed + /// value indicating the reason for the failure. + /// + /// + /// (Optional.) If not NULL, this is a caller-supplied pointer to a string buffer that receives a text string. The type of + /// information this string provides is dependent on the value received by pVetoType. For information about these strings, see PNP_VETO_TYPE. + /// + /// + /// (Optional.) Caller-supplied value representing the length of the string buffer supplied by pszVetoName. This should be set to MAX_PATH. + /// + /// Not used. + /// + /// Caller-supplied machine handle to which the caller-supplied device instance handle is bound. + /// + /// Note Using this function to access remote machines is not supported beginning with Windows 8 and Windows Server 2012, as + /// this functionality has been removed. + /// + /// + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h. + /// + /// + /// + /// If pszVetoName is NULL, the PnP manager displays a message to the user indicating the device was removed or, if the + /// request failed, identifying the reason for the failure. If pszVetoName is not NULL, the PnP manager does not display a + /// message. (Note, however, that for Microsoft Windows 2000 only, the PnP manager displays a message even if pszVetoName is not + /// NULL, if the device's CM_DEVCAP_DOCKDEVICE capability is set.) + /// + /// + /// For remote machines, this function only works for "dock" device instances. That is, the function can only be used remotely to + /// undock a machine. In that case, the caller must have SeUndockPrivilege. + /// + /// Callers of CM_Request_Eject_Ex sometimes require SeUndockPrivilege or SeLoadDriverPrivilege, as follows: + /// + /// + /// + /// If the device's CM_DEVCAP_DOCKDEVICE capability is set (the device is a "dock" device), callers must have + /// SeUndockPrivilege. ( SeLoadDriverPrivilege is not required.) + /// + /// + /// + /// + /// If the device's CM_DEVCAP_DOCKDEVICE capability is not set (the device is not a "dock" device), and if the calling process is + /// either not interactive or is running in a multi-user environment in a session not attached to the physical console (such as a + /// remote Terminal Services session) callers of this function must have SeLoadDriverPrivilege. + /// + /// + /// + /// (Privileges are described in the Microsoft Windows SDK documentation.) + /// For information about using device instance handles that are bound to a local or a remote machine, see CM_Get_Child_Ex. + /// + /// Functionality to access remote machines has been removed in Windows 8 and Windows Server 2012 and later operating systems thus + /// you cannot access remote machines when running on these versions of Windows. + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_request_device_eject_exw CMAPI CONFIGRET + // CM_Request_Device_Eject_ExW( DEVINST dnDevInst, PPNP_VETO_TYPE pVetoType, LPWSTR pszVetoName, ULONG ulNameLength, ULONG ulFlags, + // HMACHINE hMachine ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Auto)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Request_Device_Eject_ExW")] + public static extern CONFIGRET CM_Request_Device_Eject_Ex(uint dnDevInst, out PNP_VETO_TYPE pVetoType, [Out] StringBuilder pszVetoName, uint ulNameLength, [In, Optional] uint ulFlags, [In, Optional] HMACHINE hMachine); + + /// + /// + /// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated. Please use CM_Request_Device_Eject instead.] + /// + /// + /// The CM_Request_Device_Eject_Ex function prepares a local or a remote device instance for safe removal, if the device is + /// removable. If the device can be physically ejected, it will be. + /// + /// + /// Caller-supplied device instance handle that is bound to the machine handle supplied by hMachine. + /// + /// (Optional.) If not NULL, this points to a location that, if the removal request fails, receives a PNP_VETO_TYPE-typed + /// value indicating the reason for the failure. + /// + /// + /// (Optional.) If not NULL, this is a caller-supplied pointer to a string buffer that receives a text string. The type of + /// information this string provides is dependent on the value received by pVetoType. For information about these strings, see PNP_VETO_TYPE. + /// + /// + /// (Optional.) Caller-supplied value representing the length of the string buffer supplied by pszVetoName. This should be set to MAX_PATH. + /// + /// Not used. + /// + /// Caller-supplied machine handle to which the caller-supplied device instance handle is bound. + /// + /// Note Using this function to access remote machines is not supported beginning with Windows 8 and Windows Server 2012, as + /// this functionality has been removed. + /// + /// + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h. + /// + /// + /// + /// If pszVetoName is NULL, the PnP manager displays a message to the user indicating the device was removed or, if the + /// request failed, identifying the reason for the failure. If pszVetoName is not NULL, the PnP manager does not display a + /// message. (Note, however, that for Microsoft Windows 2000 only, the PnP manager displays a message even if pszVetoName is not + /// NULL, if the device's CM_DEVCAP_DOCKDEVICE capability is set.) + /// + /// + /// For remote machines, this function only works for "dock" device instances. That is, the function can only be used remotely to + /// undock a machine. In that case, the caller must have SeUndockPrivilege. + /// + /// Callers of CM_Request_Eject_Ex sometimes require SeUndockPrivilege or SeLoadDriverPrivilege, as follows: + /// + /// + /// + /// If the device's CM_DEVCAP_DOCKDEVICE capability is set (the device is a "dock" device), callers must have + /// SeUndockPrivilege. ( SeLoadDriverPrivilege is not required.) + /// + /// + /// + /// + /// If the device's CM_DEVCAP_DOCKDEVICE capability is not set (the device is not a "dock" device), and if the calling process is + /// either not interactive or is running in a multi-user environment in a session not attached to the physical console (such as a + /// remote Terminal Services session) callers of this function must have SeLoadDriverPrivilege. + /// + /// + /// + /// (Privileges are described in the Microsoft Windows SDK documentation.) + /// For information about using device instance handles that are bound to a local or a remote machine, see CM_Get_Child_Ex. + /// + /// Functionality to access remote machines has been removed in Windows 8 and Windows Server 2012 and later operating systems thus + /// you cannot access remote machines when running on these versions of Windows. + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_request_device_eject_exw CMAPI CONFIGRET + // CM_Request_Device_Eject_ExW( DEVINST dnDevInst, PPNP_VETO_TYPE pVetoType, LPWSTR pszVetoName, ULONG ulNameLength, ULONG ulFlags, + // HMACHINE hMachine ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Auto)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Request_Device_Eject_ExW")] + public static extern CONFIGRET CM_Request_Device_Eject_Ex(uint dnDevInst, [In, Optional] IntPtr pVetoType, [Out] StringBuilder pszVetoName, uint ulNameLength, [In, Optional] uint ulFlags, [In, Optional] HMACHINE hMachine); + + /// + /// The CM_Request_Eject_PC function requests that a portable PC, which is inserted in a local docking station, be ejected. + /// + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, the function returns one of the CR_-prefixed error codes + /// that are defined in Cfgmgr32.h. + /// + /// + /// + /// Use this function to request that a portable PC, which is inserted in a local docking station, be ejected. You can also use the + /// following related functions with docking stations: + /// + /// + /// + /// + /// CM_Is_Dock_Station_Present identifies whether a docking station is present in a local machine. + /// + /// + /// + /// + /// CM_Is_Dock_Station_Present_Ex identifies whether a docking station is present in a local or a remote machine. + /// + /// + /// + /// + /// CM_Request_Eject_PC_Ex requests that a portable PC, which is inserted in a local or a remote docking station, be ejected. + /// + /// + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_request_eject_pc CMAPI CONFIGRET CM_Request_Eject_PC(); + [DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Request_Eject_PC")] + public static extern CONFIGRET CM_Request_Eject_PC(); + + /// + /// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated. Please use CM_Request_Eject_PC instead.] + /// + /// The CM_Request_Eject_PC_Ex function requests that a portable PC, which is inserted in a local or a remote docking + /// station, be ejected. + /// + /// + /// + /// Supplies a machine handle that is returned by CM_Connect_Machine. + /// + /// Note Using this function to access remote machines is not supported beginning with Windows 8 and Windows Server 2012, as + /// this functionality has been removed. + /// + /// + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, the function returns one of the CR_-prefixed error codes + /// that are defined in Cfgmgr32.h. + /// + /// + /// + /// Use this function to request that a portable PC, which is inserted in a local or a remote docking station, be ejected. You can + /// also use the following related functions with docking stations: + /// + /// + /// + /// + /// CM_Is_Dock_Station_Present identifies whether a docking station is present in a local machine. + /// + /// + /// + /// + /// CM_Is_Dock_Station_Present_Ex identifies whether a docking station is present in a local or a remote machine. + /// + /// + /// + /// + /// CM_Request_Eject_PC requests that a portable PC, which is inserted in a local docking station, be ejected. + /// + /// + /// + /// + /// Functionality to access remote machines has been removed in Windows 8 and Windows Server 2012 and later operating systems thus + /// you cannot access remote machines when running on these versions of Windows. + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_request_eject_pc_ex CMAPI CONFIGRET + // CM_Request_Eject_PC_Ex( HMACHINE hMachine ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Request_Eject_PC_Ex")] + public static extern CONFIGRET CM_Request_Eject_PC_Ex([In, Optional] HMACHINE hMachine); + + /// The CM_Set_Class_Property function sets a class property for a device setup class or a device interface class. + /// + /// Pointer to the GUID that identifies the device interface class or device setup class for which to set a device property. For + /// information about specifying the class type, see the ulFlags parameter. + /// + /// + /// Pointer to a DEVPROPKEY structure that represents the property key of the device class property to set. + /// + /// + /// A DEVPROPTYPE-typed value that represents the property-data-type identifier for the device class property. To delete a property, + /// set this to DEVPROP_TYPE_EMPTY. + /// + /// + /// Pointer to a buffer that contains the property value of the device class property. If either the property or the data is to be + /// deleted, this pointer must be set to NULL, and PropertyBufferSize must be set to zero. + /// + /// + /// The size, in bytes, of the PropertyBuffer buffer. If PropertyBuffer is set to NULL, PropertyBufferSize must be set to zero. + /// + /// + /// Class property flags: + /// CM_CLASS_PROPERTY_INSTALLER + /// ClassGUID specifies a device setup class. Do not combine with CM_CLASS_PROPERTY_INTERFACE. + /// CM_CLASS_PROPERTY_INTERFACE + /// ClassGUID specifies a device interface class. Do not combine with CM_CLASS_PROPERTY_INSTALLER. + /// + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h. + /// + /// CM_Set_Class_Property is part of the Unified Device Property Model. + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_set_class_propertyw CMAPI CONFIGRET + // CM_Set_Class_PropertyW( LPCGUID ClassGUID, const DEVPROPKEY *PropertyKey, DEVPROPTYPE PropertyType, const PBYTE PropertyBuffer, + // ULONG PropertyBufferSize, ULONG ulFlags ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Unicode)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Set_Class_PropertyW")] + public static extern CONFIGRET CM_Set_Class_Property(in Guid ClassGUID, in DEVPROPKEY PropertyKey, DEVPROPTYPE PropertyType, [In, Optional] IntPtr PropertyBuffer, uint PropertyBufferSize, uint ulFlags = 0); + + /// + /// + /// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated. Please use CM_Set_Class_Property instead.] + /// + /// The CM_Set_Class_Property_ExW function sets a class property for a device setup class or a device interface class. + /// + /// + /// Pointer to the GUID that identifies the device interface class or device setup class for which to set a device property. For + /// information about specifying the class type, see the ulFlags parameter. + /// + /// + /// Pointer to a DEVPROPKEY structure that represents the property key of the device class property to set. + /// + /// + /// A DEVPROPTYPE-typed value that represents the property-data-type identifier for the device class property. To delete a property, + /// set this to DEVPROP_TYPE_EMPTY. + /// + /// + /// Pointer to a buffer that contains the property value of the device class property. If either the property or the data is to be + /// deleted, this pointer must be set to NULL, and PropertyBufferSize must be set to zero. + /// + /// + /// The size, in bytes, of the PropertyBuffer buffer. If PropertyBuffer is set to NULL, PropertyBufferSize must be set to zero. + /// + /// + /// Class property flags: + /// CM_CLASS_PROPERTY_INSTALLER + /// ClassGUID specifies a device setup class. Do not combine with CM_CLASS_PROPERTY_INTERFACE. + /// CM_CLASS_PROPERTY_INTERFACE + /// ClassGUID specifies a device interface class. Do not combine with CM_CLASS_PROPERTY_INSTALLER. + /// + /// + /// Caller-supplied machine handle, obtained from a previous call to CM_Connect_Machine. + /// + /// Note Using this function to access remote machines is not supported beginning with Windows 8 and Windows Server 2012, as + /// this functionality has been removed. + /// + /// + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h. + /// + /// CM_Set_Class_Property_ExW is part of the Unified Device Property Model. + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_set_class_property_exw CMAPI CONFIGRET + // CM_Set_Class_Property_ExW( LPCGUID ClassGUID, const DEVPROPKEY *PropertyKey, DEVPROPTYPE PropertyType, const PBYTE + // PropertyBuffer, ULONG PropertyBufferSize, ULONG ulFlags, HMACHINE hMachine ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Unicode)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Set_Class_Property_ExW")] + public static extern CONFIGRET CM_Set_Class_Property_Ex(in Guid ClassGUID, in DEVPROPKEY PropertyKey, DEVPROPTYPE PropertyType, [In, Optional] IntPtr PropertyBuffer, uint PropertyBufferSize, + CM_CLASS_PROPERTY ulFlags, [In, Optional] HMACHINE hMachine); + + /// The CM_Set_Class_Registry_Property function sets or deletes a property of a device setup class. + /// A pointer to the GUID that represents the device setup class for which to set a property. + /// + /// A value of type ULONG that identifies the property to set. This value must be one of the CM_CRP_Xxx values that are described + /// for the ulProperty parameter of the CM_Get_Class_Registry_Property function. + /// + /// + /// A pointer to a buffer that contains the property data. This parameter is optional and can be set to NULL. For more + /// information about setting this parameter and the corresponding ulLength parameter, see the following Remarks section. + /// + /// A value of type ULONG that specifies the size, in bytes, of the property data. + /// Reserved for internal use only. Must be set to zero. + /// + /// A handle to a remote machine on which to set the specified device setup class property. This parameter is optional. If set to + /// NULL, the property is set on the local machine. + /// + /// + /// If the operation succeeds, CM_Set_Class_Registry_Property returns CR_SUCCESS. Otherwise, the function returns one of the + /// other CR_Xxx status codes that are defined in Cfgmgr32.h. + /// + /// + /// If Buffer is NULL, ulLength must be set to zero. + /// If ulLength is set to zero, the function deletes the property. + /// + /// If Buffer is not set to NULL and ulLength is not set to zero, the supplied value must be the correct size for the REG_Xxx + /// data type for the property that is specified in ulProperty. + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_set_class_registry_propertyw CMAPI CONFIGRET + // CM_Set_Class_Registry_PropertyW( LPGUID ClassGuid, ULONG ulProperty, PCVOID Buffer, ULONG ulLength, ULONG ulFlags, HMACHINE + // hMachine ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Auto)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Set_Class_Registry_PropertyW")] + public static extern CONFIGRET CM_Set_Class_Registry_Property(in Guid ClassGuid, CM_CRP ulProperty, [In, Optional] IntPtr Buffer, uint ulLength, [In, Optional] uint ulFlags, [In, Optional] HMACHINE hMachine); + + /// The CM_Set_Device_Interface_Property function sets a device property of a device interface. + /// + /// Pointer to a string that identifies the device interface instance for which to set a property for. + /// + /// + /// Pointer to a DEVPROPKEY structure that represents the property key of the device interface property to set. + /// + /// + /// A DEVPROPTYPE-typed value that represents the property-data-type identifier for the device interface property. To delete a + /// property, this must be set to DEVPROP_TYPE_EMPTY. + /// + /// + /// Pointer to a buffer that contains the property value of the device interface property. If either the property or the data is + /// being deleted, this pointer must be set to NULL, and PropertyBufferSize must be set to zero. + /// + /// + /// The size, in bytes, of the PropertyBuffer buffer. If PropertyBuffer is set to NULL, PropertyBufferSize must be set to zero. + /// + /// Reserved. Must be set to zero. + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h. + /// + /// CM_Set_Device_Interface_Property is part of the Unified Device Property Model. + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_set_device_interface_propertyw CMAPI CONFIGRET + // CM_Set_Device_Interface_PropertyW( LPCWSTR pszDeviceInterface, const DEVPROPKEY *PropertyKey, DEVPROPTYPE PropertyType, const + // PBYTE PropertyBuffer, ULONG PropertyBufferSize, ULONG ulFlags ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Unicode)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Set_Device_Interface_PropertyW")] + public static extern CONFIGRET CM_Set_Device_Interface_Property(string pszDeviceInterface, in DEVPROPKEY PropertyKey, DEVPROPTYPE PropertyType, [In, Optional] IntPtr PropertyBuffer, + uint PropertyBufferSize, uint ulFlags = 0); + + /// + /// + /// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated. Please use + /// CM_Set_Device_Interface_Property instead.] + /// + /// The CM_Set_Device_Interface_Property_ExW function sets a device property of a device interface. + /// + /// + /// Pointer to a string that identifies the device interface instance for which to set a property for. + /// + /// + /// Pointer to a DEVPROPKEY structure that represents the property key of the device interface property to set. + /// + /// + /// A DEVPROPTYPE-typed value that represents the property-data-type identifier for the device interface property. To delete a + /// property, this must be set to DEVPROP_TYPE_EMPTY. + /// + /// + /// Pointer to a buffer that contains the property value of the device interface property. If either the property or the data is + /// being deleted, this pointer must be set to NULL, and PropertyBufferSize must be set to zero. + /// + /// + /// The size, in bytes, of the PropertyBuffer buffer. If PropertyBuffer is set to NULL, PropertyBufferSize must be set to zero. + /// + /// Reserved. Must be set to zero. + /// + /// Caller-supplied machine handle, obtained from a previous call to CM_Connect_Machine. + /// + /// Note Using this function to access remote machines is not supported beginning with Windows 8 and Windows Server 2012, as + /// this functionality has been removed. + /// + /// + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h. + /// + /// CM_Set_Device_Interface_Property_ExW is part of the Unified Device Property Model. + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_set_device_interface_property_exw CMAPI CONFIGRET + // CM_Set_Device_Interface_Property_ExW( LPCWSTR pszDeviceInterface, const DEVPROPKEY *PropertyKey, DEVPROPTYPE PropertyType, const + // PBYTE PropertyBuffer, ULONG PropertyBufferSize, ULONG ulFlags, HMACHINE hMachine ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Unicode)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Set_Device_Interface_Property_ExW")] + public static extern CONFIGRET CM_Set_Device_Interface_Property_Ex(string pszDeviceInterface, in DEVPROPKEY PropertyKey, DEVPROPTYPE PropertyType, [In, Optional] IntPtr PropertyBuffer, + uint PropertyBufferSize, [In, Optional] uint ulFlags, [In, Optional] HMACHINE hMachine); + + /// The CM_Set_DevNode_Problem function sets a problem code for a device that is installed in a local machine. + /// Caller-supplied device instance handle that is bound to the local machine. + /// + /// Supplies a problem code, which is zero or one of the CM_PROB_Xxx flags that are described in Device Manager Error Messages. A + /// value of zero indicates that a problem is not set for the device. + /// + /// Must be set to zero. + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, the function returns one of the CR_-prefixed error codes + /// that are defined in Cfgmgr32.h. + /// + /// + /// + /// Use this function to set a problem code for a device that is installed in a local machine. You can also use the following + /// functions to set a device's problem code and to obtain the problem code set for the device: + /// + /// + /// + /// + /// CM_Get_DevNode_Status returns the problem code set for a device installed in a local machine. + /// + /// + /// + /// + /// CM_Get_DevNode_Status_Ex returns the problem code set for a device installed in a local or a remote machine. + /// + /// + /// + /// + /// CM_Set_DevNode_Problem_Ex sets a problem code for a device installed in a local or a remote machine. + /// + /// + /// + /// For information about using device instance handles that are bound to the local machine, see CM_Get_Child. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_set_devnode_problem CMAPI CONFIGRET + // CM_Set_DevNode_Problem( DEVINST dnDevInst, ULONG ulProblem, ULONG ulFlags ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Set_DevNode_Problem")] + public static extern CONFIGRET CM_Set_DevNode_Problem(uint dnDevInst, CM_PROB ulProblem, uint ulFlags = 0); + + /// + /// + /// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated. Please use CM_Set_DevNode_Problem instead.] + /// + /// + /// The CM_Set_DevNode_Problem_Ex function sets a problem code for a device that is installed in a local or a remote machine. + /// + /// + /// Caller-supplied device instance handle that is bound to the machine handle supplied by hMachine. + /// + /// Supplies a problem code, which is zero or one of the CM_PROB_Xxx flags that are described in Device Manager Error Messages. A + /// value of zero indicates that a problem code is not set for the device. + /// + /// Must be set to zero. + /// + /// Caller-supplied machine handle to which the caller-supplied device instance handle is bound. + /// + /// Note Using this function to access remote machines is not supported beginning with Windows 8 and Windows Server 2012, as + /// this functionality has been removed. + /// + /// + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, the function returns one of the CR_-prefixed error codes + /// that are defined in Cfgmgr32.h. + /// + /// + /// + /// Use this function to set a problem code for a device that is installed in a local or a remote machine. You can also use the + /// following functions to set a device's problem code and to obtain the problem code set for the device: + /// + /// + /// + /// + /// CM_Get_DevNode_Status returns the problem code set for a device installed in a local machine. + /// + /// + /// + /// + /// CM_Get_DevNode_Status_Ex returns the problem code set for a device installed in a local or a remote machine. + /// + /// + /// + /// + /// CM_Set_DevNode_Problem sets a problem code for a device installed in a local machine. + /// + /// + /// + /// For information about using device instance handles that are bound to a local or a remote machine, see CM_Get_Child_Ex. + /// + /// Functionality to access remote machines has been removed in Windows 8 and Windows Server 2012 and later operating systems thus + /// you cannot access remote machines when running on these versions of Windows. + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_set_devnode_problem_ex CMAPI CONFIGRET + // CM_Set_DevNode_Problem_Ex( DEVINST dnDevInst, ULONG ulProblem, ULONG ulFlags, HMACHINE hMachine ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Set_DevNode_Problem_Ex")] + public static extern CONFIGRET CM_Set_DevNode_Problem_Ex(uint dnDevInst, CM_PROB ulProblem, [In, Optional] uint ulFlags, [In, Optional] HMACHINE hMachine); + + /// The CM_Set_DevNode_Property function sets a device instance property. + /// Device instance handle that is bound to the local machine. + /// + /// Pointer to a DEVPROPKEY structure that represents the property key of the device instance property to set. + /// + /// + /// A DEVPROPTYPE-typed value that represents the property-data-type identifier for the device instance property. To delete a + /// property, this must be set to DEVPROP_TYPE_EMPTY. + /// + /// + /// Pointer to a buffer that contains the property value of the device instance property. If either the property or the data is + /// being deleted, this pointer must be set to NULL, and PropertyBufferSize must be set to zero. + /// + /// + /// The size, in bytes, of the PropertyBuffer buffer. If PropertyBuffer is set to NULL, PropertyBufferSize must be set to zero. + /// + /// Reserved. Must be set to zero. + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h. + /// + /// CM_Set_DevNode_Property is part of the Unified Device Property Model. + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_set_devnode_propertyw CMAPI CONFIGRET + // CM_Set_DevNode_PropertyW( DEVINST dnDevInst, const DEVPROPKEY *PropertyKey, DEVPROPTYPE PropertyType, const PBYTE PropertyBuffer, + // ULONG PropertyBufferSize, ULONG ulFlags ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Unicode)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Set_DevNode_PropertyW")] + public static extern CONFIGRET CM_Set_DevNode_Property(uint dnDevInst, in DEVPROPKEY PropertyKey, DEVPROPTYPE PropertyType, [In, Optional] IntPtr PropertyBuffer, uint PropertyBufferSize, uint ulFlags = 0); + + /// + /// + /// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated. Please use CM_Set_DevNode_Property instead.] + /// + /// The CM_Set_DevNode_Property_ExW function sets a device instance property. + /// + /// Device instance handle that is bound to the local machine. + /// + /// Pointer to a DEVPROPKEY structure that represents the property key of the device instance property to set. + /// + /// + /// A DEVPROPTYPE-typed value that represents the property-data-type identifier for the device instance property. To delete a + /// property, this must be set to DEVPROP_TYPE_EMPTY. + /// + /// + /// Pointer to a buffer that contains the property value of the device instance property. If either the property or the data is + /// being deleted, this pointer must be set to NULL, and PropertyBufferSize must be set to zero. + /// + /// + /// The size, in bytes, of the PropertyBuffer buffer. If PropertyBuffer is set to NULL, PropertyBufferSize must be set to zero. + /// + /// Reserved. Must be set to zero. + /// + /// Caller-supplied machine handle, obtained from a previous call to CM_Connect_Machine. + /// + /// Note Using this function to access remote machines is not supported beginning with Windows 8 and Windows Server 2012, as + /// this functionality has been removed. + /// + /// + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h. + /// + /// CM_Set_DevNode_Property_ExW is part of the Unified Device Property Model. + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_set_devnode_property_exw CMAPI CONFIGRET + // CM_Set_DevNode_Property_ExW( DEVINST dnDevInst, const DEVPROPKEY *PropertyKey, DEVPROPTYPE PropertyType, const PBYTE + // PropertyBuffer, ULONG PropertyBufferSize, ULONG ulFlags, HMACHINE hMachine ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Unicode)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Set_DevNode_Property_ExW")] + public static extern CONFIGRET CM_Set_DevNode_Property_Ex(uint dnDevInst, in DEVPROPKEY PropertyKey, DEVPROPTYPE PropertyType, [In, Optional] IntPtr PropertyBuffer, uint PropertyBufferSize, + [In, Optional] uint ulFlags, [In, Optional] HMACHINE hMachine); + + /// The CM_Set_DevNode_Registry_Property function sets a specified device property in the registry. + /// A caller-supplied device instance handle that is bound to the local machine. + /// + /// A CM_DRP_-prefixed constant value that identifies the device property to be set in the registry. These constants are defined in Cfgmgr32.h. + /// + /// + /// A pointer to a caller-supplied buffer that supplies the requested device property, formatted appropriately for the property's + /// data type. + /// + /// The length, in bytes, of the supplied device property. + /// Not used, must be zero. + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes that are + /// defined in Cfgmgr32.h. + /// + /// For information about how to use device instance handles that are bound to the local machine, see CM_Get_Child. + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_set_devnode_registry_propertyw CMAPI CONFIGRET + // CM_Set_DevNode_Registry_PropertyW( DEVINST dnDevInst, ULONG ulProperty, PCVOID Buffer, ULONG ulLength, ULONG ulFlags ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Auto)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Set_DevNode_Registry_PropertyW")] + public static extern CONFIGRET CM_Set_DevNode_Registry_Property(uint dnDevInst, CM_DRP ulProperty, [In, Optional] IntPtr Buffer, uint ulLength, uint ulFlags = 0); + + /// + /// The CM_Setup_DevNode function restarts a device instance that is not running because there is a problem with the device configuration. + /// + /// A device instance handle that is bound to the local system. + /// + /// One of the following flag values: + /// CM_SETUP_DEVNODE_READY + /// Restarts a device instance that is not running because of a problem with the device configuration. + /// CM_SETUP_DEVNODE_RESET (Windows XP and later versions of Windows) + /// + /// Resets a device instance that has the no restart device status flag set. The no restart device status flag is set if a device is + /// removed by calling CM_Query_And_Remove_SubTree or CM_Query_And_Remove_SubTree_Ex and specifying the + /// CM_REMOVE_NO_RESTART flag. + /// + /// + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise it returns one of the error codes with "CR_" prefix that + /// are defined in Cfgmgr32.h. + /// + /// + /// + /// Device installation applications should use the DIF_PROPERTYCHANGE request to restart a device instead of using this function. + /// The DIF_PROPERTYCHANGE request can be used to enable, disable, restart, stop, or change the properties of a device. + /// + /// + /// If a device instance does not have a problem and is already started, CM_Setup_DevNode returns without changing the status + /// of the device instance. + /// + /// Call CM_Get_DevNode_Status or CM_Get_DevNode_Status_Ex to determine the status and problem code for a device instance. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_setup_devnode CMAPI CONFIGRET CM_Setup_DevNode( + // DEVINST dnDevInst, ULONG ulFlags ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Setup_DevNode")] + public static extern CONFIGRET CM_Setup_DevNode(uint dnDevInst, CM_SETUP_DEVNODE ulFlags); + + /// The CM_Uninstall_DevNode function removes all persistent state associated with a device instance. + /// Device instance handle that is bound to the local machine. + /// Reserved. Must be set to zero. + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h. + /// + /// + /// + /// This function uninstalls the device without sending an IRP_MN_QUERY_REMOVE_DEVICE request or calling class installers or + /// co-installers. If your application will run only on a Target Platform of Desktop, instead of calling + /// CM_Uninstall_DevNode, the application should uninstall the device by calling SetupDiCallClassInstaller with the + /// DIF_REMOVE code, or by calling DiUninstallDevice. + /// + /// Use the following sequence to call this function: + /// + /// + /// Check if CM_Get_DevNode_Status returns success. This means that the device is present. + /// + /// + /// If the device is present, call CM_Query_And_Remove_SubTree. + /// + /// + /// Call CM_Uninstall_DevNode. + /// + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_uninstall_devnode CMAPI CONFIGRET + // CM_Uninstall_DevNode( DEVNODE dnDevInst, ULONG ulFlags ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Uninstall_DevNode")] + public static extern CONFIGRET CM_Uninstall_DevNode(uint dnDevInst, uint ulFlags = 0); + + /// + /// + /// Use UnregisterDeviceNotification instead of CM_Unregister_Notification if your code targets Windows 7 or earlier versions + /// of Windows. + /// + /// The CM_Unregister_Notification function closes the specified HCMNOTIFICATION handle. + /// + /// The HCMNOTIFICATION handle returned by the CM_Register_Notification function. + /// + /// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h. + /// + /// + /// + /// Do not call CM_Unregister_Notification from a notification callback. Doing so may cause a deadlock because + /// CM_Unregister_Notification waits for pending callbacks to finish. + /// + /// + /// Instead, if you want to unregister from the notification callback, you must do so asynchronously. The following sequence shows + /// one way to do this: + /// + /// + /// + /// + /// Allocate a context structure to use with your notifications. Include a pointer to a threadpool work structure ( PTP_WORK) + /// and any other information you would like to pass to the notification callback. + /// + /// + /// + /// + /// Call CreateThreadpoolWork. Provide a callback function that calls CM_Unregister_Notification. Add the returned work + /// structure to the previously allocated context structure. + /// + /// + /// + /// Call CM_Register_Notification and provide the context structure as the pContext parameter. + /// + /// + /// Do work, get notifications, etc. + /// + /// + /// + /// Call SubmitThreadpoolWork from within the notification callback, providing the pointer to a threadpool work structure ( + /// PTP_WORK) stored in your context structure. + /// + /// + /// + /// When the threadpool thread runs, the work item calls CM_Unregister_Notification. + /// + /// + /// Call CloseThreadpoolWork to release the work object. + /// + /// + /// If you are finished with the context structure, don't forget to release resources and and free the structure. + /// + /// Caution Do not free the context structure until after the work item has called CM_Unregister_Notification. You can + /// still receive notifications after submitting the threadpool work item and before the work item calls CM_Unregister_Notification. + /// + /// Examples + /// The following example shows how to unregister from the notification callback, as described in the Remarks section. + /// + /// typedef struct _CALLBACK_CONTEXT { BOOL bUnregister; PTP_WORK pWork; HCMNOTIFICATION hNotify; CRITICAL_SECTION lock; } CALLBACK_CONTEXT, *PCALLBACK_CONTEXT; DWORD WINAPI EventCallback( __in HCMNOTIFICATION hNotification, __in PVOID Context, __in CM_NOTIFY_ACTION Action, __in PCM_NOTIFY_EVENT_DATA EventData, __in DWORD EventDataSize ) { PCALLBACK_CONTEXT pCallbackContext = (PCALLBACK_CONTEXT)Context; // unregister from the callback EnterCriticalSection(&(pCallbackContext->lock)); // in case this callback fires before the registration call returns, make sure the notification handle is properly set Context->hNotify = hNotification; if (!pCallbackContext->bUnregister) { pCallbackContext->bUnregister = TRUE; SubmitThreadpoolWork(pCallbackContext->pWork); } LeaveCriticalSection(&(pCallbackContext->lock)); return ERROR_SUCCESS; }; VOID CALLBACK WorkCallback( _Inout_ PTP_CALLBACK_INSTANCE Instance, _Inout_opt_ PVOID Context, _Inout_ PTP_WORK pWork ) { PCALLBACK_CONTEXT pCallbackContext = (PCALLBACK_CONTEXT)Context; CM_Unregister_Notification(pCallbackContext->hNotify); } VOID NotificationFunction() { CONFIGRET cr = CR_SUCCESS; HRESULT hr = S_OK; CM_NOTIFY_FILTER NotifyFilter = { 0 }; BOOL bShouldUnregister = FALSE; PCALLBACK_CONTEXT context; context = (PCALLBACK_CONTEXT)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CALLBACK_CONTEXT)); if (context == NULL) { goto end; } InitializeCriticalSection(&(context->lock)); NotifyFilter.cbSize = sizeof(NotifyFilter); NotifyFilter.Flags = 0; NotifyFilter.FilterType = CM_NOTIFY_FILTER_TYPE_DEVICEINSTANCE; NotifyFilter.Reserved = 0; hr = StringCchCopy(NotifyFilter.u.DeviceInstance.InstanceId, MAX_DEVICE_ID_LEN, TEST_DEVICE_INSTANCE_ID); if (FAILED(hr)) { goto end; } context->pWork = CreateThreadpoolWork(WorkCallback, context, NULL); if (context->pWork == NULL) { goto end; } cr = CM_Register_Notification(&NotifyFilter, context, EventCallback, &context->hNotify); if (cr != CR_SUCCESS) { goto end; } // ... do work here ... EnterCriticalSection(&(context->lock)); if (!context->bUnregister) { // unregister not from the callback bShouldUnregister = TRUE; context->bUnregister = TRUE; } LeaveCriticalSection(&(context->lock)); if (bShouldUnregister) { cr = CM_Unregister_Notification(context->hNotify); if (cr != CR_SUCCESS) { goto end; } } else { // if the callback is the one performing the unregister, wait for the threadpool work item to complete the unregister WaitForThreadpoolWorkCallbacks(context->pWork, FALSE); } end: if (context != NULL) { if (context->pWork != NULL) { CloseThreadpoolWork(context->pWork); } DeleteCriticalSection(&(context->lock)); HeapFree(GetProcessHeap(), 0, context); } return; } + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_unregister_notification CMAPI CONFIGRET + // CM_Unregister_Notification( HCMNOTIFICATION NotifyContext ); + [DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Unregister_Notification")] + public static extern CONFIGRET CM_Unregister_Notification([In] HCMNOTIFICATION NotifyContext); + + /// + /// The CMP_WaitNoPendingInstallEvents (CM_WaitNoPendingInstallEvents) function waits until there are no pending device + /// installation activities for the PnP manager to perform. + /// + /// + /// Specifies a time-out interval, in milliseconds. + /// + /// + /// If dwTimeout is set to zero, the function tests whether there are pending installation events and returns immediately. + /// + /// + /// If dwTimeout is set to INFINITE (defined in Winbase.h), the function's time-out interval never elapses. + /// + /// + /// + /// For all other dwTimeout values, the function returns when the specified interval elapses, even if there are still pending + /// installation events. + /// + /// + /// + /// + /// + /// The function returns one of the following values (defined in Winbase.h): + /// + /// + /// Return code + /// Description + /// + /// + /// WAIT_OBJECT_0 + /// There are no pending installation activities. + /// + /// + /// WAIT_TIMEOUT + /// The time-out interval elapsed, and installation activities are still pending. + /// + /// + /// WAIT_FAILED + /// The function failed. Call GetLastError for additional error information. + /// + /// + /// + /// + /// + /// The function waits for an internal event object, which the PnP manager sets when it determines that no installation activities + /// are pending. + /// + /// + /// If a non-zero time-out value is specified, then CMP_WaitNoPendingInstallEvents will return either when no installation + /// events are pending or when the time-out period has expired, whichever comes first. + /// + /// + /// New installation events can occur at any time. This function just indicates that there are no pending installation activities at + /// the moment it is called. + /// + /// + /// This function is typically used by device installation applications. For more information, see Writing a Device Installation Application. + /// + /// + /// Do not call this function while processing any events inside of a system-initiated callback function that is expected to return + /// within a short amount of time. This includes service startup (for example in the ServiceMain callback function) or while + /// processing any control in the service handler (for example, the Handler callback function), or from installation + /// components such as class-installers or co-installers. + /// + /// + /// For Windows XP (with no service pack installed), this function must be called from session zero, with administrator privileges. + /// For Windows XP with Service Pack 1 (SP1) and later versions of Windows, the function can be called from any session, and + /// administrator privileges are not required. + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_waitnopendinginstallevents DWORD + // CM_WaitNoPendingInstallEvents( DWORD dwTimeout ); + [DllImport(Lib_Cfgmgr32, SetLastError = true, ExactSpelling = true)] + [PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_WaitNoPendingInstallEvents")] + public static extern Kernel32.WAIT_STATUS CM_WaitNoPendingInstallEvents(uint dwTimeout); + + /// Gets the .NET exception for a value. + /// The value to check. + /// The message. + /// An exception instance or if value indicated success. + public static Exception GetException(this CONFIGRET cr, string message = null) + { + if (cr == CONFIGRET.CR_SUCCESS) return null; + var err = cr.ToError(Win32Error.RPC_S_UNKNOWN_IF); + if (err == Win32Error.RPC_S_UNKNOWN_IF) + { + var ex = new Exception(message); + ex.Data.Add("CONFIGRET", cr); + return ex; + } + return err.GetException(message); + } + + /// Throws an exception if value is not . + /// The value to check. + /// The message. + public static void ThrowIfFailed(this CONFIGRET cr, string message = null) { if (cr != CONFIGRET.CR_SUCCESS) throw cr.GetException(message); } + + /// Converts a specified CONFIGRET code to its equivalent system error code. + /// The CONFIGRET code to be converted. + /// + /// A default system error code to be returned when no system error code is mapped to the specified CONFIGRET code. + /// + /// + /// The system error code that corresponds to the CONFIGRET code. + /// + /// When there is no mapping from the specified CONFIGRET code to a system error code, CM_MapCrToWin32Err returns the + /// value specified in . + /// + /// + public static Win32Error ToError(this CONFIGRET cr, Win32Error defaultErr) => CM_MapCrToWin32Err(cr, (uint)defaultErr); } } \ No newline at end of file diff --git a/PInvoke/CfgMgr32/Vanara.PInvoke.CfgMgr32.csproj b/PInvoke/CfgMgr32/Vanara.PInvoke.CfgMgr32.csproj index 7317cf4d..fc377420 100644 --- a/PInvoke/CfgMgr32/Vanara.PInvoke.CfgMgr32.csproj +++ b/PInvoke/CfgMgr32/Vanara.PInvoke.CfgMgr32.csproj @@ -10,10 +10,12 @@ Vanara.PInvoke.CfgMgr32 $(AssemblyName) pinvoke;vanara;net-extensions;interop;CfgMgr32 + true +