diff --git a/Tools/ComponentFirmwareUpdateStandAloneToolSample/FwUpdate.cpp b/Tools/ComponentFirmwareUpdateStandAloneToolSample/FwUpdate.cpp index abb533a..0a156b3 100644 --- a/Tools/ComponentFirmwareUpdateStandAloneToolSample/FwUpdate.cpp +++ b/Tools/ComponentFirmwareUpdateStandAloneToolSample/FwUpdate.cpp @@ -182,18 +182,32 @@ Return Value: NTSTATUS status; HRESULT hr = S_OK; device.hDevice = INVALID_HANDLE_VALUE; - - // Check that the VID/PID matches. - wchar_t vidPidFilterString[256] = { 0 }; - memset(&VerReport, 0, sizeof(VerReport)); + HIDD_ATTRIBUTES attr = { 0 }; + // Open a handle to the device. + device.hDevice = CreateFileW( + DevicePath, + GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); + if (device.hDevice == INVALID_HANDLE_VALUE) + { + wprintf(L"INVALID_HANDLE_VALUE %s", DevicePath); + hr = HRESULT_FROM_WIN32(GetLastError()); + goto Exit; + } + if (!HidD_GetAttributes(device.hDevice, &attr)) { + hr = HRESULT_FROM_WIN32(GetLastError()); + goto Exit; + } // Filter on both if both set - if (ProtocolSettings.Vid && ProtocolSettings.Pid) + if (ProtocolSettings.Vid && ProtocolSettings.Pid) { - swprintf(vidPidFilterString, 256, L"VID_%04X&PID_%04X", - ProtocolSettings.Vid, ProtocolSettings.Pid); - if (!wcsstr(DevicePath, vidPidFilterString)) + if ((attr.VendorID != ProtocolSettings.Vid) || (attr.ProductID != ProtocolSettings.Pid)) { // The device found doesn't match the vid and pid //wprintf(L"The device found does not match the VID/PID\n"); @@ -205,8 +219,7 @@ Return Value: // Filter on vid only (vid is mandatory) else { - swprintf(vidPidFilterString, 256, L"VID_%04X", ProtocolSettings.Vid); - if (!wcsstr(DevicePath, vidPidFilterString)) + if (attr.VendorID != ProtocolSettings.Vid) { // The device found doesn't match the vid hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND); @@ -214,22 +227,6 @@ Return Value: } } - // Open a handle to the device. - device.hDevice = CreateFileW( - DevicePath, - GENERIC_READ, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL); - if (device.hDevice == INVALID_HANDLE_VALUE) - { - wprintf(L"INVALID_HANDLE_VALUE %s", DevicePath); - hr = HRESULT_FROM_WIN32(GetLastError()); - goto Exit; - } - // Try to get the device's preparsed HID data. if (!HidD_GetPreparsedData(device.hDevice, &device.PreparsedData)) {