From bf40b1cea9eb2e13d13f05118fe11b43be621485 Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Fri, 24 Jan 2020 04:30:22 +0000 Subject: [PATCH] windows: Use correct variant of FormatMessage. When built with MSVC and unicode enabled, using 'message' gave: warning C4133: 'initializing': incompatible types - from 'TCHAR *' to 'char *' FormatMessage expands to either FormatMessageA or FormatMessageW depending if unicode is enabled, and generates either a char (8-bit) or WCHAR (UTF-16) string accordingly. Since sp_last_error_message() returns char *, we must use the 8-bit variant. The message will be encoded in the current code page. --- serialport.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/serialport.c b/serialport.c index 0a46688..eee453a 100644 --- a/serialport.c +++ b/serialport.c @@ -2478,17 +2478,17 @@ SP_API char *sp_last_error_message(void) TRACE_VOID(); #ifdef _WIN32 - TCHAR *message; + char *message; DWORD error = GetLastError(); - DWORD length = FormatMessage( + DWORD length = FormatMessageA( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR) &message, + (LPSTR) &message, 0, NULL ); if (length >= 2 && message[length - 2] == '\r')