C++ 为什么SetupDiGetDeviceProperty功能不起作用?
我试图使用SetupDiGetDeviceProperty,但显然在setupapi.h中找不到这样的函数。我已经看过了文档,包括了所有的头文件和库文件,但是它不允许我使用这个函数。。。怎么回事?我做错了什么?代码如下:C++ 为什么SetupDiGetDeviceProperty功能不起作用?,c++,device,wdk,C++,Device,Wdk,我试图使用SetupDiGetDeviceProperty,但显然在setupapi.h中找不到这样的函数。我已经看过了文档,包括了所有的头文件和库文件,但是它不允许我使用这个函数。。。怎么回事?我做错了什么?代码如下: //Mainframe.cpp file #include"DeviceManager.h" int main() { int iQuit; DeviceManager deviceManager; deviceManager.ListAllDevi
//Mainframe.cpp file
#include"DeviceManager.h"
int main()
{
int iQuit;
DeviceManager deviceManager;
deviceManager.ListAllDevices();
std::cin >> iQuit;
return 0;
}
//DeviceManager.h file
#include <windows.h>
#include <setupapi.h>
#include <iostream>
#include <cfgmgr32.h>
#include <tchar.h>
#include <devpkey.h>
//#pragma comment (lib, "setupapi.lib")
class DeviceManager
{
public:
DeviceManager();
~DeviceManager();
void ListAllDevices();
};
//DeviceManager.cpp file
#include"DeviceManager.h"
DeviceManager::DeviceManager()
{
}
DeviceManager::~DeviceManager()
{
}
void DeviceManager::ListAllDevices()
{
HDEVINFO deviceInfoSet; //A list of all the devices
SP_DEVINFO_DATA deviceInfoData; //A device from deviceInfoSet
DEVPROPTYPE devicePropertyType;
//CONFIGRET device;
DWORD deviceIndex = 0;
DWORD size;
TCHAR description[1024];
bool foundAllDevices = false;
deviceInfoSet = SetupDiGetClassDevs(NULL, TEXT("USB"), NULL, DIGCF_PRESENT|DIGCF_ALLCLASSES); //Gets all Devices
deviceInfoData.cbSize = sizeof(deviceInfoData);
while(SetupDiEnumDeviceInfo(deviceInfoSet, deviceIndex, &deviceInfoData))
{
deviceInfoData.cbSize = sizeof(deviceInfoData);
ULONG tcharSize;
CM_Get_Device_ID_Size(&tcharSize, deviceInfoData.DevInst, 0);
TCHAR* deviceIDbuffer = new TCHAR[tcharSize]; //the device ID will be stored in this array, so the tcharSize needs to be big enough to hold all the info.
//Or we can use MAX_DEVICE_ID_LEN, which is 200
CM_Get_Device_ID(deviceInfoData.DevInst, deviceIDbuffer, MAX_PATH, 0); //gets the devices ID - a long string that looks like a file path.
SetupDiGetDeviceProperty(deviceInfoSet, deviceInfoData, DEVPKEY_NAME, devicePropertyType, description, sizeof(description), size, 0);
std::cout << deviceIDbuffer << std::endl;
deviceIndex++;
}
}
//Mainframe.cpp文件
#包括“DeviceManager.h”
int main()
{
国际货币基金组织;
设备管理器设备管理器;
deviceManager.ListAllDevices();
标准:cin>>iQuit;
返回0;
}
//DeviceManager.h文件
#包括
#包括
#包括
#包括
#包括
#包括
//#pragma注释(lib,“setupapi.lib”)
类设备管理器
{
公众:
DeviceManager();
~DeviceManager();
void ListAllDevices();
};
//DeviceManager.cpp文件
#包括“DeviceManager.h”
DeviceManager::DeviceManager()
{
}
DeviceManager::~DeviceManager()
{
}
void DeviceManager::ListAllDevices()
{
HDEVINFO deviceinfo;//所有设备的列表
SP_DEVINFO_DATA deviceinfo;//设备信息集中的设备
DEVPROPTYPE设备属性类型;
//配置设备;
DWORD设备索引=0;
德沃德尺寸;
TCHAR描述[1024];
bool foundAllDevices=false;
DeviceInfo=SetupDiGetClassDevs(NULL,文本(“USB”),NULL,DIGCF_PRESENT | DIGCF_ALLCLASSES);//获取所有设备
DeviceInfo.cbSize=sizeof(DeviceInfo数据);
while(SetupDiEnumDeviceInfo(DeviceInfo集、deviceIndex和DeviceInfo数据))
{
DeviceInfo.cbSize=sizeof(DeviceInfo数据);
ULONG Tcharize;
CM_Get_Device_ID_Size(&tcharSize,deviceinfo.DevInst,0);
TCHAR*deviceIDbuffer=new TCHAR[tcharSize];//设备ID将存储在此数组中,因此tcharSize需要足够大以容纳所有信息。
//或者我们可以使用MAX_DEVICE_ID_LEN,即200
CM_Get_Device_ID(deviceinfo.DevInst,deviceIDbuffer,MAX_PATH,0);//获取设备ID-一个看起来像文件路径的长字符串。
SetupDiGetDeviceProperty(DeviceInfo集、DeviceInfo数据、devKey_名称、DeviceProperty类型、说明、sizeof(说明)、大小、0);
std::cout需要Vista或更高版本,如文档中所述。因此,必须相应地定义WINVER
和\u WIN32\u WINNT
#define WINVER 0x0600
#define _WIN32_WINNT 0x0600
我猜您的项目的目标是Windows的早期版本
或者,您可以在项目选项中或在命令行中定义它们。更多详细信息
如果这不是答案,那么是否可能您使用的是Vista之前的过期版本的SDK?IntelliSense错误不是最合适的引用。我将引用编译器发出的错误。IntelliSense可能会出错。