diff options
author | dmitrykos <dmitrykos@neutroncode.com> | 2019-01-31 23:17:06 +0200 |
---|---|---|
committer | Nathan Hjelm <hjelmn@me.com> | 2019-04-04 22:35:03 -0600 |
commit | 542e6fd03d115b74a9aa3ebea1d21d63e4a86aa1 (patch) | |
tree | 06b8c7a4c62ff46de553264ad552819886af3f49 | |
parent | 5347d115d94eeaa67eddb4eb4c39402d2785f979 (diff) | |
download | libusb-542e6fd03d115b74a9aa3ebea1d21d63e4a86aa1.tar.gz |
windows: Improved log message output to MSVC
Improved log message output to MSVC handling by converting multi-byte
string (assumed to be UTF-8) to WCHAR string if UNICODE is defined, if
UNICODE is not defined then multi-byte string is sent to MSVC (Windows
CE defines UNICODE always, so it will use UNICODE case), added check
for 0 to avoid sending trash to MSVC (and possibly crash the process)
if conversion to WCHAR string fails.
Closes #504
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
-rw-r--r-- | libusb/core.c | 11 | ||||
-rw-r--r-- | libusb/version_nano.h | 2 |
2 files changed, 7 insertions, 6 deletions
diff --git a/libusb/core.c b/libusb/core.c index 8823b19..ddba089 100644 --- a/libusb/core.c +++ b/libusb/core.c @@ -2480,13 +2480,14 @@ int usbi_vsnprintf(char *str, size_t size, const char *format, va_list ap) static void usbi_log_str(enum libusb_log_level level, const char *str) { #if defined(USE_SYSTEM_LOGGING_FACILITY) -#if defined(OS_WINDOWS) +#if defined(OS_WINDOWS) || defined(OS_WINCE) +#if !defined(UNICODE) OutputDebugStringA(str); -#elif defined(OS_WINCE) - /* Windows CE only supports the Unicode version of OutputDebugString. */ +#else WCHAR wbuf[USBI_MAX_LOG_LEN]; - MultiByteToWideChar(CP_UTF8, 0, str, -1, wbuf, sizeof(wbuf)); - OutputDebugStringW(wbuf); + if (MultiByteToWideChar(CP_UTF8, 0, str, -1, wbuf, sizeof(wbuf)) != 0) + OutputDebugStringW(wbuf); +#endif #elif defined(__ANDROID__) int priority = ANDROID_LOG_UNKNOWN; switch (level) { diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 25c45e5..aefd792 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 11358 +#define LIBUSB_NANO 11359 |