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
///
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;
public const int MAX_CONFIG_VALUE = 9999;
public const int MAX_DEVICE_ID_LEN = 200;
public const int MAX_DEVNODE_ID_LEN = MAX_DEVICE_ID_LEN;
public const int MAX_DMA_CHANNELS = 7;
public const int MAX_GUID_STRING_LEN = 39; // 38 chars + terminator null
public const int MAX_INSTANCE_VALUE = 9999;
public const int MAX_IO_PORTS = 20;
public const int MAX_IRQS = 7;
public const int MAX_MEM_REGISTERS = 9;
public const int MAX_PROFILE_LEN = 80;
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
/// 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
{
///
CM_ADD_ID_HARDWARE = 0x00000000,
///
CM_ADD_ID_COMPATIBLE = 0x00000001,
}
/// Class property flags
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Get_Class_Property_ExW")]
public enum CM_CLASS_PROPERTY
{
/// ClassGUID specifies a device setup class. Do not combine with CM_CLASS_PROPERTY_INTERFACE.
CM_CLASS_PROPERTY_INSTALLER = 0x00000000,
/// ClassGUID specifies a device interface class. Do not combine with CM_CLASS_PROPERTY_INSTALLER.
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
{
/// Delete the class only if it does not contain any subkeys.
CM_DELETE_CLASS_ONLY = 0x00000000,
/// Delete the class and all of its subkeys.
CM_DELETE_CLASS_SUBKEYS = 0x00000001,
/// Indicates that ClassGuid specifies a device interface class and not a device setup class.
CM_DELETE_CLASS_INTERFACE = 0x00000002,
}
/// Disable flags
[PInvokeData("cfgmgr32.h")]
[Flags]
public enum CM_DISABLE : uint
{
/// Ask the driver
CM_DISABLE_POLITE = 0x00000000,
/// Don't ask the driver
CM_DISABLE_ABSOLUTE = 0x00000001,
/// Don't ask the driver, and won't be restarteable
CM_DISABLE_HARDWARE = 0x00000002,
/// Do not display any interface to the user if the attempt to disable the device fails.
CM_DISABLE_UI_NOT_OK = 0x00000004,
/// Disables the device across reboots.
CM_DISABLE_PERSIST = 0x00000008,
}
/// Enumerate flags.
[Flags]
public enum CM_ENUMERATE_CLASSES : uint
{
/// Enumerate device setup classes.
CM_ENUMERATE_CLASSES_INSTALLER = 0x00000000,
/// Enumerate device interface classes.
CM_ENUMERATE_CLASSES_INTERFACE = 0x00000001,
}
/// One of the following caller-supplied bit flags that specifies search filters.
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Get_Device_ID_ListA")]
[Flags]
public enum CM_GETIDLIST
{
/// If this flag is set, pszFilter is ignored, and a list of all devices on the system is returned.
CM_GETIDLIST_FILTER_NONE = 0x00000000,
///
///
/// If this flag is set, pszFilter must specify the name of a device enumerator, optionally followed by a device ID. The string
/// format is EnumeratorName\<DeviceID>, such as ROOT or ROOT\*PNP0500.
///
///
/// If pszFilter supplies only an enumerator name, the function returns device instance IDs for the instances of each device
/// associated with the enumerator. Enumerator names can be obtained by calling CM_Enumerate_Enumerators.
///
///
/// If pszFilter supplies both an enumerator and a device ID, the function returns device instance IDs only for the instances of
/// the specified device that is associated with the enumerator.
///
///
CM_GETIDLIST_FILTER_ENUMERATOR = 0x00000001,
///
///
/// If this flag is set, pszFilter must specify the name of a Microsoft Windows service (typically a driver). The function
/// returns device instance IDs for the device instances controlled by the specified service.
///
///
/// Note that if the device tree does not contain a devnode for the specified service, this function creates one by default. To
/// inhibit this behavior, also set CM_GETIDLIST_DONOTGENERATE.
///
///
CM_GETIDLIST_FILTER_SERVICE = 0x00000002,
///
/// If this flag is set, pszFilter must specify a device instance identifier. The function returns device instance IDs for the
/// ejection relations of the specified device instance.
///
CM_GETIDLIST_FILTER_EJECTRELATIONS = 0x00000004,
///
/// If this flag is set, pszFilter must specify a device instance identifier. The function returns device instance IDs for the
/// removal relations of the specified device instance.
///
CM_GETIDLIST_FILTER_REMOVALRELATIONS = 0x00000008,
///
/// If this flag is set, pszFilter must specify a device instance identifier. The function returns device instance IDs for the
/// power relations of the specified device instance.
///
CM_GETIDLIST_FILTER_POWERRELATIONS = 0x00000010,
///
/// If this flag is set, pszFilter must specify a device instance identifier. The function returns device instance IDs for the
/// bus relations of the specified device instance.
///
CM_GETIDLIST_FILTER_BUSRELATIONS = 0x00000020,
///
/// Used only with CM_GETIDLIST_FILTER_SERVICE. If set, and if the device tree does not contain a devnode for the specified
/// service, this flag prevents the function from creating a devnode for the service.
///
CM_GETIDLIST_DONOTGENERATE = 0x10000040,
///
/// If this flag is set, pszFilter must specify the device instance identifier of a composite device node (devnode).
///
/// The function returns the device instance identifiers of the devnodes that represent the transport relations of the specified
/// composite devnode.
///
/// For more information about composite devnodes and transport relations, see the following Remarks section.
///
CM_GETIDLIST_FILTER_TRANSPORTRELATIONS = 0x00000080,
///
/// If this flag is set, the returned list contains only device instances that are currently present on the system. This value
/// can be combined with other ulFlags values, such as CM_GETIDLIST_FILTER_CLASS.
///
CM_GETIDLIST_FILTER_PRESENT = 0x00000100,
///
/// If this flag is set, pszFilter contains a string that specifies a device setup class GUID. The returned list contains device
/// instances for which the property (referenced by the CM_DRP_CLASSGUID constant) matches the specified device setup class GUID.
///
CM_GETIDLIST_FILTER_CLASS = 0x00000200,
}
/// Delete device node key flags. Indicates the scope and type of registry storage key to delete.
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Delete_DevNode_Key")]
[Flags]
public enum CM_REGISTRY
{
/// Delete the device’s hardware key. Do not combine with CM_REGISTRY_SOFTWARE.
CM_REGISTRY_HARDWARE = 0x00000000,
/// Delete the device’s software key. Do not combine with CM_REGISTRY_HARDWARE.
CM_REGISTRY_SOFTWARE = 0x00000001,
/// Delete the per-user key for the current user. Do not combine with CM_REGISTRY_CONFIG.
CM_REGISTRY_USER = 0x00000100,
/// Delete the key that stores hardware profile-specific configuration information. Do not combine with CM_REGISTRY_USER.
CM_REGISTRY_CONFIG = 0x00000200,
}
/// One of the CR_-prefixed error codes defined in Cfgmgr32.h.
[PInvokeData("cfgmgr32.h")]
public enum CONFIGRET : uint
{
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
CR_SUCCESS = 0x00000000,
CR_DEFAULT = 0x00000001,
CR_OUT_OF_MEMORY = 0x00000002,
CR_INVALID_POINTER = 0x00000003,
CR_INVALID_FLAG = 0x00000004,
CR_INVALID_DEVNODE = 0x00000005,
CR_INVALID_DEVINST = CR_INVALID_DEVNODE,
CR_INVALID_RES_DES = 0x00000006,
CR_INVALID_LOG_CONF = 0x00000007,
CR_INVALID_ARBITRATOR = 0x00000008,
CR_INVALID_NODELIST = 0x00000009,
CR_DEVNODE_HAS_REQS = 0x0000000A,
CR_DEVINST_HAS_REQS = CR_DEVNODE_HAS_REQS,
CR_INVALID_RESOURCEID = 0x0000000B,
CR_DLVXD_NOT_FOUND = 0x0000000C, // WIN 95 ONLY
CR_NO_SUCH_DEVNODE = 0x0000000D,
CR_NO_SUCH_DEVINST = CR_NO_SUCH_DEVNODE,
CR_NO_MORE_LOG_CONF = 0x0000000E,
CR_NO_MORE_RES_DES = 0x0000000F,
CR_ALREADY_SUCH_DEVNODE = 0x00000010,
CR_ALREADY_SUCH_DEVINST = CR_ALREADY_SUCH_DEVNODE,
CR_INVALID_RANGE_LIST = 0x00000011,
CR_INVALID_RANGE = 0x00000012,
CR_FAILURE = 0x00000013,
CR_NO_SUCH_LOGICAL_DEV = 0x00000014,
CR_CREATE_BLOCKED = 0x00000015,
CR_NOT_SYSTEM_VM = 0x00000016, // WIN 95 ONLY
CR_REMOVE_VETOED = 0x00000017,
CR_APM_VETOED = 0x00000018,
CR_INVALID_LOAD_TYPE = 0x00000019,
CR_BUFFER_SMALL = 0x0000001A,
CR_NO_ARBITRATOR = 0x0000001B,
CR_NO_REGISTRY_HANDLE = 0x0000001C,
CR_REGISTRY_ERROR = 0x0000001D,
CR_INVALID_DEVICE_ID = 0x0000001E,
CR_INVALID_DATA = 0x0000001F,
CR_INVALID_API = 0x00000020,
CR_DEVLOADER_NOT_READY = 0x00000021,
CR_NEED_RESTART = 0x00000022,
CR_NO_MORE_HW_PROFILES = 0x00000023,
CR_DEVICE_NOT_THERE = 0x00000024,
CR_NO_SUCH_VALUE = 0x00000025,
CR_WRONG_TYPE = 0x00000026,
CR_INVALID_PRIORITY = 0x00000027,
CR_NOT_DISABLEABLE = 0x00000028,
CR_FREE_RESOURCES = 0x00000029,
CR_QUERY_VETOED = 0x0000002A,
CR_CANT_SHARE_IRQ = 0x0000002B,
CR_NO_DEPENDENT = 0x0000002C,
CR_SAME_RESOURCES = 0x0000002D,
CR_NO_SUCH_REGISTRY_KEY = 0x0000002E,
CR_INVALID_MACHINENAME = 0x0000002F, // NT ONLY
CR_REMOTE_COMM_FAILURE = 0x00000030, // NT ONLY
CR_MACHINE_UNAVAILABLE = 0x00000031, // NT ONLY
CR_NO_CM_SERVICES = 0x00000032, // NT ONLY
CR_ACCESS_DENIED = 0x00000033, // NT ONLY
CR_CALL_NOT_IMPLEMENTED = 0x00000034,
CR_INVALID_PROPERTY = 0x00000035,
CR_DEVICE_INTERFACE_ACTIVE = 0x00000036,
CR_NO_SUCH_DEVICE_INTERFACE = 0x00000037,
CR_INVALID_REFERENCE_STRING = 0x00000038,
CR_INVALID_CONFLICT_LIST = 0x00000039,
CR_INVALID_INDEX = 0x0000003A,
CR_INVALID_STRUCTURE_SIZE = 0x0000003B,
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
}
/// Caller-supplied flags that specify the type of the logical configuration.
[PInvokeData("cfgmgr32.h")]
public enum LOG_CONF_FLAG
{
/// Specifies the req list.
BASIC_LOG_CONF = 0x00000000,
/// Specifies the filtered req list.
FILTERED_LOG_CONF = 0x00000001,
/// Specifies the Alloc Element.
ALLOC_LOG_CONF = 0x00000002,
/// Specifies the RM Alloc Element.
BOOT_LOG_CONF = 0x00000003,
/// Specifies the Forced Log Conf
FORCED_LOG_CONF = 0x00000004,
/// Specifies the Override req list.
OVERRIDE_LOG_CONF = 0x00000005,
/// Number of Log Conf type
NUM_LOG_CONF = 0x00000006,
/// The bits of the log conf type.
LOG_CONF_BITS = 0x00000007,
/// Same priority, new one first
PRIORITY_EQUAL_FIRST = 0x00000008,
/// Same priority, new one last
PRIORITY_EQUAL_LAST = 0x00000000,
}
///
/// If the PnP manager rejects a request to perform an operation, the PNP_VETO_TYPE enumeration is used to identify the reason for
/// the rejection.
///
///
///
/// Text strings are associated with most of the veto types, and a function that receives a veto type value can typically request to
/// also receive the value's associated text string. The following table identifies the text string associated with each value.
///
///
///
/// pVeto type value
/// Text String
///
/// -
/// PNP_VetoTypeUnknown
/// None.
///
/// -
/// PNP_VetoLegacyDevice
/// A device instance path.
///
/// -
/// PNP_VetoPendingClose
/// A device instance path.
///
/// -
/// PNP_VetoWindowsApp
/// An application module name.
///
/// -
/// PNP_VetoWindowsService
/// A Windows service name.
///
/// -
/// PNP_VetoOutstandingOpen
/// A device instance path.
///
/// -
/// PNP_VetoDevice
/// A device instance path.
///
/// -
/// PNP_VetoDriver
/// A driver name.
///
/// -
/// PNP_VetoIllegalDeviceRequest
/// A device instance path.
///
/// -
/// PNP_VetoInsufficientPower
/// None.
///
/// -
/// PNP_VetoNonDisableable
/// A device instance path.
///
/// -
/// PNP_VetoLegacyDriver
/// A Windows service name.
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/cfg/ne-cfg-pnp_veto_type typedef enum _PNP_VETO_TYPE { PNP_VetoTypeUnknown,
// PNP_VetoLegacyDevice, PNP_VetoPendingClose, PNP_VetoWindowsApp, PNP_VetoWindowsService, PNP_VetoOutstandingOpen, PNP_VetoDevice,
// PNP_VetoDriver, PNP_VetoIllegalDeviceRequest, PNP_VetoInsufficientPower, PNP_VetoNonDisableable, PNP_VetoLegacyDriver,
// PNP_VetoInsufficientRights, PNP_VetoAlreadyRemoved } PNP_VETO_TYPE, *PPNP_VETO_TYPE;
[PInvokeData("cfg.h", MSDNShortId = "NE:cfg._PNP_VETO_TYPE")]
public enum PNP_VETO_TYPE
{
/// The specified operation was rejected for an unknown reason.
PNP_VetoTypeUnknown,
/// The device does not support the specified PnP operation.
PNP_VetoLegacyDevice,
/// The specified operation cannot be completed because of a pending close operation.
PNP_VetoPendingClose,
/// A Microsoft Win32 application vetoed the specified operation.
PNP_VetoWindowsApp,
/// A Win32 service vetoed the specified operation.
PNP_VetoWindowsService,
/// The requested operation was rejected because of outstanding open handles.
PNP_VetoOutstandingOpen,
/// The device supports the specified operation, but the device rejected the operation.
PNP_VetoDevice,
/// The driver supports the specified operation, but the driver rejected the operation.
PNP_VetoDriver,
/// The device does not support the specified operation.
PNP_VetoIllegalDeviceRequest,
/// There is insufficient power to perform the requested operation.
PNP_VetoInsufficientPower,
/// The device cannot be disabled.
PNP_VetoNonDisableable,
/// The driver does not support the specified PnP operation.
PNP_VetoLegacyDriver,
/// The caller has insufficient privileges to complete the operation.
PNP_VetoInsufficientRights,
}
/// Caller-supplied configuration priority value.
[PInvokeData("cfg.h")]
public enum PRIORITY
{
/// Coming from a forced config
LCPRI_FORCECONFIG = 0x00000000,
/// Coming from a boot config
LCPRI_BOOTCONFIG = 0x00000001,
/// Preferable (better performance)
LCPRI_DESIRED = 0x00002000,
/// Workable (acceptable performance)
LCPRI_NORMAL = 0x00003000,
/// CM only--do not use
LCPRI_LASTBESTCONFIG = 0x00003FFF,
/// Not desired, but will work
LCPRI_SUBOPTIMAL = 0x00005000,
/// CM only--do not use
LCPRI_LASTSOFTCONFIG = 0x00007FFF,
/// Need to restart
LCPRI_RESTART = 0x00008000,
/// Need to reboot
LCPRI_REBOOT = 0x00009000,
/// Need to shutdown/power-off
LCPRI_POWEROFF = 0x0000A000,
/// Need to change a jumper
LCPRI_HARDRECONFIG = 0x0000C000,
/// Cannot be changed
LCPRI_HARDWIRED = 0x0000E000,
/// Impossible configuration
LCPRI_IMPOSSIBLE = 0x0000F000,
/// Disabled configuration
LCPRI_DISABLED = 0x0000FFFF,
}
/// Caller-supplied resource type identifier, which identifies the type of structure supplied by ResourceData.
[PInvokeData("cfgmgr32.h")]
public enum RESOURCEID
{
/// Return all resource types
ResType_All = 0x00000000,
/// Arbitration always succeeded
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
ResType_MemLarge = 0x00000007,
/// Maximum known (arbitrated) ResType
ResType_MAX = 0x00000007,
/// Ignore this resource
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,
}
///
/// The CM_Add_Empty_Log_Conf function creates an empty logical configuration, for a specified configuration type and a
/// specified device instance, on the local machine.
///
/// Address of a location to receive the handle to an empty logical configuration.
/// Caller-supplied device instance handle that is bound to the local machine.
///
///
/// Caller-supplied configuration priority value. This must be one of the constant values listed in the following table. The
/// constants are listed in order of priority, from highest to lowest. (For multiple configurations with the same ulFlags value, the
/// system will attempt to use the one with the highest priority first.)
///
///
///
/// Priority Constant
/// Definition
///
/// -
/// LCPRI_FORCECONFIG
/// Result of a forced configuration.
///
/// -
/// LCPRI_BOOTCONFIG
/// Result of a boot configuration.
///
/// -
/// LCPRI_DESIRED
/// Preferred configuration (better performance).
///
/// -
/// LCPRI_NORMAL
/// Workable configuration (acceptable performance).
///
/// -
/// LCPRI_LASTBESTCONFIG
/// For internal use only.
///
/// -
/// LCPRI_SUBOPTIMAL
/// Not a desirable configuration, but it will work.
///
/// -
/// LCPRI_LASTSOFTCONFIG
/// For internal use only.
///
/// -
/// LCPRI_RESTART
/// The system must be restarted
///
/// -
/// LCPRI_REBOOT
/// The system must be restarted (same as LCPRI_RESTART).
///
/// -
/// LCPRI_POWEROFF
/// The system must be shut down and powered off.
///
/// -
/// LCPRI_HARDRECONFIG
/// A jumper must be changed.
///
/// -
/// LCPRI_HARDWIRED
/// The configuration cannot be changed.
///
/// -
/// LCPRI_IMPOSSIBLE
/// The configuration cannot exist.
///
/// -
/// LCPRI_DISABLED
/// Disabled configuration.
///
///
///
///
/// Caller-supplied flags that specify the type of the logical configuration. One of the following flags must be specified.
///
///
/// Configuration Type Flags
/// Definitions
///
/// -
/// BASIC_LOG_CONF
/// Resource descriptors added to this configuration will describe a basic configuration.
///
/// -
/// FILTERED_LOG_CONF
/// Do not use. (Only the PnP manager can create a filtered configuration.)
///
/// -
/// ALLOC_LOG_CONF
/// Do not use. (Only the PnP manager can create an allocated configuration.)
///
/// -
/// BOOT_LOG_CONF
/// Resource descriptors added to this configuration will describe a boot configuration.
///
/// -
/// FORCED_LOG_CONF
/// Resource descriptors added to this configuration will describe a forced configuration.
///
/// -
/// OVERRIDE_LOG_CONF
/// Resource descriptors added to this configuration will describe an override configuration.
///
///
/// One of the following bit flags can be ORed with the configuration type flag.
///
///
/// Priority Comparison Flags
/// Definitions
///
/// -
/// PRIORITY_EQUAL_FIRST
///
/// If multiple configurations of the same type (ulFlags) have the same priority (Priority), this configuration is placed at the
/// head of the list.
///
///
/// -
/// PRIORITY_EQUAL_LAST
///
/// (Default) If multiple configurations of the same type (ulFlags) have the same priority (Priority), this configuration is placed
/// at the tail of the list.
///
///
///
///
///
///
/// 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_Add_Empty_Log_Conf 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.
///
///
///
///
/// Calling CM_Add_Empty_Log_Conf can cause the handles returned by CM_Get_First_Log_Conf and CM_Get_Next_Log_Conf to become
/// invalid. Thus if you want to obtain logical configurations after calling CM_Add_Empty_Log_Conf, your code must call
/// CM_Get_First_Log_Conf again and start at the first configuration.
///
/// To remove a logical configuration created by CM_Add_Empty_Log_Conf, call CM_Free_Log_Conf.
/// The handle received in plcLogConf must be explicitly freed by calling CM_Free_Log_Conf_Handle.
///
/// 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_add_empty_log_conf CMAPI CONFIGRET
// CM_Add_Empty_Log_Conf( PLOG_CONF plcLogConf, DEVINST dnDevInst, PRIORITY Priority, ULONG ulFlags );
[DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Add_Empty_Log_Conf")]
public static extern CONFIGRET CM_Add_Empty_Log_Conf(out SafeLOG_CONF plcLogConf, uint dnDevInst, PRIORITY Priority, LOG_CONF_FLAG ulFlags);
///
///
/// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated. Please use CM_Add_Empty_Log_Conf instead.]
///
///
/// The CM_Add_Empty_Log_Conf_Ex function creates an empty logical configuration, for a specified configuration type and a
/// specified device instance, on either the local or a remote machine.
///
///
/// Pointer to a location to receive the handle to an empty logical configuration.
/// Caller-supplied device instance handle that is bound to the machine handle supplied by hMachine.
///
/// Caller-supplied configuration priority value. For a list of values, see the Priority description for CM_Add_Empty_Log_Conf.
///
///
/// Caller-supplied flags that specify the type of the logical configuration. For a list of flags, see the description ulFlags
/// description for CM_Add_Empty_Log_Conf.
///
///
/// 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.
///
///
/// Note Starting with Windows 8, CM_Add_Empty_Log_Conf_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.
///
///
///
///
/// Calling CM_Add_Empty_Log_Conf_Ex can cause the handles returned by CM_Get_First_Log_Conf_Ex and CM_Get_Next_Log_Conf_Ex
/// to become invalid. Thus if you want to obtain logical configurations after calling CM_Add_Empty_Log_Conf_Ex, your code
/// must call CM_Get_First_Log_Conf_Ex again and start at the first configuration.
///
/// To remove a logical configuration created by CM_Add_Empty_Log_Conf_Ex, call CM_Free_Log_Conf_Ex.
/// The handle received in plcLogConf must be explicitly freed by calling CM_Free_Log_Conf_Handle.
///
/// 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_add_empty_log_conf_ex CMAPI CONFIGRET
// CM_Add_Empty_Log_Conf_Ex( PLOG_CONF plcLogConf, DEVINST dnDevInst, PRIORITY Priority, ULONG ulFlags, HMACHINE hMachine );
[DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Add_Empty_Log_Conf_Ex")]
public static extern CONFIGRET CM_Add_Empty_Log_Conf_Ex(out SafeLOG_CONF plcLogConf, uint dnDevInst, PRIORITY Priority, LOG_CONF_FLAG ulFlags, HMACHINE hMachine);
///
/// The CM_Add_ID function appends a specified device ID (if not already present) to a device instance's hardware ID list or
/// compatible ID list.
///
/// Caller-supplied device instance handle that is bound to the local machine.
/// Caller-supplied pointer to a NULL-terminated device ID string.
///
///
/// Caller-supplied flag constant that specifies the list onto which the supplied device ID should be appended. The following flag
/// constants are valid.
///
///
///
/// Flag Constant
/// Definition
///
/// -
/// CM_ADD_ID_COMPATIBLE
/// The specified device ID should be appended to the specific device instance's compatible ID list.
///
/// -
/// CM_ADD_ID_HARDWARE
/// The specified device ID should be appended to the specific device instance's hardware ID list.
///
///
///
///
/// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h.
///
///
///
/// The CM_Add_ID function can only be used when dnDevInst represents a root-enumerated device. For other devices, the bus
/// driver reports hardware and compatible IDs when enumerating a child device after receiving IRP_MN_QUERY_ID.
///
///
/// Each appended device ID is considered less compatible than IDs already existing in the specified list. For information about
/// device IDs, hardware IDs, and compatible IDs, see Device Identification Strings.
///
///
/// 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_add_idw CMAPI CONFIGRET CM_Add_IDW( DEVINST dnDevInst,
// PWSTR pszID, ULONG ulFlags );
[DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Add_IDW")]
public static extern CONFIGRET CM_Add_ID(uint dnDevInst, string pszID, CM_ADD_ID ulFlags);
///
/// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated. Please use CM_Add_ID instead.]
///
/// The CM_Add_ID_Ex function appends a device ID (if not already present) to a device instance's hardware ID list or
/// compatible ID list, on either the local or a remote machine.
///
///
///
/// Caller-supplied device instance handle that is bound to the machine handle supplied by
/// hMachine
/// .
///
/// Caller-supplied pointer to a NULL-terminated device ID string.
///
///
/// Caller-supplied flag constant that specifies the list onto which the supplied device ID should be appended. The following flag
/// constants are valid.
///
///
///
/// Flag Constant
/// Definition
///
/// -
/// CM_ADD_ID_COMPATIBLE
/// The specified device ID should be appended to the specific device instance's compatible ID list.
///
/// -
/// CM_ADD_ID_HARDWARE
/// The specified device ID should be appended to the specific device instance's hardware ID list.
///
///
///
///
/// 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.
///
///
///
/// Each appended device ID is considered less compatible than IDs already existing in the specified list. For information about
/// device IDs, hardware IDs, and compatible IDs, see Device Identification Strings.
///
///
/// 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_add_id_exw CMAPI CONFIGRET CM_Add_ID_ExW( DEVINST
// dnDevInst, PWSTR pszID, ULONG ulFlags, HMACHINE hMachine );
[DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Add_ID_ExW")]
public static extern CONFIGRET CM_Add_ID_Ex(uint dnDevInst, string pszID, CM_ADD_ID ulFlags, HMACHINE hMachine);
/// The CM_Add_Res_Des function adds a resource descriptor to a logical configuration.
/// Pointer to a location to receive a handle to the new resource descriptor.
///
///
/// 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 type identifier, which identifies the type of structure supplied by ResourceData. This must be one of
/// the ResType_-prefixed constants defined in Cfgmgr32.h.
///
///
/// Caller-supplied pointer to one of the resource structures listed in the following table.
///
///
/// ResourceID Parameter
/// Resource Structure
///
/// -
/// ResType_BusNumber
/// BUSNUMBER_RESOURCE
///
/// -
/// ResType_ClassSpecific
/// CS_RESOURCE
///
/// -
/// ResType_DevicePrivate
/// DEVPRIVATE_RESOURCE
///
/// -
/// ResType_DMA
/// DMA_RESOURCE
///
/// -
/// ResType_IO
/// IO_RESOURCE
///
/// -
/// ResType_IRQ
/// IRQ_RESOURCE
///
/// -
/// ResType_Mem
/// MEM_RESOURCE
///
/// -
/// ResType_MfCardConfig
/// MFCARD_RESOURCE
///
/// -
/// ResType_PcCardConfig
/// PCCARD_RESOURCE
///
///
///
/// 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_Add_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.
///
///
///
///
/// Callers of CM_Add_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_add_res_des CMAPI CONFIGRET CM_Add_Res_Des( PRES_DES
// prdResDes, LOG_CONF lcLogConf, RESOURCEID ResourceID, PCVOID ResourceData, ULONG ResourceLen, ULONG ulFlags );
[DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)]
[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.]
///
/// The CM_Add_Res_Des_Ex function adds a resource descriptor to a logical configuration. The logical configuration can be on
/// either the local or a remote machine.
///
///
/// Pointer to a location to receive a handle to the new resource descriptor.
///
///
/// 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 type identifier, which identifies the type of structure supplied by ResourceData. This must be one of
/// the ResType_-prefixed constants defined in Cfgmgr32.h.
///
///
/// Caller-supplied pointer to one of the resource structures listed in the following table.
///
///
/// ResourceID Parameter
/// Resource Structure
///
/// -
/// ResType_BusNumber
/// BUSNUMBER_RESOURCE
///
/// -
/// ResType_ClassSpecific
/// CS_RESOURCE
///
/// -
/// ResType_DevicePrivate
/// DEVPRIVATE_RESOURCE
///
/// -
/// ResType_DMA
/// DMA_RESOURCE
///
/// -
/// ResType_IO
/// IO_RESOURCE
///
/// -
/// ResType_IRQ
/// IRQ_RESOURCE
///
/// -
/// ResType_Mem
/// MEM_RESOURCE
///
/// -
/// ResType_MfCardConfig
/// MFCARD_RESOURCE
///
/// -
/// ResType_PcCardConfig
/// PCCARD_RESOURCE
///
///
///
/// 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, or NULL.
///
/// 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_Add_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.
///
///
///
///
/// Callers of CM_Add_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_add_res_des_ex CMAPI CONFIGRET CM_Add_Res_Des_Ex(
// PRES_DES prdResDes, LOG_CONF lcLogConf, RESOURCEID ResourceID, PCVOID ResourceData, ULONG ResourceLen, ULONG ulFlags, HMACHINE
// hMachine );
[DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Add_Res_Des_Ex")]
public static extern CONFIGRET CM_Add_Res_Des_Ex(out SafeRES_DES prdResDes, LOG_CONF lcLogConf, RESOURCEID ResourceID, IntPtr ResourceData,
uint ResourceLen, [In, Optional] uint ulFlags, [In, Optional] HMACHINE hMachine);
///
///
/// [Beginning in Windows 8 and Windows Server 2012 functionality to access remote machines has been removed. You cannot access
/// remote machines when running on these versions of Windows.]
///
/// The CM_Connect_Machine function creates a connection to a remote machine.
///
///
/// Caller-supplied pointer to a text string representing the UNC name, including the \ prefix, of the system for which a
/// connection will be made. If the pointer is NULL, the local system is used.
///
///
/// Address of a location to receive a machine handle.
///
/// 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.
///
///
///
/// Callers of CM_Connect_Machine must call CM_Disconnect_Machine to deallocate the machine handle, after it is no longer needed.
///
/// Use machine handles obtained with this function only with the PnP configuration manager functions.
///
/// 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_connect_machinew CMAPI CONFIGRET CM_Connect_MachineW(
// PCWSTR UNCServerName, PHMACHINE phMachine );
[DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Connect_MachineW")]
public static extern CONFIGRET CM_Connect_Machine(string UNCServerName, out SafeHMACHINE phMachine);
/// The CM_Delete_Class_Key function removes the specified installed device class from the system.
/// Pointer to the GUID of the device class to remove.
///
/// Delete class key flags:
/// CM_DELETE_CLASS_ONLY
/// Delete the class only if it does not contain any subkeys.
/// CM_DELETE_CLASS_SUBKEYS
/// Delete the class and all of its subkeys.
/// CM_DELETE_CLASS_INTERFACE (available only in Windows Vista and later)
/// Indicates that ClassGuid specifies a device interface class and not a device setup class.
///
///
/// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h.
///
// https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_delete_class_key CMAPI CONFIGRET CM_Delete_Class_Key(
// LPGUID ClassGuid, ULONG ulFlags );
[DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Delete_Class_Key")]
public static extern CONFIGRET CM_Delete_Class_Key(in Guid ClassGuid, CM_DELETE_CLASS ulFlags);
///
/// The CM_Delete_Device_Interface_Key function deletes the registry subkey that is used by applications and drivers to store
/// interface-specific information.
///
///
/// Pointer to a string that identifies the device interface instance of the registry subkey to delete.
///
/// 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.
///
// https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_delete_device_interface_keyw CMAPI CONFIGRET
// CM_Delete_Device_Interface_KeyW( LPCWSTR pszDeviceInterface, ULONG ulFlags );
[DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Unicode)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Delete_Device_Interface_KeyW")]
public static extern CONFIGRET CM_Delete_Device_Interface_Key(string pszDeviceInterface, uint ulFlags = 0);
///
///
/// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated. Please use CM_Delete_Device_Interface_Key instead.]
///
///
/// The CM_Delete_Device_Interface_Key_ExW function deletes the registry subkey that is used by applications and drivers to
/// store interface-specific information.
///
///
///
/// Pointer to a string that identifies the device interface instance of the registry subkey to delete.
///
/// 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.
///
///
/// Note
///
/// The cfgmgr32.h header defines CM_Delete_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_delete_device_interface_key_exw CMAPI CONFIGRET
// CM_Delete_Device_Interface_Key_ExW( LPCWSTR pszDeviceInterface, ULONG ulFlags, HMACHINE hMachine );
[DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Delete_Device_Interface_Key_ExW")]
public static extern CONFIGRET CM_Delete_Device_Interface_Key_Ex(string pszDeviceInterface, [In, Optional] uint ulFlags, [In, Optional] HMACHINE hMachine);
///
/// The CM_Delete_DevNode_Key function deletes the specified user-accessible registry keys that are associated with a device.
///
/// Device instance handle that is bound to the local machine.
///
/// The hardware profile to delete if ulFlags includes CM_REGISTRY_CONFIG. If this value is zero, the key for the current hardware
/// profile is deleted. If this value is 0xFFFFFFFF, the registry keys for all hardware profiles are deleted.
///
///
///
/// Delete device node key flags. Indicates the scope and type of registry storage key to delete. Can be a combination of the
/// following flags:
///
/// CM_REGISTRY_HARDWARE
/// Delete the device’s hardware key. Do not combine with CM_REGISTRY_SOFTWARE.
/// CM_REGISTRY_SOFTWARE
/// Delete the device’s software key. Do not combine with CM_REGISTRY_HARDWARE.
/// CM_REGISTRY_USER
/// Delete the per-user key for the current user. Do not combine with CM_REGISTRY_CONFIG.
/// CM_REGISTRY_CONFIG
/// Delete 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.
///
// https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_delete_devnode_key CMAPI CONFIGRET
// CM_Delete_DevNode_Key( DEVNODE dnDevNode, ULONG ulHardwareProfile, ULONG ulFlags );
[DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Delete_DevNode_Key")]
public static extern CONFIGRET CM_Delete_DevNode_Key(uint dnDevNode, uint ulHardwareProfile, CM_REGISTRY ulFlags);
/// The CM_Disable_DevNode function disables a device.
/// Device instance handle that is bound to the local machine.
///
/// Disable flags:
/// CM_DISABLE_UI_NOT_OK
/// Do not display any interface to the user if the attempt to disable the device fails.
/// CM_DISABLE_PERSIST
/// Disables the device across reboots.
///
///
/// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h.
///
///
/// By default, CM_Disable_DevNode disables a device at one time, but after reboot the device is enabled again. Starting in
/// Windows 10, you can specify the CM_DISABLE_PERSIST flag to disable the device across reboots.
///
// https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_disable_devnode CMAPI CONFIGRET CM_Disable_DevNode(
// 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 = 0);
///
///
/// [Beginning in Windows 8 and Windows Server 2012 functionality to access remote machines has been removed. You cannot access
/// remote machines when running on these versions of Windows.]
///
/// The CM_Disconnect_Machine function removes a connection to a remote machine.
///
///
/// 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.
///
///
/// 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_disconnect_machine CMAPI CONFIGRET
// CM_Disconnect_Machine( HMACHINE hMachine );
[DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Disconnect_Machine")]
public static extern CONFIGRET CM_Disconnect_Machine(HMACHINE hMachine);
/// The CM_Enable_DevNode function enables a device.
/// 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.
///
// https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_enable_devnode CMAPI CONFIGRET CM_Enable_DevNode(
// DEVINST dnDevInst, ULONG ulFlags );
[DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Enable_DevNode")]
public static extern CONFIGRET CM_Enable_DevNode(uint dnDevInst, uint ulFlags = 0);
///
/// The CM_Enumerate_Classes function, when called repeatedly, enumerates the local machine's installed device classes by
/// supplying each class's GUID.
///
///
/// Caller-supplied index into the machine's list of device classes. For more information, see the Remarks section.
///
///
/// Caller-supplied address of a GUID structure (described in the Microsoft Windows SDK) to receive a device class's GUID.
///
///
/// Beginning with Windows 8, callers can specify the following flags:
/// CM_ENUMERATE_CLASSES_INSTALLER
/// Enumerate device setup classes.
/// CM_ENUMERATE_CLASSES_INTERFACE
/// Enumerate device interface classes.
/// Otherwise, should 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.
///
///
///
/// To enumerate the local machine's device classes, call CM_Enumerate_Classes repeatedly, starting with a ulClassIndex value
/// of zero and incrementing the index value with each subsequent call until the function returns CR_NO_SUCH_VALUE. Some index
/// values might represent list entries containing invalid class data, in which case the function returns CR_INVALID_DATA. This
/// return value can be ignored.
///
/// The class GUIDs obtained from this function can be used as input to the device installation functions.
///
/// Beginning with Windows 8 and later operating systems, callers can use the ulFlags member to specify which device classes
/// CM_Enumerate_Classes should return. Prior to Windows 8, CM_Enumerate_Classes returned only device setup classes.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_enumerate_classes CMAPI CONFIGRET
// CM_Enumerate_Classes( ULONG ulClassIndex, LPGUID ClassGuid, ULONG ulFlags );
[DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Enumerate_Classes")]
public static extern CONFIGRET CM_Enumerate_Classes(uint ulClassIndex, out Guid ClassGuid, CM_ENUMERATE_CLASSES ulFlags);
///
/// The CM_Enumerate_Classes function, when called repeatedly, enumerates the local machine's installed device classes by
/// supplying each class's GUID.
///
///
/// Beginning with Windows 8, callers can specify the following flags:
/// CM_ENUMERATE_CLASSES_INSTALLER
/// Enumerate device setup classes.
/// CM_ENUMERATE_CLASSES_INTERFACE
/// Enumerate device interface classes.
/// Otherwise, should be set to zero.
///
/// A sequence of device class GUIDs.
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Enumerate_Classes")]
public static IEnumerable CM_Enumerate_Classes(CM_ENUMERATE_CLASSES ulFlags)
{
var i = 0U;
var cr = CM_Enumerate_Classes(i, out var guid, ulFlags);
while (cr == CONFIGRET.CR_SUCCESS || cr == CONFIGRET.CR_INVALID_DATA)
{
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();
}
///
///
/// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated. Please use CM_Enumerate_Classes instead.]
///
///
/// The CM_Enumerate_Classes_Ex function, when called repeatedly, enumerates a local or a remote machine's installed device
/// classes, by supplying each class's GUID.
///
///
///
/// Caller-supplied index into the machine's list of device classes. For more information, see the following Remarks section.
///
///
/// Caller-supplied address of a GUID structure (described in the Microsoft Windows SDK) to receive a device class's GUID.
///
///
/// Beginning with Windows 8, callers can specify the following flags:
/// CM_ENUMERATE_CLASSES_INSTALLER
/// Enumerate device setup classes.
/// CM_ENUMERATE_CLASSES_INTERFACE
/// Enumerate device interface classes.
/// Otherwise, should 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.
///
///
///
/// To enumerate the local or a remote machine's device classes, call CM_Enumerate_Classes_Ex repeatedly, starting with a
/// ulClassIndex index value of zero and incrementing the index value with each subsequent call until the function returns
/// CR_NO_SUCH_VALUE. Some index values might represent list entries containing invalid class data, in which case the function
/// returns CR_INVALID_DATA. This return value can be ignored.
///
/// The class GUIDs obtained from this function can be used as input to the device installation functions.
///
/// Beginning with Windows 8 and later operating systems, callers can use the ulFlags member to specify which device classes
/// CM_Enumerate_Classes_Ex should return. Prior to Windows 8, CM_Enumerate_Classes_Ex returned only device setup classes.
///
///
/// 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_enumerate_classes_ex CMAPI CONFIGRET
// CM_Enumerate_Classes_Ex( ULONG ulClassIndex, LPGUID ClassGuid, ULONG ulFlags, HMACHINE hMachine );
[DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Enumerate_Classes_Ex")]
public static extern CONFIGRET CM_Enumerate_Classes_Ex(uint ulClassIndex, out Guid ClassGuid, CM_ENUMERATE_CLASSES ulFlags, [In, Optional] HMACHINE hMachine);
///
/// The CM_Enumerate_Enumerators function enumerates the local machine's device enumerators by supplying each enumerator's name.
///
///
/// Caller-supplied index into the machine's list of device enumerators. For more information, see the following Remarks section.
///
///
/// Address of a buffer to receive an enumerator name. This buffer should be MAX_DEVICE_ID_LEN-sized (or, set Buffer to zero and
/// obtain the actual name length in the location referenced by puLength).
///
///
/// Caller-supplied address of a location to hold the buffer size. The caller supplies the length of the buffer pointed to by
/// Buffer. The function replaces this value with the actual size of the enumerator's name string. If the caller-supplied buffer
/// length is too small, the function supplies the required buffer size and returns CR_BUFFER_SMALL.
///
/// 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 the local machine's device enumerators, call CM_Enumerate_Enumerators repeatedly, starting with a
/// ulEnumIndex index value of zero. and incrementing the index value with each subsequent call until the function returns CR_NO_SUCH_VALUE.
///
/// After enumerator names have been obtained, the names can be used as input to CM_Get_Device_ID_List.
///
// https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_enumerate_enumeratorsw CMAPI CONFIGRET
// CM_Enumerate_EnumeratorsW( ULONG ulEnumIndex, PWSTR Buffer, PULONG pulLength, ULONG ulFlags );
[DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Enumerate_EnumeratorsW")]
public static extern CONFIGRET CM_Enumerate_Enumerators(uint ulEnumIndex, StringBuilder Buffer, ref int pulLength, uint ulFlags = 0);
///
/// The CM_Enumerate_Enumerators function enumerates the local machine's device enumerators by supplying each enumerator's name.
///
/// A sequence of enumerator names.
public static IEnumerable CM_Enumerate_Enumerators()
{
var i = 0U;
CONFIGRET cr;
var sbCap = MAX_DEVICE_ID_LEN;
StringBuilder sb = new(sbCap);
while ((cr = CM_Enumerate_Enumerators(i, sb, ref sbCap)) == CONFIGRET.CR_SUCCESS)
{
yield return sb.ToString();
i++;
sbCap = sb.Capacity;
}
if (cr != CONFIGRET.CR_NO_SUCH_VALUE && cr != CONFIGRET.CR_SUCCESS)
throw cr.GetException();
}
///
///
/// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated. Please use CM_Enumerate_Enumerators instead.]
///
///
/// The CM_Enumerate_Enumerators_Ex function enumerates a local or a remote machine's device enumerators, by supplying each
/// enumerator's name.
///
///
///
/// Caller-supplied index into the machine's list of device enumerators. For more information, see the following Remarks section.
///
///
/// Address of a buffer to receive an enumerator name. This buffer should be MAX_DEVICE_ID_LEN-sized (or, set Buffer to zero and
/// obtain the actual name length in the location referenced by puLength).
///
///
/// Caller-supplied address of a location to hold the buffer size. The caller supplies the length of the buffer pointed to by
/// Buffer. The function replaces this value with the actual size of the enumerator's name string. If the caller-supplied buffer
/// length is too small, the function supplies the required buffer size and returns CR_BUFFER_SMALL.
///
/// 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.
///
///
///
/// To enumerate the local or a remote machine's device enumerators, call CM_Enumerate_Enumerators_Ex repeatedly, starting
/// with a ulEnumIndex index value of zero, and incrementing the index value with each subsequent call until the function returns CR_NO_SUCH_VALUE.
///
/// After enumerator names have been obtained, the names can be used as input to CM_Get_Device_ID_List.
///
/// 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_enumerate_enumerators_exw CMAPI CONFIGRET
// CM_Enumerate_Enumerators_ExW( ULONG ulEnumIndex, PWSTR Buffer, PULONG pulLength, ULONG ulFlags, HMACHINE hMachine );
[DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Enumerate_Enumerators_ExW")]
public static extern CONFIGRET CM_Enumerate_Enumerators_Ex(uint ulEnumIndex, StringBuilder Buffer, ref int pulLength, [In, Optional] uint ulFlags, [In, Optional] HMACHINE hMachine);
///
/// The CM_Free_Log_Conf function removes a logical configuration and all associated resource descriptors from the local machine.
///
///
///
/// Caller-supplied handle to a logical configuration. 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
///
/// 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_Free_Log_Conf 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.
///
///
///
///
/// Calling CM_Free_Log_Conf can cause the handles returned by CM_Get_First_Log_Conf and CM_Get_Next_Log_Conf to become
/// invalid. Thus if you want to obtain logical configurations after calling CM_Free_Log_Conf, your code must call
/// CM_Get_First_Log_Conf again and start at the first configuration.
///
///
/// Note that calling CM_Free_Log_Conf frees the configuration, but not the configuration's handle. To free the handle, call CM_Free_Log_Conf_Handle.
///
///
/// 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_free_log_conf CMAPI CONFIGRET CM_Free_Log_Conf(
// LOG_CONF lcLogConfToBeFreed, ULONG ulFlags );
[DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Free_Log_Conf")]
public static extern CONFIGRET CM_Free_Log_Conf([In] LOG_CONF lcLogConfToBeFreed, uint ulFlags = 0);
///
/// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated. Please use CM_Free_Log_Conf instead.]
///
/// The CM_Free_Log_Conf_Ex function removes a logical configuration and all associated resource descriptors from either a
/// local or a remote machine.
///
///
///
///
/// Caller-supplied handle to a logical configuration. 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
///
/// 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_Free_Log_Conf_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.
///
///
///
///
/// Calling CM_Free_Log_Conf_Ex can cause the handles returned by CM_Get_First_Log_Conf_Ex and CM_Get_Next_Log_Conf_Ex to
/// become invalid. Thus if you want to obtain logical configurations after calling CM_Free_Log_Conf_Ex, your code must call
/// CM_Get_First_Log_Conf_Ex again and start at the first configuration.
///
///
/// Note that calling CM_Free_Log_Conf_Ex frees the configuration, but not the configuration's handle. To free the handle,
/// call CM_Free_Log_Conf_Handle_Ex.
///
///
/// 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_free_log_conf_ex CMAPI CONFIGRET CM_Free_Log_Conf_Ex(
// LOG_CONF lcLogConfToBeFreed, ULONG ulFlags, HMACHINE hMachine );
[DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Free_Log_Conf_Ex")]
public static extern CONFIGRET CM_Free_Log_Conf_Ex([In] LOG_CONF lcLogConfToBeFreed, [In, Optional] uint ulFlags, [In, Optional] HMACHINE hMachine);
///
/// The CM_Free_Log_Conf_Handle function invalidates a logical configuration handle and frees its associated memory allocation.
///
///
///
/// Caller-supplied logical configuration handle. 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
///
///
/// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h.
///
///
/// Each time your code calls one of the functions listed under the description of lcLogConf, it must subsequently call CM_Free_Log_Conf_Handle.
///
// https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_free_log_conf_handle CMAPI CONFIGRET
// CM_Free_Log_Conf_Handle( LOG_CONF lcLogConf );
[DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Free_Log_Conf_Handle")]
public static extern CONFIGRET CM_Free_Log_Conf_Handle(LOG_CONF lcLogConf);
/// The CM_Free_Res_Des function removes a resource descriptor from a logical configuration on the local machine.
///
/// Caller-supplied location to receive a handle to the configuration's previous resource descriptor. This parameter can be
/// NULL. For more information, see the following Remarks section.
///
///
///
/// Caller-supplied handle to the resource descriptor to be removed. 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
///
/// 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_Free_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.
///
///
///
///
/// Resource descriptors for each configuration are stored in an array. If you specify an address for prdResDes, then
/// CM_Free_Res_Des returns a handle to the resource descriptor that was previous, in the array, to the one removed. If the
/// handle specified by rdResDes represents the resource descriptor located first in the array, then prdResDes receives a handle to
/// the logical configuration.
///
///
/// Note that calling CM_Free_Res_Des frees the resource descriptor, but not the descriptor's handle. To free the handle,
/// call CM_Free_Res_Des_Handle.
///
///
/// 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_free_res_des CMAPI CONFIGRET CM_Free_Res_Des( PRES_DES
// prdResDes, RES_DES rdResDes, ULONG ulFlags );
[DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Free_Res_Des")]
public static extern CONFIGRET CM_Free_Res_Des(out SafeRES_DES prdResDes, RES_DES rdResDes, uint ulFlags = 0);
/// The CM_Free_Res_Des function removes a resource descriptor from a logical configuration on the local machine.
///
/// Caller-supplied location to receive a handle to the configuration's previous resource descriptor. This parameter can be
/// NULL. For more information, see the following Remarks section.
///
///
///
/// Caller-supplied handle to the resource descriptor to be removed. 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
///
/// 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_Free_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.
///
///
///
///
/// Resource descriptors for each configuration are stored in an array. If you specify an address for prdResDes, then
/// CM_Free_Res_Des returns a handle to the resource descriptor that was previous, in the array, to the one removed. If the
/// handle specified by rdResDes represents the resource descriptor located first in the array, then prdResDes receives a handle to
/// the logical configuration.
///
///
/// Note that calling CM_Free_Res_Des frees the resource descriptor, but not the descriptor's handle. To free the handle,
/// call CM_Free_Res_Des_Handle.
///
///
/// 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_free_res_des CMAPI CONFIGRET CM_Free_Res_Des( PRES_DES
// prdResDes, RES_DES rdResDes, ULONG ulFlags );
[DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Free_Res_Des")]
public static extern CONFIGRET CM_Free_Res_Des([In, Optional] IntPtr prdResDes, RES_DES rdResDes, uint ulFlags = 0);
///
/// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated. Please use CM_Free_Res_Des instead.]
///
/// The CM_Free_Res_Des_Ex function removes a resource descriptor from a logical configuration on either a local or a remote machine.
///
///
///
/// Caller-supplied location to receive a handle to the configuration's previous resource descriptor. This parameter can be
/// NULL. For more information, see the following Remarks section.
///
///
///
/// Caller-supplied handle to the resource descriptor to be removed. 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
///
/// 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_Free_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.
///
///
///
///
/// Resource descriptors for each configuration are stored in an array. If you specify an address for prdResDes, then
/// CM_Free_Res_Des returns a handle to the resource descriptor that was previous, in the array, to the one removed. If the
/// handle specified by rdResDes represents the resource descriptor located first in the array, then prdResDes receives a handle to
/// the logical configuration.
///
///
/// Note that calling CM_Free_Res_Des_Ex frees the resource descriptor, but not the descriptor's handle. To free the handle,
/// call CM_Free_Res_Des_Handle_Ex.
///
///
/// 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_free_res_des_ex CMAPI CONFIGRET CM_Free_Res_Des_Ex(
// PRES_DES prdResDes, RES_DES rdResDes, ULONG ulFlags, HMACHINE hMachine );
[DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Free_Res_Des_Ex")]
public static extern CONFIGRET CM_Free_Res_Des_Ex(out SafeRES_DES prdResDes, RES_DES rdResDes, [In, Optional] uint ulFlags, [In, Optional] HMACHINE hMachine);
///
/// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated. Please use CM_Free_Res_Des instead.]
///
/// The CM_Free_Res_Des_Ex function removes a resource descriptor from a logical configuration on either a local or a remote machine.
///
///
///
/// Caller-supplied location to receive a handle to the configuration's previous resource descriptor. This parameter can be
/// NULL. For more information, see the following Remarks section.
///
///
///
/// Caller-supplied handle to the resource descriptor to be removed. 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
///
/// 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_Free_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.
///
///
///
///
/// Resource descriptors for each configuration are stored in an array. If you specify an address for prdResDes, then
/// CM_Free_Res_Des returns a handle to the resource descriptor that was previous, in the array, to the one removed. If the
/// handle specified by rdResDes represents the resource descriptor located first in the array, then prdResDes receives a handle to
/// the logical configuration.
///
///
/// Note that calling CM_Free_Res_Des_Ex frees the resource descriptor, but not the descriptor's handle. To free the handle,
/// call CM_Free_Res_Des_Handle_Ex.
///
///
/// 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_free_res_des_ex CMAPI CONFIGRET CM_Free_Res_Des_Ex(
// PRES_DES prdResDes, RES_DES rdResDes, ULONG ulFlags, HMACHINE hMachine );
[DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Free_Res_Des_Ex")]
public static extern CONFIGRET CM_Free_Res_Des_Ex([In, Optional] IntPtr prdResDes, RES_DES rdResDes, [In, Optional] uint ulFlags, [In, Optional] HMACHINE hMachine);
///
/// The CM_Free_Res_Des_Handle function invalidates a resource description handle and frees its associated memory allocation.
///
///
///
/// Caller-supplied resource descriptor handle to be freed. 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
///
///
/// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h.
///
///
/// Each time your code calls one of the functions listed under the description of rdResDes, it must subsequently call CM_Free_Res_Des_Handle.
///
// https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_free_res_des_handle CMAPI CONFIGRET
// CM_Free_Res_Des_Handle( RES_DES rdResDes );
[DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Free_Res_Des_Handle")]
public static extern CONFIGRET CM_Free_Res_Des_Handle(RES_DES rdResDes);
///
/// The CM_Free_Resource_Conflict_Handle function invalidates a handle to a resource conflict list, and frees the handle's
/// associated memory allocation.
///
///
/// Caller-supplied handle to be freed. This conflict list handle must have been previously obtained by calling CM_Query_Resource_Conflict_List.
///
///
/// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h.
///
///
/// An application must call CM_Free_Resource_Conflict_Handle after it has finished using the handle that was obtained
/// calling CM_Query_Resource_Conflict_List.
///
// https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_free_resource_conflict_handle CMAPI CONFIGRET
// CM_Free_Resource_Conflict_Handle( CONFLICT_LIST clConflictList );
[DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Free_Resource_Conflict_Handle")]
public static extern CONFIGRET CM_Free_Resource_Conflict_Handle(CONFLICT_LIST clConflictList);
///
/// The CM_Get_Child function is used to retrieve a device instance handle to the first child node of a specified device node
/// (devnode) in the local machine's device tree.
///
///
/// Caller-supplied pointer to the device instance handle to the child node that this function retrieves. The retrieved handle is
/// bound to the local machine. See the Remarks section.
///
/// 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 device
/// instance handle to the first child node, then call CM_Get_Sibling to obtain handles for the rest of the children.
///
/// Using Device Instance Handles
/// Device instance handle that you use with PnP configuration manager functions are bound to machine handles, as follows:
///
/// -
/// All local device instance handles are bound to a NULL-valued local machine handle.
///
/// -
///
/// If you use a remote machine handle to obtain a device instance handle, the resulting remote device instance handle is bound to
/// the remote machine handle.
///
///
/// -
/// A device instance handle can be used only with the machine handle to which it is bound.
///
/// -
///
/// A device instance handle can be used with another device instance handle only if both device instance handles are bound to the
/// same machine handle.
///
///
///
/// To obtain a device instance handle that is bound to the local machine, do one of the following.
///
/// -
///
/// Use one of the following functions that retrieve only local device instance handles: CM_Locate_DevNode, CM_Get_Child,
/// CM_Get_Parent, or CM_Get_Sibling.
///
///
/// -
///
/// Use one of the following functions, which retrieves local and remote device instance handles, to retrieve a local device
/// instance handle: CM_Locate_DevNode_Ex, CM_Get_Child_Ex, CM_Get_Parent_Ex, or CM_Get_Sibling_Ex.
///
///
///
///
/// You can also use the device installation functions to obtain local device instance handles from a device information set that is
/// bound to the local machine. Do the following steps:
///
///
/// -
///
/// Obtain a device information set that is bound to the local machine. (A device instance handle obtained from a device information
/// set is bound to the machine handle to which the device information set is bound. You obtain the machine handle for a device
/// information set from the RemoteMachineHandle member of its SP_DEVINFO_LIST_DETAIL_DATA structure. For a local device
/// information set that is bound to the local machine, the value of RemoteMachineHandle is NULL. Call
/// SetupDiGetDeviceInfoListDetail to obtain an SP_DEVINFO_LIST_DETAIL_DATA structure.)
///
///
/// -
/// Obtain an SP_DEVINFO_DATA structure for a device instance in the device information set.
///
/// -
/// Obtain the device instance handle for the device instance from the DevInst member of the SP_DEVINFO_DATA structure.
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_get_child CMAPI CONFIGRET CM_Get_Child( PDEVINST
// pdnDevInst, DEVINST dnDevInst, ULONG ulFlags );
[DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Get_Child")]
public static extern CONFIGRET CM_Get_Child(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_Child instead.]
///
/// The CM_Get_Child_Ex function is used to retrieve a device instance handle to the first child node of a specified device
/// node (devnode) in a local or a remote machine's device tree.
///
///
///
/// Caller-supplied pointer to the device instance handle to the child node that this function retrieves. The retrieved handle is
/// bound to the machine handle supplied by hMachine. See the Remarks section.
///
/// Caller-supplied device instance handle that is bound to the machine handle supplied 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 devnode in a local or a remote 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.
///
/// Using Device Instance Handles
/// Device instance handle that you use with PnP configuration manager functions are bound to machine handles, as follows:
///
/// -
/// All local device instance handles are bound to a NULL-valued local machine handle.
///
/// -
///
/// If you use a remote machine handle to obtain a device instance handle, the resulting remote device instance handle is bound to
/// the remote machine handle.
///
///
/// -
/// A device instance handle can be used only with the machine handle to which it is bound.
///
/// -
///
/// A device instance handle can be used with another device instance handle only if both device instance handles are bound to the
/// same machine handle.
///
///
///
/// Use CM_Connect_Machine to obtain a remote machine handle for use with remote device instance handles.
/// To obtain a local or a remote device instance handle, do one of the following.
///
/// -
///
/// Use one of the following functions to retrieve a device instance handle bound to the local machine: CM_Locate_DevNode,
/// CM_Get_Child, CM_Get_Parent, or CM_Get_Sibling.
///
///
/// -
///
/// Use one of the following functions to retrieve a device instance handle bound to a local or a remote machine:
/// CM_Locate_DevNode_Ex, CM_Get_Child_Ex, CM_Get_Parent_Ex, or CM_Get_Sibling_Ex.
///
///
///
/// You can also use the device installation functions to obtain device instance handles. Do the following steps:
///
/// -
/// Obtain a device information set.
///
/// -
/// Obtain an SP_DEVINFO_DATA structure for a device instance in the device information set.
///
/// -
/// Obtain the device instance handle for the device instance from the DevInst member of the SP_DEVINFO_DATA structure.
///
/// -
///
/// Obtain the machine handle to which the device instance handle is bound. A device instance handle obtained from a device
/// information set is bound to the machine handle to which the device information set is bound. You obtain the machine handle for a
/// device information set from the RemoteMachineHandle member of its SP_DEVINFO_LIST_DETAIL_DATA structure. (Call
/// SetupDiGetDeviceInfoListDetail to obtain an SP_DEVINFO_LIST_DETAIL_DATA structure.)
///
///
///
///
/// 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_child_ex CMAPI CONFIGRET CM_Get_Child_Ex( PDEVINST
// pdnDevInst, DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine );
[DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Get_Child_Ex")]
public static extern CONFIGRET CM_Get_Child_Ex(out uint pdnDevInst, uint dnDevInst, [In, Optional] uint ulFlags, [In, Optional] HMACHINE hMachine);
///
/// The CM_Get_Class_Property function retrieves a device property that is set for a device interface class or device setup class.
///
///
/// Pointer to the GUID that identifies the device interface class or device setup class for which to retrieve a device property
/// that is set for the device class. For information about specifying the class type, see the ulFlags parameter.
///
///
/// Pointer to a DEVPROPKEY structure that represents the device property key of the requested device class property.
///
///
/// Pointer to a DEVPROPTYPE-typed variable that receives the property-data-type identifier of the requested device class property,
/// where the property-data-type identifier is the bitwise OR between a base-data-type identifier and, if the base data type is
/// modified, a property-data-type modifier.
///
///
/// Pointer to a buffer that receives the requested device class property. CM_Get_Class_Property retrieves the requested
/// property value only if the buffer is large enough to hold all the property value data. The pointer can be NULL.
///
///
/// The size, in bytes, of the PropertyBuffer buffer. If the PropertyBuffer parameter is set to NULL, *PropertyBufferSize must be
/// set to zero. As output, if the buffer is not large enough to hold all the property value data, CM_Get_Class_Property
/// returns the size of the data, in bytes, in *PropertyBufferSize.
///
///
/// 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_Get_Class_Property is part of the Unified Device Property Model.
// https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_get_class_propertyw CMAPI CONFIGRET
// CM_Get_Class_PropertyW( LPCGUID ClassGUID, const DEVPROPKEY *PropertyKey, DEVPROPTYPE *PropertyType, PBYTE PropertyBuffer, PULONG
// PropertyBufferSize, ULONG ulFlags );
[DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Unicode)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Get_Class_PropertyW")]
public static extern CONFIGRET CM_Get_Class_Property(in Guid ClassGUID, in DEVPROPKEY PropertyKey, out DEVPROPTYPE PropertyType, [Out, Optional] IntPtr PropertyBuffer,
ref uint PropertyBufferSize, CM_CLASS_PROPERTY ulFlags);
///
///
/// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated. Please use CM_Get_Class_Property instead.]
///
///
/// The CM_Get_Class_Property_ExW function retrieves a device property that is set for a device interface class or device
/// setup class.
///
///
///
/// Pointer to the GUID that identifies the device interface class or device setup class for which to retrieve a device property
/// that is set for the device class. For information about specifying the class type, see the ulFlags parameter.
///
///
/// Pointer to a DEVPROPKEY structure that represents the device property key of the requested device class property.
///
///
/// Pointer to a DEVPROPTYPE-typed variable that receives the property-data-type identifier of the requested device class property,
/// where the property-data-type identifier is the bitwise OR between a base-data-type identifier and, if the base data type is
/// modified, a property-data-type modifier.
///
///
/// Pointer to a buffer that receives the requested device class property. CM_Get_Class_Property_ExW retrieves the requested
/// property value only if the buffer is large enough to hold all the property value data. The pointer can be NULL.
///
///
/// The size, in bytes, of the PropertyBuffer buffer. If the PropertyBuffer parameter is set to NULL, *PropertyBufferSize must be
/// set to zero. As output, if the buffer is not large enough to hold all the property value data, CM_Get_Class_Property_ExW
/// returns the size of the data, in bytes, in *PropertyBufferSize.
///
///
/// 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_Get_Class_Property_ExW is part of the Unified Device Property Model.
// https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_get_class_property_exw CMAPI CONFIGRET
// CM_Get_Class_Property_ExW( LPCGUID ClassGUID, const DEVPROPKEY *PropertyKey, DEVPROPTYPE *PropertyType, PBYTE PropertyBuffer,
// PULONG PropertyBufferSize, ULONG ulFlags, HMACHINE hMachine );
[DllImport(Lib_Cfgmgr32, SetLastError = false, CharSet = CharSet.Unicode)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Get_Class_Property_ExW")]
public static extern CONFIGRET CM_Get_Class_Property_Ex(in Guid ClassGUID, in DEVPROPKEY PropertyKey, out DEVPROPTYPE PropertyType, [Out, Optional] IntPtr PropertyBuffer,
ref uint PropertyBufferSize, CM_CLASS_PROPERTY ulFlags, [In, Optional] HMACHINE hMachine);
///
/// The CM_Get_Class_Property_Keys function retrieves an array of the device property keys that represent the device
/// properties that are set for a device interface class or device setup class.
///
///
/// Pointer to the GUID that identifies the device interface class or device setup class for which to retrieve the property keys
/// for. For information about specifying the class type, see the ulFlags parameter.
///
///
/// Pointer to a buffer that receives an array of DEVPROPKEY-typed values, where each value is a device property key that represents
/// a device property that is set for the device class. The pointer is optional and can be NULL.
///
///
/// The size, in DEVPROPKEY-typed units, of the PropertyKeyArray buffer. If PropertyKeyArray is set to NULL, *PropertyKeyCount must
/// be set to zero. As output, if PropertyKeyArray is not large enough to hold all the property key data,
/// CM_Get_Class_Property_Keys returns the count of the keys, in *PropertyKeyCount.
///
///
/// Class property key 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_Get_Class_Property_Keys is part of the Unified Device Property Model.
// https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_get_class_property_keys CMAPI CONFIGRET
// CM_Get_Class_Property_Keys( LPCGUID ClassGUID, DEVPROPKEY *PropertyKeyArray, PULONG PropertyKeyCount, ULONG ulFlags );
[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 int PropertyKeyCount, CM_CLASS_PROPERTY ulFlags);
///
///
/// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated. Please use CM_Get_Class_Property_Keys instead.]
///
///
/// The CM_Get_Class_Property_Keys_Ex function retrieves an array of the device property keys that represent the device
/// properties that are set for a device interface class or device setup class.
///
///
///
/// Pointer to the GUID that identifies the device interface class or device setup class for which to retrieve the property keys
/// for. For information about specifying the class type, see the ulFlags parameter.
///
///
/// Pointer to a buffer that receives an array of DEVPROPKEY-typed values, where each value is a device property key that represents
/// a device property that is set for the device class. The pointer is optional and can be NULL.
///
///
/// The size, in DEVPROPKEY-typed units, of the PropertyKeyArray buffer. If PropertyKeyArray is set to NULL, *PropertyKeyCount must
/// be set to zero. As output, if PropertyKeyArray is not large enough to hold all the property key data,
/// CM_Get_Class_Property_Keys_Ex returns the count of the keys, in *PropertyKeyCount.
///
///
/// Class property key 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_Get_Class_Property_Keys_Ex is part of the Unified Device Property Model.
// https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_get_class_property_keys_ex CMAPI CONFIGRET
// CM_Get_Class_Property_Keys_Ex( LPCGUID ClassGUID, DEVPROPKEY *PropertyKeyArray, PULONG PropertyKeyCount, ULONG ulFlags, HMACHINE
// hMachine );
[DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Get_Class_Property_Keys_Ex")]
public static extern CONFIGRET CM_Get_Class_Property_Keys_Ex(in Guid ClassGUID, [In, Out, Optional, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] DEVPROPKEY[] PropertyKeyArray,
ref uint PropertyKeyCount, CM_CLASS_PROPERTY ulFlags, [In, Optional] HMACHINE hMachine);
/// The CM_Get_Class_Registry_Property function retrieves a device setup class property.
/// A pointer to the GUID that represents the device setup class for which to retrieve a property.
///
///
/// A value of type ULONG that identifies the property to be retrieved. This value must be one of the following CM_CRP_Xxx values
/// that are defined in Cfgmgr32.h:
///
/// CM_CRP_UPPERFILTERS
///
/// Represents a REG_MULTI_SZ-type list of strings, where each string contains the name of an upper-level filter driver that is
/// registered for the class.
///
/// CM_CRP_LOWERFILTERS
///
/// Represents a REG_MULTI_SZ-typed list of strings, where each string contains the name of a lower-level filter drivers that is
/// registered for the class.
///
/// CM_CRP_SECURITY
/// Represents a value of type REG_BINARY that contains a variable-length, self-relative, SECURITY_DESCRIPTOR structure.
/// CM_CRP_SECURITY_SDS
///
/// Represents a string of type REG_SZ that contains a security descriptor in the Security Descriptor Definition Language (SDDL) format.
///
/// CM_CRP_DEVTYPE
///
/// Represents a value of type REG_DWORD that indicates the device type for the class. For more information, see Specifying Device Types.
///
/// CM_CRP_EXCLUSIVE
///
/// Represents a value of type REG_DWORD that indicates whether users can obtain exclusive access to devices for this class. The
/// returned value is 1 if exclusive access is allowed, or zero otherwise.
///
/// CM_CRP_CHARACTERISTICS
///
/// Represents a value of type DWORD that indicates the device characteristics for the class. For a list of characteristics flags,
/// see the DeviceCharacteristics parameter of the IoCreateDevice routine.
///
///
///
/// A pointer to a variable of type ULONG that receives the REG_Xxx constant that represents the data type of the requested
/// property. The REG_Xxx constants are defined in Winnt.h and are described in the Type member of the
/// KEY_VALUE_BASIC_INFORMATION structure. This parameter is optional and can be set to NULL.
///
///
/// A pointer to a buffer that receives the requested property data. For more information about this parameter and the buffer-size
/// parameter pulLength, see the following Remarks section.
///
///
/// A pointer to variable of type ULONG whose value, on input, is the size, in bytes, of the buffer that is supplied by Buffer. On
/// return, CM_Get_Class_Registry_Property sets this variable to the size, in bytes, of the requested property.
///
/// Reserved for internal use only. Must be set to zero.
///
/// A handle to a remote machine from which to retrieve the specified device class property. This parameter is optional, and, if it
/// is set to NULL, the property is retrieved from the local machine.
///
///
/// If the operation succeeds, CM_Get_Class_Registry_Property returns CR_SUCCESS. Otherwise, the function returns one of the
/// other CR_Xxx status codes that are defined in Cfgmgr32.h.
///
///
/// To determine the size, in bytes, of a property before attempting to retrieve the property, first call
/// CM_Get_Class_Registry_Property, supplying a NULL Buffer pointer and a pulLength value of zero. In response
/// to such a call, the function does not retrieve the property, but sets pulLength to the size of the requested property
/// and returns CR_BUFFER_SMALL. After obtaining the property size, call CM_Get_Class_Registry_Property again, supplying a
/// Buffer pointer to the buffer to receive the property data and supplying the property size in * pulLength.
///
// https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_get_class_registry_propertyw CMAPI CONFIGRET
// CM_Get_Class_Registry_PropertyW( LPGUID ClassGuid, ULONG ulProperty, PULONG pulRegDataType, PVOID Buffer, PULONG pulLength, ULONG
// 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, CM_CRP ulProperty, out REG_VALUE_TYPE pulRegDataType, [Out, Optional] IntPtr Buffer,
ref uint pulLength, [In, Optional] uint ulFlags, [In, Optional] HMACHINE hMachine);
///
/// The CM_Get_Depth function is used to obtain the depth of a specified device node (devnode) within the local machine's
/// device tree.
///
///
/// Caller-supplied address of a location to receive a depth value, where zero represents the device tree's root node, one
/// represents the root node's children, and so on.
///
/// 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.
///
/// 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_depth CMAPI CONFIGRET CM_Get_Depth( PULONG
// pulDepth, DEVINST dnDevInst, ULONG ulFlags );
[DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Get_Depth")]
public static extern CONFIGRET CM_Get_Depth(out uint pulDepth, uint dnDevInst, uint ulFlags = 0);
///
/// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated. Please use CM_Get_Depth instead.]
///
/// The CM_Get_Depth_Ex function is used to obtain the depth of a specified device node (devnode) within a local or a remote
/// machine's device tree.
///
///
///
/// Caller-supplied address of a location to receive a depth value, where zero represents the device tree's root node, one
/// represents the root node's children, and so on.
///
/// Caller-supplied device instance handle that is bound to the machine handle supplied 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.
///
///
/// 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_depth_ex CMAPI CONFIGRET CM_Get_Depth_Ex( PULONG
// pulDepth, DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine );
[DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Get_Depth_Ex")]
public static extern CONFIGRET CM_Get_Depth_Ex(out uint pulDepth, uint dnDevInst, [In, Optional] uint ulFlags, [In, Optional] HMACHINE hMachine);
///
/// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated. Please use CM_Get_Device_ID instead.]
///
/// The CM_Get_Device_ID_Ex function retrieves the device instance ID for a specified device instance on a local or a remote machine.
///
///
/// Caller-supplied device instance handle that is bound to the machine handle supplied by hMachine.
///
/// Address of a buffer to receive a device instance ID string. The required buffer size can be obtained by calling
/// CM_Get_Device_ID_Size_Ex, then incrementing the received value to allow room for the string's terminating NULL.
///
/// Caller-supplied length, in characters, of the buffer specified by Buffer.
/// 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.
///
///
///
/// The function appends a NULL terminator to the supplied device instance ID string, unless the buffer is too small to hold the
/// string. In this case, the function supplies as much of the identifier string as will fit into the buffer, and then returns CR_BUFFER_SMALL.
///
/// For information about device instance IDs, see Device Identification Strings.
/// 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_device_id_exw CMAPI CONFIGRET
// CM_Get_Device_ID_ExW( DEVINST dnDevInst, PWSTR 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_ExW")]
public static extern CONFIGRET CM_Get_Device_ID_Ex(uint dnDevInst, StringBuilder Buffer, uint BufferLen, [In, Optional] uint ulFlags, [In, Optional] HMACHINE hMachine);
///
/// The CM_Get_Device_ID_List function retrieves a list of device instance IDs for the local computer's device instances.
///
///
/// Caller-supplied pointer to a character string that is either set to a subset of the computer's device instance identifiers
/// (IDs), or to NULL. See the following description of ulFlags.
///
///
/// Address of a buffer to receive a set of NULL-terminated device instance identifier strings. The end of the set is terminated by
/// an extra NULL. The required buffer size should be obtained by calling CM_Get_Device_ID_List_Size.
///
/// Caller-supplied length, in characters, of the buffer specified by Buffer.
///
/// One of the following caller-supplied bit flags that specifies search filters:
/// CM_GETIDLIST_FILTER_BUSRELATIONS
///
/// If this flag is set, pszFilter must specify a device instance identifier. The function returns device instance IDs for the bus
/// relations of the specified device instance.
///
/// CM_GETIDLIST_FILTER_CLASS (Windows 7 and later versions of Windows)
///
/// If this flag is set, pszFilter contains a string that specifies a device setup class GUID. The returned list contains device
/// instances for which the property (referenced by the CM_DRP_CLASSGUID constant) matches the specified device setup class GUID.
///
/// The CM_DRP_CLASSGUID constant is defined in Cfgmgr32.h.
/// CM_GETIDLIST_FILTER_PRESENT (Windows 7 and later versions of Windows)
///
/// If this flag is set, the returned list contains only device instances that are currently present on the system. This value can
/// be combined with other ulFlags values, such as CM_GETIDLIST_FILTER_CLASS.
///
/// CM_GETIDLIST_FILTER_TRANSPORTRELATIONS (Windows 7 and later versions of Windows)
/// If this flag is set, pszFilter must specify the device instance identifier of a composite device node (devnode).
///
/// The function returns the device instance identifiers of the devnodes that represent the transport relations of the specified
/// composite devnode.
///
/// For more information about composite devnodes and transport relations, see the following Remarks section.
/// CM_GETIDLIST_DONOTGENERATE
///
/// Used only with CM_GETIDLIST_FILTER_SERVICE. If set, and if the device tree does not contain a devnode for the specified service,
/// this flag prevents the function from creating a devnode for the service.
///
/// CM_GETIDLIST_FILTER_EJECTRELATIONS
///
/// If this flag is set, pszFilter must specify a device instance identifier. The function returns device instance IDs for the
/// ejection relations of the specified device instance.
///
/// CM_GETIDLIST_FILTER_ENUMERATOR
///
/// If this flag is set, pszFilter must specify the name of a device enumerator, optionally followed by a device ID. The string
/// format is EnumeratorName\<DeviceID>, such as ROOT or ROOT\*PNP0500.
///
///
/// If pszFilter supplies only an enumerator name, the function returns device instance IDs for the instances of each device
/// associated with the enumerator. Enumerator names can be obtained by calling CM_Enumerate_Enumerators.
///
///
/// If pszFilter supplies both an enumerator and a device ID, the function returns device instance IDs only for the instances of the
/// specified device that is associated with the enumerator.
///
/// CM_GETIDLIST_FILTER_NONE
/// If this flag is set, pszFilter is ignored, and a list of all devices on the system is returned.
/// CM_GETIDLIST_FILTER_POWERRELATIONS
///
/// If this flag is set, pszFilter must specify a device instance identifier. The function returns device instance IDs for the power
/// relations of the specified device instance.
///
/// CM_GETIDLIST_FILTER_REMOVALRELATIONS
///
/// If this flag is set, pszFilter must specify a device instance identifier. The function returns device instance IDs for the
/// removal relations of the specified device instance.
///
/// CM_GETIDLIST_FILTER_SERVICE
///
/// If this flag is set, pszFilter must specify the name of a Microsoft Windows service (typically a driver). The function returns
/// device instance IDs for the device instances controlled by the specified service.
///
///
/// Note that if the device tree does not contain a devnode for the specified service, this function creates one by default. To
/// inhibit this behavior, also set CM_GETIDLIST_DONOTGENERATE.
///
/// If no search filter flag is specified, the function returns all device instance IDs for all device instances.
///
///
/// If the operation succeeds, the function returns CR_SUCCESS. Otherwise, it returns one of the CR_-prefixed error codes defined in Cfgmgr32.h.
///
///
///
/// 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.
///
/// Note
///
/// The cfgmgr32.h header defines CM_Get_Device_ID_List 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_get_device_id_lista CMAPI CONFIGRET
// 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([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();
}
}
///
///
/// [Beginning with Windows 8 and Windows Server 2012, this function has been deprecated. Please use CM_Get_Device_ID_List instead.]
///
///
/// The CM_Get_Device_ID_List_Ex function retrieves a list of device instance IDs for the device instances on a local or a
/// remote machine.
///
///
///
/// Caller-supplied pointer to a character string specifying a subset of the machine's device instance identifiers, or NULL.
/// See the following description of ulFlags.
///
///
/// Address of a buffer to receive a set of NULL-terminated device instance identifier strings. The end of the set is terminated by
/// an extra NULL. The required buffer size should be obtained by calling CM_Get_Device_ID_List_Size_Ex.
///
/// Caller-supplied length, in characters, of the buffer specified by Buffer.
///
/// One of the optional, caller-supplied bit flags that specify search filters. If no flags are specified, the function supplies all
/// instance identifiers for all device instances. For a list of bit flags, see the ulFlags description for CM_Get_Device_ID_List.
///
///
/// 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.
///
///
/// For information about device instance IDs, see Device Identification Strings.
///
/// 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_device_id_list_exw CMAPI CONFIGRET
// 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, [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
/// the local machine's device tree.
///
///
/// Caller-supplied pointer to the device instance handle to the parent 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.
///
/// For information about using a device instance handle that is bound to the local machine, see CM_Get_Child.
// https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/nf-cfgmgr32-cm_get_parent CMAPI CONFIGRET CM_Get_Parent( PDEVINST
// pdnDevInst, DEVINST dnDevInst, ULONG ulFlags );
[DllImport(Lib_Cfgmgr32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("cfgmgr32.h", MSDNShortId = "NF:cfgmgr32.CM_Get_Parent")]
public static extern CONFIGRET CM_Get_Parent(out uint pdnDevInst, uint dnDevInst, uint ulFlags = 0);
/// Provides a handle to a resource conflict list.
[PInvokeData("cfgmgr32.h")]
[StructLayout(LayoutKind.Sequential)]
public struct CONFLICT_LIST : IHandle
{
private readonly IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public CONFLICT_LIST(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static CONFLICT_LIST 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(CONFLICT_LIST h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator CONFLICT_LIST(IntPtr h) => new(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(CONFLICT_LIST h1, CONFLICT_LIST h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(CONFLICT_LIST h1, CONFLICT_LIST h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is CONFLICT_LIST h && handle == h.handle;
///
public override int GetHashCode() => handle.GetHashCode();
///
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}")]
public struct HMACHINE
{
private readonly IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HMACHINE(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HMACHINE 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(HMACHINE h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HMACHINE(IntPtr h) => new(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HMACHINE h1, HMACHINE h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HMACHINE h1, HMACHINE h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HMACHINE h && handle == h.handle;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a logical configuration.
[PInvokeData("cfgmgr32.h")]
[StructLayout(LayoutKind.Sequential)]
public struct LOG_CONF : IHandle
{
private readonly IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public LOG_CONF(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static LOG_CONF 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(LOG_CONF h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator LOG_CONF(IntPtr h) => new(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(LOG_CONF h1, LOG_CONF h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(LOG_CONF h1, LOG_CONF h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is LOG_CONF h && handle == h.handle;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a resource descriptor.
[PInvokeData("cfgmgr32.h")]
[StructLayout(LayoutKind.Sequential)]
public struct RES_DES : IHandle
{
private readonly IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public RES_DES(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static RES_DES 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(RES_DES h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator RES_DES(IntPtr h) => new(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(RES_DES h1, RES_DES h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(RES_DES h1, RES_DES h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is RES_DES h && handle == h.handle;
///
public override int GetHashCode() => handle.GetHashCode();
///
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
{
/// 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 SafeHMACHINE(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { }
/// Initializes a new instance of the class.
private SafeHMACHINE() : base() { }
/// Performs an implicit conversion from to .
/// The safe handle instance.
/// The result of the conversion.
public static implicit operator HMACHINE(SafeHMACHINE h) => h.handle;
///
protected override bool InternalReleaseHandle() => CM_Disconnect_Machine(handle) == 0;
}
/// Provides a for that is disposed using .
public class SafeLOG_CONF : 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 SafeLOG_CONF(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { }
/// Initializes a new instance of the class.
private SafeLOG_CONF() : base() { }
/// Performs an implicit conversion from to .
/// The safe handle instance.
/// The result of the conversion.
public static implicit operator LOG_CONF(SafeLOG_CONF h) => h.handle;
///
protected override bool InternalReleaseHandle() => CM_Free_Log_Conf_Handle(handle) == 0;
}
/// Provides a for that is disposed using .
public class SafeRES_DES : 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 SafeRES_DES(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { }
/// Initializes a new instance of the class.
private SafeRES_DES() : base() { }
/// Performs an implicit conversion from to .
/// The safe handle instance.
/// The result of the conversion.
public static implicit operator RES_DES(SafeRES_DES h) => h.handle;
///
protected override bool InternalReleaseHandle() => CM_Free_Res_Des_Handle(handle) == 0;
}
}
}