代码功能将windows设备遍历一次,然后将结果直接存放到map容器中,需要清楚其中一个设备的个数,直接通过map可以查询
#include <Windows.h>
#include <setupapi.h>
#include <string>
#include <vector>
#include<map>
#include<stdio.h>
#pragma comment(lib, "setupapi.lib")
using namespace std;
class QueryCard{
public:
map<string,int>Card;
map<string,int>::iterator it;
HDEVINFO hDevInfo;
SP_DEVINFO_DATA DeviceInfoData;
DWORD i;
void QueryCardCount();
};
void QueryCard::QueryCardCount(){
hDevInfo = SetupDiGetClassDevs(NULL, 0, 0, DIGCF_PRESENT | DIGCF_ALLCLASSES);
if (hDevInfo == INVALID_HANDLE_VALUE)
return ;
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
&n

该代码示例展示了如何使用C++在Windows上通过SetupDiGetClassDevs API遍历设备,并将设备描述存入map容器,以便查询特定设备的数量。主要涉及到Windows API和设备枚举。
最低0.47元/天 解锁文章
800

被折叠的 条评论
为什么被折叠?



