0
我想使用SetupDiGetDeviceProperty,但顯然它無法在setupapi.h中找到這樣的函數。我已經看過文檔幷包含了所有的頭文件和庫文件,但它只是不讓我使用該功能......發生了什麼?我做錯了什麼?下面是代碼:爲什麼SetupDiGetDeviceProperty函數無法正常工作?
//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++;
}
}
SetupDiGetDeviceProperty函數在ListAllDevices函數的底部被調用。
由於
編輯:抱歉,忘陳述錯誤:智能感知:標識符 「SetupDiGetDeviceProperty」 未定義
智能感知錯誤不是最適合引用的錯誤。我會引用編譯器發出的錯誤。智能感知可能會導致錯誤。 –