基于Windows的设备管理开发(主要阐述SetupDi系列函数及其相关内容)

基于Windows的设备管理开发

 

1.1、HDEVINFO SetupDiGetClassDevs(
  const GUID* ClassGuid,
  PCTSTR Enumerator,
  HWND hwndParent,
  DWORD Flags
);
返回指定类别(第一个参数指定)的已安装设备的句柄,即获取设备信息集
If the function succeeds, the return value is a handle to a device information set that contains all the installed devices that match the specified parameters.
If the function fails, the return value is INVALID_HANDLE_VALUE. To get extended error information, call GetLastError.

第一个参数简述 [in]

指定DIGCF_DEVICEINTERFACE :使用设备接口类的GUID,否则使用安装类的GUID(If the DIGCF_DEVICEINTERFACE flag is set, ClassGuid represents an interface class; otherwise, ClassGuid represents a setup class.)

如果指定 DIGCF_ALLCLASSES ,该参数将被忽略,返回的句柄包括所有已安装设备类别(If the DIGCF_ALLCLASSES flag is set, this parameter is ignored and the resulting list contains devices of all the installed classes.)

第二个参数简述 [in]

枚举器子键的内容

常见的子键有:ACPI、ACPI_HAL、DISPLAY、HID、HTREE、IDE、ISAPNP、LPTENUM、PCI、PCIIDE、Root、STORAGE、SW、USB、USBSTOR

(If the DIGCF_DEVICEINTERFACE flag is set, this parameter is an optional pointer to a null-terminated string that specifies the PnP name of a specific device. This function examines the specific device only to determine whether it exposes any interfaces of the requested interface class.

If the DIGCF_DEVICEINTERFACE flag is not set, this parameter is an optional pointer to a null-terminated string that specifies the name of the PnP enumerator for the devices of interest. (The complete list of enumerator names that are installed on a computer are listed under the HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Enum
subkey. A few of the system-supplied enumerator names are listed in Regstr.h.) This function examines only device instances of this enumerator.
If this parameter is NULL, this function retrieves device information for all device instances on the system.)

第三个参数简述 [in]

关联到当前集合成员的任意用户接口的最顶层窗口句柄(Handle to the top-level window to be used for any user interface that relates to the members of this set. )

第四个参数简述 [in]

返回句柄的控制选项(Control options that are used to build the device information set. This parameter can be one or more of the following values. )

DIGCF_ALLCLASSES 返回所有已安装类别的设备列表(Return a list of installed devices for all classes. If this flag is set, the ClassGuid parameter is ignored. )
DIGCF_DEVICEINTERFACE Return devices that expose interfaces of the interface class that are specified by ClassGuid. If this flag is not set, ClassGuid specifies a setup class.
DIGCF_PRESENT 仅仅返回当前存在的设备(Return only devices that are present currently. )
DIGCF_PROFILE 仅仅返回当前硬件配置文件中的设备(Return only devices that are a part of the current hardware profile. )
 

Return Values
If the function succeeds, the return value is a handle to a device information set that contains all the installed devices that match the specified parameters.
If the function fails, the return value is INVALID_HANDLE_VALUE. To get extended error information, call GetLastError.

Remarks
To destroy the device information set when you finish, call the SetupDiDestroyDeviceInfoList function.
If DIGCF_DEVICEINTERFACE is set, ClassGuid (if used) must point to a device interface class GUID, and Enumerator (if used) must point to a PnP device name. The device information set that is returned contains devices that expose interfaces of the requested interface class. Enumerate the interfaces of the devices by using the SetupDiEnumDeviceInterfaces function.
If DIGCF_DEVICEINTERFACE is not set, ClassGuid (if used) must point to a setup class GUID, and Enumerator (if used) must specify the name of the PnP enumerator that enumerates the devices of interest.
To retrieve the devices for a class on a remote computer, call the SetupDiGetClassDevsEx function.

备注:#include <setupapi.h> #pragma comment(lib, "setupapi.lib")

 

1.2、BOOL SetupDiEnumDeviceInfo(
  HDEVINFO DeviceInfoSet,
  DWORD MemberIndex,
  PSP_DEVINFO_DATA DeviceInfoData
);

遍历指定设备信息集合中的某个元素的结构信息,即从设备信息集中遍历设备信息的具体属性

The SetupDiEnumDeviceInfo function retrieves a context structure for a device information element of the specified device information set. Each call returns information about one device. The function can be called repeatedly to get information about several devices.

第一个参数简述 [in]

要枚举的设备信息集合的句柄(Handle to the device information set containing the devices for which to return element information.)

第二个参数简述 [in]

设备索引号(Zero-based index to the list of interfaces in the device information set. You should first call this function with the MemberIndex parameter set to zero to obtain the first interface. Then, repeatedly increment MemberIndex and retrieve an interface until this function fails and GetLastError returns ERROR_NO_MORE_ITEMS. )

第三个参数简述 [out]

接收枚举到的设备信息(Pointer to an SP_DEVINFO_DATA structure that receives information about this element. You must set the cbSize member to sizeof( SP_DEVINFO_DATA) before calling this function. )

Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.

1.3、BOOL SetupDiGetDeviceRegistryProperty(
  HDEVINFO DeviceInfoSet,
  PSP_DEVINFO_DATA DeviceInfoData,
  DWORD Property,
  PDWORD PropertyRegDataType,
  PBYTE PropertyBuffer,
  DWORD PropertyBufferSize,
  PDWORD RequiredSize
);

返回指定设备的注册属性,即从注册表中读取PnP设备属性

The SetupDiGetDeviceRegistryProperty function retrieves the specified device property.

第一个参数简述 [in]

要获取属性的设备集合的句柄(Handle to the device information set that contains the interface and its underlying device. This handle is typically returned by the SetupDiGetClassDevs or SetupDiGetClassDevsEx function. )

第二个参数简述 [in]

设备的SP_DEVINFO_DATA属性(Pointer to an SP_DEVINFO_DATA structure that defines the device instance. )

第三个参数简述 [in]

请求的属性名称(Device property to be retrieved. See the SPDRP_* constants defined in Setupapi.h.)

第四个参数简述 [out]

接收注册的数据类型(Pointer to a variable that receives the registry data type. This parameter can be NULL. )

第五个参数简述 [out]

指向一个接收设备属性的缓冲区(Pointer to a buffer that receives the requested device property.If this buffer is too small, the function fails and GetLastError returns ERROR_INSUFFICIENT_BUFFER. )

第六个参数简述 [in]

上述缓冲区的字节大小(Size of the buffer, in bytes.)

第七个参数简述 [out]

指向一个有效接收的缓冲区字节长度(Pointer to a variable that receives the required buffer size, in bytes. This parameter can be NULL. )

1.4、WINSETUPAPI
BOOL
WINAPI
SetupDiSetClassInstallParams(
    IN HDEVINFO                DeviceInfoSet,
    IN PSP_DEVINFO_DATA        DeviceInfoData,        OPTIONAL
    IN PSP_CLASSINSTALL_HEADER ClassInstallParams,    OPTIONAL
    IN DWORD                   ClassInstallParamsSize
    );

第一个参数简述

指定要获取的设备集合的句柄

第二个参数简述

具体的设备结构信息,上述SP_DEVINFO_DATA类型

第三个参数简述

设备安装类的头结构(SP_CLASSINSTALL_HEADER )信息

第四个参数简述

第3个参数的字节大小

 

1.5、WINSETUPAPI
BOOL
WINAPI
SetupDiCallClassInstaller(
    IN DI_FUNCTION      InstallFunction,
    IN HDEVINFO         DeviceInfoSet,
    IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
    );

 

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值