ToB企服应用市场:ToB评测及商务社交产业平台

标题: Windows下获取设备管理器列表信息-setupAPI [打印本页]

作者: 美食家大橙子    时间: 2024-2-16 05:09
标题: Windows下获取设备管理器列表信息-setupAPI
背景及问题:

在与硬件打交道时,经常需要知道当前设备连接的硬件信息,以便连接正确的硬件,比如串口通讯查询连接的硬件及端口,一般手工的方式就是去设备管理器查看相应的信息,应用程序如何读取这一部分信息呢,Windows下的SetupAPI系列就可以解决这个问题示例程序

[code]#include#include#include#include#pragma comment(lib, "setupapi.lib")int main(){        //set chinese character        std::locale::global(std::locale(""));        //The SetupDiGetClassDevs function returns a handle to a device     //information set that contains requested device information     //elements for a local computer.        HDEVINFO hdevinfo = SetupDiGetClassDevs(NULL,                NULL, NULL, DIGCF_PRESENT | DIGCF_ALLCLASSES);        if (hdevinfo != INVALID_HANDLE_VALUE)        {                DWORD MemberIndex = 0;                SP_DEVINFO_DATA sp_devinfo_data;                ZeroMemory(&sp_devinfo_data, sizeof(sp_devinfo_data));                sp_devinfo_data.cbSize = sizeof(sp_devinfo_data);        //The SetupDiEnumDeviceInfo function returns a SP_DEVINFO_DATA         //structure that specifies a device information element in a         //device information set.                while (SetupDiEnumDeviceInfo(hdevinfo, MemberIndex, &sp_devinfo_data))                {                        TCHAR PropertyBuffer[100];                //The SetupDiGetDeviceRegistryProperty function retrieves                        //a specified Plug and Play device property.                            if (SetupDiGetDeviceRegistryProperty(hdevinfo,                                &sp_devinfo_data,                                SPDRP_DEVICEDESC,                                NULL,                                (PBYTE)&ropertyBuffer,                                sizeof(PropertyBuffer),                                NULL))                        {                                std::wcout




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4