setupDigetDeviceInterfacedEtail 모든 USB HID 객체의 경로에 대해서만 ""만 반환합니다.

StackOverflow https://stackoverflow.com/questions/1744513

  •  20-09-2019
  •  | 
  •  

문제

나는 얼마나 많은 USB HID 장치를 가지고 있는지 알 수 있지만 (7), 모든 장치에 대한 세부 정보를 얻을 때마다 반환 된 경로는 항상 ""이므로 장치에 전혀 액세스 할 수 없도록합니다. . 이 코드의 절차에서 매우 유사한 코드를 사용하고 있습니다.

HANDLE connectDeviceNumber(DWORD deviceIndex)
{
    GUID hidGUID;
    HDEVINFO hardwareDeviceInfoSet;
    SP_DEVICE_INTERFACE_DATA deviceInterfaceData;
    PSP_INTERFACE_DEVICE_DETAIL_DATA deviceDetail;
    ULONG requiredSize;
    HANDLE deviceHandle = INVALID_HANDLE_VALUE;
    DWORD result;

    //Get the HID GUID value - used as mask to get list of devices
    HidD_GetHidGuid (&hidGUID);

    //Get a list of devices matching the criteria (hid interface, present)
    hardwareDeviceInfoSet = SetupDiGetClassDevs (&hidGUID,
                                                 NULL, // Define no enumerator (global)
                                                 NULL, // Define no
                                                 (DIGCF_PRESENT | // Only Devices present
                                                 DIGCF_DEVICEINTERFACE)); // Function class devices.

    deviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);

    //Go through the list and get the interface data
    result = SetupDiEnumDeviceInterfaces (hardwareDeviceInfoSet,
                                          NULL, //infoData,
                                          &hidGUID, //interfaceClassGuid,
                                          deviceIndex, 
                                          &deviceInterfaceData);

    /* Failed to get a device - possibly the index is larger than the number of devices */
    if (result == FALSE)
    {
        SetupDiDestroyDeviceInfoList (hardwareDeviceInfoSet);
        Log("hidin: -- failed to get specified device number");
        return INVALID_HANDLE_VALUE;
    }

    //Get the details with null values to get the required size of the buffer
    SetupDiGetDeviceInterfaceDetail (hardwareDeviceInfoSet,
                                     &deviceInterfaceData,
                                     NULL, //interfaceDetail,
                                     0, //interfaceDetailSize,
                                     &requiredSize,
                                     0); //infoData))

    //Allocate the buffer
    deviceDetail = (PSP_INTERFACE_DEVICE_DETAIL_DATA)malloc(requiredSize);
    deviceDetail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);

    //Fill the buffer with the device details
    if (!SetupDiGetDeviceInterfaceDetail (hardwareDeviceInfoSet,
                                          &deviceInterfaceData,
                                          deviceDetail,
                                          requiredSize,
                                          &requiredSize,
                                          NULL)) 
    {
        SetupDiDestroyDeviceInfoList (hardwareDeviceInfoSet);
        free (deviceDetail);
        Log("hidin: -- failed to get device info");
        return INVALID_HANDLE_VALUE;
    }

    Log("Opening device with path: %s", deviceDetail->DevicePath);
도움이 되었습니까?

해결책

확실히 당신은 정의 된 유니 코드로 컴파일하고 있습니까? 그런 다음 log () 서식 문자열이 잘못되었습니다. 고치다:

   Log("Opening device with path: %ls", deviceDetail->DevicePath);

다른 팁

문서 SetupDiEnumDeviceInterfaces 먼저 DeviceIndex == 0으로 호출해야한다고 말합니다. 당신은 가치를 건너 뛰지 않아야합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top