diff options
author | Pete Batard <pete@akeo.ie> | 2013-12-30 21:32:28 +0000 |
---|---|---|
committer | Pete Batard <pete@akeo.ie> | 2013-12-30 21:32:28 +0000 |
commit | 8b46e1c088167eb86b1712765896e2f17d70d148 (patch) | |
tree | d841d189e0349a8bd868f82f8b53f73b57bd3182 | |
parent | 28424b945cc5abed182f83ab3fc70676986d7cf3 (diff) | |
download | libusb-8b46e1c088167eb86b1712765896e2f17d70d148.tar.gz |
Windows: Add SetupAPI error handling
* http://msdn.microsoft.com/en-us/library/windows/hardware/ff545011.aspx
states that SetupAPI errors must be be converted before passing it to FormatMessage().
* Use our own implementation of HRESULT_FROM_SETUPAPI to avoid defining a new function call.
* Issue and original fix suggested by Matthias Bolte
* Closes #166
-rw-r--r-- | libusb/os/windows_usb.c | 14 | ||||
-rw-r--r-- | libusb/version_nano.h | 2 |
2 files changed, 15 insertions, 1 deletions
diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c index aa4c0f4..5abadc1 100644 --- a/libusb/os/windows_usb.c +++ b/libusb/os/windows_usb.c @@ -158,6 +158,20 @@ static char err_string[ERR_BUFFER_SIZE]; safe_sprintf(err_string, ERR_BUFFER_SIZE, "[%u] ", error_code); + // Translate codes returned by SetupAPI. The ones we are dealing with are either + // in 0x0000xxxx or 0xE000xxxx and can be distinguished from standard error codes. + // See http://msdn.microsoft.com/en-us/library/windows/hardware/ff545011.aspx + switch (error_code & 0xE0000000) { + case 0: + error_code = HRESULT_FROM_WIN32(error_code); // Still leaves ERROR_SUCCESS unmodified + break; + case 0xE0000000: + error_code = 0x80000000 | (FACILITY_SETUPAPI << 16) | (error_code & 0x0000FFFF); + break; + default: + break; + } + size = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), &err_string[safe_strlen(err_string)], ERR_BUFFER_SIZE - (DWORD)safe_strlen(err_string), NULL); diff --git a/libusb/version_nano.h b/libusb/version_nano.h index c7f218d..9b72a0c 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 10856 +#define LIBUSB_NANO 10857 |