SetupDiGetDeviceInterfaceDetail devuelve sólo “\” para la trayectoria de todos los objetos USB HID

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

  •  20-09-2019
  •  | 
  •  

Pregunta

que puedo decir cuántos dispositivos USB HID tengo (7), pero cada vez que trato de obtener detalles sobre cualquier dispositivo, el camino volvió para siempre es "\", por lo que es por lo que no puedo tener acceso a la dispositivo en absoluto. Estoy usando el código que es muy similar en el procedimiento de este código:

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);
¿Fue útil?

Solución

Sin duda, se compila con UNICODE definido? A continuación, log () cadena de formato es incorrecto. Solución:

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

Otros consejos

La documentación de los estados SetupDiEnumDeviceInterfaces que usted debe llamar primero con deviceIndex == 0; no se supone saltarse valores.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top