SetupDi系列函数

摘要:
返回值如果调用成功,SetupDiGetClassDevs将返回一个设备信息集的句柄,该句柄包含了与所提供参数所匹配的所有设备。SetupDiEnumDeviceInfo函数WINSETUPAPIBOOLSetupDiEnumDeviceInfo;说明:功能:返回一个SP_DEVINFO_DATA结构体,这个结构体是在一个设备信息集中指定的一个设备信息元素反复的调用该函数会返回不同设备的设备信息元素。
SetupDiClassGuidsFromName

WINSETUPAPI BOOL SetupDiClassGuidsFromNameA( PCSTR ClassName,

LPGUID ClassGuidList,

DWORD ClassGuidListSize,

PDWORD RequiredSize );

SetupDiClassGuidsFromName函数检索与指定类名关联的GUID。

ClassName:要检索的GUID的类名字;

ClassGuidList:一个数组的指针,以获得与指定类名称关联的GUID列表;

ClassGuidListSize:ClassGuidList列表数组中GUID的数量;

RequiredSize :提供一个指向变量的指针,该变量接收与类名关联的guid数。如果这个数字大于ClassGuidList缓冲区的大小,那么这个数字表示为了存储所有的guid,数组必须有多大。

返回值:

如何调用成功返回TRUE,失败返回FALSE;

SetupDiGetClassDevs

WINSETUPAPI HDEVINFO SetupDiGetClassDevsW( const GUID *ClassGuid,

PCWSTR Enumerator,

HWND hwndParent,

DWORD Flags );

该函数返回一个设备信息集的句柄看,该设备信息集包含本地计算机所请求的设备信息元素。

参数:

ClassGuid:一个指向设备安装类或设备接口类的GUID的指针;该指针是随意的也可以为空。

Enumerator:一个指向空字符结尾的字符串,列举如下:

  • 即插即用设备枚举树的ID,此ID既可以是全局唯一标识符(GUID)也可以是符号名称。比如:“PCI”可以用于指定PCI的PnP值,符号名称则包括像“USB”,“PCMCIA”和“SCSI”这样的Pnp值。

  • 一个PnP设备句柄ID。当指定了一个PnP设备句柄ID时,DIGCF_DEVICEINTERFACE必须在Flag参数上被设置。

hwndParent:用于与在设备信息集中安装设备实例相关联的用户界面的顶级窗口句柄。该句柄是可选的,并且可以为NULL。

Flags :Flags是一个DWORD类型的变量,通过此参数来过滤指定的设备信息集中的设备。此参数可以是以下标志位中的一个或多个的按位或组合。

DIGCF_ALLCLASSES
返回所有已安装设备的列表或所有设备接口类。

DIGCF_DEVICEINTERFACE
返回支持指定设备接口类的设备。如果Enumerators参数制定了设备的实例ID,那么必须在Flags参数中设置此标志位。

DIGCF_DEFAULT
对于指定的设备接口类,只返回与系统默认设备接口相关联的设备(如果已设置的话)。

DIGCF_PRESENT
只返回当前系统中存在的(已连接)设备。

DIGCF_PROFILE
只返回当前硬件列表中的一部分设备。

返回值

如果调用成功,SetupDiGetClassDevs将返回一个设备信息集的句柄,该句柄包含了与所提供参数所匹配的所有设备。如果调用失败,函数返回INVALID_HANDLE_VALUE。要进一步获取错误信息,请调用GetLastError。

SetupDiEnumDeviceInfo 函数

WINSETUPAPI BOOL SetupDiEnumDeviceInfo( HDEVINFO DeviceInfoSet,

DWORD MemberIndex,

PSP_DEVINFO_DATA DeviceInfoData );

说明:

功能:返回一个SP_DEVINFO_DATA结构体,这个结构体是在一个设备信息集中指定的一个设备信息元素

反复的调用该函数会返回不同设备的设备信息元素。

枚举设备信息元素,最初调用该函数时要将MemberIndex参数设置为0,然后每次调用递增MemberIndex参数的值,直到没有更多设备的设备信息元素返回(即

SetupDiEnumDeviceInfo函数调用失败,使用GetLastError函数会返回ERROR_NO_MORE_ITEMS);

参数:

DeviceInfoSet:设备信息集的句柄,用于返回表示设备信息元素的PSP_DEVINFO_DATA数据结构。

MemberIndex:要检索的从零开始的设备信息元素。

DeviceInfoData :指向PSP_DEVINFO_DATA数据结构的指针,用于接收关于枚举设备信息元素的信息。调用者必须设置DeviceInfoData。

cbSize设置成sizeof(PSP_DEVINFO_DATA)。

返回值:

如果成功返回TRUE,失败返回FALSE;

SetupDiGetDeviceRegistryProperty 函数

WINSETUPAPI BOOL SetupDiGetDeviceRegistryPropertyA( HDEVINFO DeviceInfoSet,

PSP_DEVINFO_DATA DeviceInfoData,

DWORD Property,

PDWORD PropertyRegDataType,

PBYTE PropertyBuffer,

DWORD PropertyBufferSize,

PDWORD RequiredSize );

该函数用于检索一个指定的即插即用设备的属性;

参数:

DeviceInfoSet:指向一个设备信息集的指针,表示要检索即插即用属性的设备。

DeviceInfoData:一个PSP_DEVINFO_DATA 结构体,指定DeviceInfoSet中的设备信息元素。

Property:以下要被检索的指定属性:     

SPDRP_ADDRESS

The function retrieves the device's address.

SPDRP_BUSNUMBER

The function retrieves the device's bus number.

SPDRP_BUSTYPEGUID

The function retrieves the GUID for the device's bus type.

SPDRP_CAPABILITIES

The function retrieves a bitwise OR of the following CM_DEVCAP_Xxxflags in a DWORD. The device capabilities that are represented by these flags correspond to the device capabilities that are represented by the members of theDEVICE_CAPABILITIESstructure. The CM_DEVCAP_Xxx constants are defined inCfgmgr32.h.

CM_DEVCAP_Xxx flagCorresponding DEVICE_CAPABILITIES structure member
CM_DEVCAP_LOCKSUPPORTEDLockSupported
CM_DEVCAP_EJECTSUPPORTEDEjectSupported
CM_DEVCAP_REMOVABLERemovable
CM_DEVCAP_DOCKDEVICEDockDevice
CM_DEVCAP_UNIQUEIDUniqueID
CM_DEVCAP_SILENTINSTALLSilentInstall
CM_DEVCAP_RAWDEVICEOKRawDeviceOK
CM_DEVCAP_SURPRISEREMOVALOKSurpriseRemovalOK
CM_DEVCAP_HARDWAREDISABLEDHardwareDisabled
CM_DEVCAP_NONDYNAMICNonDynamic

SPDRP_CHARACTERISTICS

The function retrieves a bitwise OR of a device's characteristics flags in a DWORD. For a description of these flags, which are defined inWdm.handNtddk.h, see theDeviceCharacteristicsparameter of theIoCreateDevicefunction.

SPDRP_CLASS

The function retrieves a REG_SZ string that contains thedevice setup classof a device.

SPDRP_CLASSGUID

The function retrieves a REG_SZ string that contains the GUID that represents the device setup class of a device.

SPDRP_COMPATIBLEIDS

The function retrieves a REG_MULTI_SZ string that contains the list of compatible IDs for a device. For information about compatible IDs, seeDevice Identification Strings.

SPDRP_CONFIGFLAGS

The function retrieves a bitwise OR of a device's configuration flags in a DWORD value. The configuration flags are represented by the CONFIGFLAG_Xxxbitmasks that are defined inRegstr.h.

SPDRP_DEVICE_POWER_DATA

(Windows XP and later) The function retrieves aCM_POWER_DATAstructure that contains the device's power management information.

SPDRP_DEVICEDESC

The function retrieves a REG_SZ string that contains the description of a device.

SPDRP_DEVTYPE

The function retrieves a DWORD value that represents the device's type. For more information, seeSpecifying Device Types.

SPDRP_DRIVER

The function retrieves a string that identifies the device'ssoftware key(sometimes called thedriver key). For more information about driver keys, seeRegistry Trees and Keys for Devices and Drivers.

SPDRP_ENUMERATOR_NAME

The function retrieves a REG_SZ string that contains the name of the device'senumerator.

SPDRP_EXCLUSIVE

The function retrieves a DWORD value that indicates whether a user can obtain exclusive use of the device. The returned value is one if exclusive use is allowed, or zero otherwise. For more information, seeIoCreateDevice.

SPDRP_FRIENDLYNAME

The function retrieves a REG_SZ string that contains the friendly name of a device.

SPDRP_HARDWAREID

The function retrieves a REG_MULTI_SZ string that contains the list of hardware IDs for a device. For information about hardware IDs, seeDevice Identification Strings.

SPDRP_INSTALL_STATE

(Windows XP and later) The function retrieves a DWORD value that indicates the installation state of a device. The installation state is represented by one of the CM_INSTALL_STATE_Xxxvalues that are defined inCfgmgr32.h. The CM_INSTALL_STATE_Xxxvalues correspond to theDEVICE_INSTALL_STATEenumeration values.

SPDRP_LEGACYBUSTYPE

The function retrieves the device's legacy bus type as an INTERFACE_TYPE value (defined inWdm.handNtddk.h).

SPDRP_LOCATION_INFORMATION

The function retrieves a REG_SZ string that contains the hardware location of a device.

SPDRP_LOCATION_PATHS

(Windows Server 2003 and later) The function retrieves a REG_MULTI_SZ string that represents the location of the device in the device tree.

SPDRP_LOWERFILTERS

The function retrieves a REG_MULTI_SZ string that contains the names of a device's lower-filter drivers.

SPDRP_MFG

The function retrieves a REG_SZ string that contains the name of the device manufacturer.

SPDRP_PHYSICAL_DEVICE_OBJECT_NAME

The function retrieves a REG_SZ string that contains the name that is associated with the device's PDO. For more information, seeIoCreateDevice.

SPDRP_REMOVAL_POLICY

(Windows XP and later) The function retrieves the device's current removal policy as a DWORD that contains one of the CM_REMOVAL_POLICY_Xxxvalues that are defined inCfgmgr32.h.

SPDRP_REMOVAL_POLICY_HW_DEFAULT

(Windows XP and later) The function retrieves the device's hardware-specified default removal policy as a DWORD that contains one of the CM_REMOVAL_POLICY_Xxxvalues that are defined inCfgmgr32.h.

SPDRP_REMOVAL_POLICY_OVERRIDE

(Windows XP and later) The function retrieves the device's override removal policy (if it exists) from the registry, as a DWORD that contains one of the CM_REMOVAL_POLICY_Xxxvalues that are defined inCfgmgr32.h.

SPDRP_SECURITY

The function retrieves aSECURITY_DESCRIPTORstructure for a device.

SPDRP_SECURITY_SDS

The function retrieves a REG_SZ string that contains the device's security descriptor. For information about security descriptor strings, seeSecurity Descriptor Definition Language (Windows). For information about the format of security descriptor strings, see Security Descriptor Definition Language (Windows).

SPDRP_SERVICE

The function retrieves a REG_SZ string that contains the service name for a device.

SPDRP_UI_NUMBER

The function retrieves a DWORD value set to the value of theUINumbermember of the device'sDEVICE_CAPABILITIESstructure.

SPDRP_UI_NUMBER_DESC_FORMAT

The function retrieves a format string (REG_SZ) used to display theUINumbervalue.

SPDRP_UPPERFILTERS

The function retrieves a REG_MULTI_SZ string that contains the names of a device's upper filter drivers.

PropertyRegDataType:指向一个变量的指针,该变量接收正在检索的属性的数据类型。这是标准注册表数据类型之一。此参数是可选的,可以为空。

PropertyBuffer:一个指向缓冲区的指针,该缓冲区接收要检索的属性。如果将该参数设置为NULL,并将PropertyBufferSize设置为0,则函数将在RequiredSize中返回 缓冲区所需的大小。

PropertyBufferSize:属性缓冲区大小;

RequiredSize:指向类型为DWORD的变量的指针,该变量接收PropertyBuffer缓冲区所需大小(以字节为单位),该缓冲区用于保存所请求属性的数据。此参数是可选 的,可以为空

返回值:

如果调用成功返回TRUE,失败返回FALSE;

SetupDiOpenDevRegKey

WINSETUPAPI HKEY SetupDiOpenDevRegKey( HDEVINFO DeviceInfoSet,

PSP_DEVINFO_DATA DeviceInfoData,

DWORD Scope,

DWORD HwProfile,

DWORD KeyType,

REGSAM samDesired );

SetupDiOpenDevRegKey函数为特定设备的配置信息打开注册表项。

参数:

DeviceInfoSet:设备信息集的句柄,该句柄包含一个设备信息元素,该元素表示要为其打开注册表项的设备。

DeviceInfoData:一个指向SP DEVINFO数据结构的指针,该结构指定DeviceInfoSet中的设备信息元素。

Scope:要打开的注册表项的范围。范围决定信息存储在何处。范围可以是全局的,也可以是特定于硬件配置文件的。范围由下列值之一指定:

DICS_FLAG_GLOBAL

打开存储全局配置信息的键值项。此信息并不特定于特定的硬件配置文件。这将打开一个根在HKEY_LOCAL_MACHINE。打开的确切键取决于KeyType的值。

DICS_FLAG_CONFIGSPECIFIC

打开存储特定于硬件概要文件的配置信息的键值项。此键根植于硬件配置文件特定的分支之一,而不是HKEY_LOCAL_MACHINE。打开的确切键取决于KeyType的值。

HwProfile:硬件配置文件值,设置如下:

  • IfScopeis set to DICS_FLAG_CONFIGSPECIFIC,HwProfilespecifies the hardware profile of the key that is to be opened.
  • IfHwProfileis 0, the key for the current hardware profile is opened.
  • IfScopeis DICS_FLAG_GLOBAL,HwProfileis ignored.

(如果HwProfile为0,打开当前硬件配置文件的键。)

KeyType:要打开的注册表存储键的类型,可以是以下值之一:

DIREG_DEV

Open ahardware keyfor the device.

DIREG_DRV

Open asoftware keyfor the device.

For more information about a device's hardware and software keys, seeRegistry Trees and Keys for Devices and Drivers.

samDesired:请求的键值项所需的注册表安全访问。

返回值:

如果函数成功,它将返回打开的注册表项的句柄,其中可以存储/检索关于此设备实例的私有配置数据。

如果失败返回INVALID_HANDLE_VALUE。

RegQueryValueEx(E)函数

函数RegQueryValueEx找回一个打开的注册表键值相关联的给定的变量数据或者变量。
LONG RegQueryValueEx(
HKEY hKey, // handle to key 主键句柄
LPCTSTR lpValueName, // value name 子键名称
LPDWORD lpReserved, // reserved 保留
LPDWORD lpType, // type buffer
LPBYTE lpData, // data buffer 存储返回值的缓冲区
LPDWORD lpcbData // size of data buffer存储返回值的缓冲区的大小
);
---------------------
作者:ju_feng
来源:CSDN
原文:https://blog.csdn.net/ju_feng/article/details/6459
版权声明:本文为博主原创文章,转载请附上博文链接!

免责声明:文章转载自《SetupDi系列函数》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇双向广度优先搜索安卓智能聊天机器人开发(二)下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

java8中List根据某一字段去重

实体类: package test; public class User { private String userid; private String username; private String age; private String address; public User(String use...

springboot中json转换LocalDateTime失败的bug解决过程

环境:jdk1.8、maven、springboot 问题:前端通过json传了一个日期:date:2019-03-01(我限制不了前端开发给到后端的日期为固定格式,有些人就是这么不配合),  而springboot中默认使用jackson做json序列化和反序列化,后台接收数据时将日期字符串转成LocalDateTime时,会报错: 1 Caused b...

WPF 获取程序路径的一些方法,根据程序路径获取程序集信息

一、WPF 获取程序路径的一些方法方式一 应用程序域 //获取基目录即当前工作目录 string str_1 = System.AppDomain.CurrentDomain.BaseDirectory; 示例结果:F:\WPF实例\bin\Debug\示例说明:取得Debug目录并且带斜杠 //获取应用程序基目录的名称 string str_2...

NeatUpload 的使用

1 <httpModules> 2 <add name="UploadHttpModule" type="Brettle.Web.NeatUpload.UploadHttpModule, Brettle.Web.NeatUpload" /> 3 </httpModules> 来自 <http://www....

【转帖】C# DllImport 系统调用使用详解 托管代码的介绍 EntryPoint的使用

1 DLLImport的使用 using System; using System.Runtime.InteropServices; //命名空间 class Example { //用DllImport 导入Win32的MessageBox函数 [DllImport("user32.dll", CharSet = CharSet.Unicode)] p...

Haskell语言学习笔记(23)MonadReader, Reader, ReaderT

MonadReader 类型类 class Monad m => MonadReader r m | m -> r where ask :: m r ask = reader id local :: (r -> r) -> m a -> m a reader :: (r -> a)...