2012-05-13 4 views
0

SetupDiGetDeviceProperty를 사용하려하지만 setupapi.h에서 이러한 기능을 찾을 수 없습니다. 나는 문서를보고 모든 헤더와 라이브러리 파일을 포함 시켰지만, 단지 함수를 사용하도록 내버려 두지 않고있다. 어떻게 될 것인가? 내가 잘못하고 있는게 뭐지? Heres는 코드 다음 SetupDiGetDeviceProperty 기능이 ListAllDevices 함수의 맨 아래라고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이"정의되지

+0

IntelliSense 오류는 인용 할 수있는 가장 적합한 오류가 아닙니다. 나는 컴파일러가 내뿜는 에러를 인용 할 것이다. IntelliSense는 잘못 이해할 수 있습니다. –

답변

2

SetupDiGetDeviceProperty가, 나중에 비스타 이상이 필요 죄송합니다, 오류를 언급하는 것을 잊었다. 따라서 WINVER_WIN32_WINNT을 적절히 정의해야합니다.

#define WINVER 0x0600 
#define _WIN32_WINNT 0x0600 

내 생각 엔 프로젝트가 이전 버전의 Windows를 대상으로합니다.

또는 프로젝트 옵션이나 명령 줄에서 정의 할 수 있습니다. 더 자세한 내용 here.

그 대답이 아니라면 Vista 이전 버전의 SDK가 오래된 버전 일 가능성이 있습니까?

관련 문제