kou commented on code in PR #13203:
URL: https://github.com/apache/arrow/pull/13203#discussion_r884452357


##########
cpp/src/arrow/util/io_util.cc:
##########
@@ -203,16 +203,26 @@ std::string ErrnoMessage(int errnum) { return 
std::strerror(errnum); }
 
 #if _WIN32
 std::string WinErrorMessage(int errnum) {
-  char buf[1024];
-  auto nchars = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | 
FORMAT_MESSAGE_IGNORE_INSERTS,
-                               NULL, errnum, 0, buf, sizeof(buf), NULL);
-  if (nchars == 0) {
+#define MAX_N_CHARACTERS 1024
+#define MAX_N_UTF8_BYTES 4096
+  WCHAR utf16_message[MAX_N_CHARACTERS];
+  auto n_utf16_chars =
+      FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | 
FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
+                     errnum, 0, utf16_message, sizeof(utf16_message), NULL);
+  if (n_utf16_chars == 0) {
     // Fallback
     std::stringstream ss;
     ss << "Windows error #" << errnum;
     return ss.str();
   }
-  return std::string(buf, nchars);
+  const UINT code_page = CP_UTF8;
+  const DWORD flags = 0;
+  char utf8_message[MAX_N_UTF8_BYTES];
+  auto n_utf8_bytes = WideCharToMultiByte(code_page, flags, utf16_message, 
n_utf16_chars,

Review Comment:
   I've changed to use `WideStringToUTF8()`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to