1
0
mirror of git://sigrok.org/libserialport synced 2023-08-10 21:13:24 +03:00

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.
This commit is contained in:
Martin Ling 2020-01-24 04:30:22 +00:00
parent e47c7dcbff
commit bf40b1cea9

View File

@ -2478,17 +2478,17 @@ SP_API char *sp_last_error_message(void)
TRACE_VOID(); TRACE_VOID();
#ifdef _WIN32 #ifdef _WIN32
TCHAR *message; char *message;
DWORD error = GetLastError(); DWORD error = GetLastError();
DWORD length = FormatMessage( DWORD length = FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, NULL,
error, error,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &message, (LPSTR) &message,
0, NULL ); 0, NULL );
if (length >= 2 && message[length - 2] == '\r') if (length >= 2 && message[length - 2] == '\r')