代码功能将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