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
1 changed files with 3 additions and 3 deletions

View File

@ -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')