2012-05-13 51 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を定義されていない文書で説明したように、後にVistaを必要としますか。したがって、WINVER_WIN32_WINNTを適切に定義する必要があります。

#define WINVER 0x0600 
#define _WIN32_WINNT 0x0600 

あなたのプロジェクトは以前のバージョンのWindowsを対象としていると思います。

また、プロジェクトオプションまたはコマンドラインで定義することもできます。詳細はhereです。

答えが得られない場合は、Vistaより前のSDKの古いバージョンを使用している可能性がありますか?

関連する問題