From 53e778af703e40e91c2021d4ab12f8d30e14bd60 Mon Sep 17 00:00:00 2001 From: Don Bright Date: Sun, 26 May 2013 22:03:16 -0500 Subject: [PATCH] fix bugs in win version --- src/PlatformUtils-win.cc | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/PlatformUtils-win.cc b/src/PlatformUtils-win.cc index d06df512..a314ebe0 100644 --- a/src/PlatformUtils-win.cc +++ b/src/PlatformUtils-win.cc @@ -1,7 +1,9 @@ #include "PlatformUtils.h" #include "printutils.h" #include +#ifndef _WIN32_IE #define _WIN32_IE 0x0501 // SHGFP_TYPE_CURRENT +#endif #include // convert from windows api w_char strings (usually utf16) to utf8 std::string @@ -11,22 +13,25 @@ std::string winapi_wstr_to_utf8( std::wstring wstr ) UINT CodePage = CP_UTF8; DWORD dwFlags = 0; - LPCSTR lpMultiByteStr = NULL; - int cbMultiByte = 0; - LPWSTR lpWideCharStr = &wstr[0]; + LPCWSTR lpWideCharStr = &wstr[0]; int cchWideChar = (int)wstr.size(); + LPSTR lpMultiByteStr = NULL; + int cbMultiByte = 0; + LPCSTR lpDefaultChar = NULL; + LPBOOL lpUsedDefaultChar = NULL; - int numbytes = MultiByteToWideChar( CodePage, dwFlags, lpMultiByteStr, - cbMultiByte, lpWideCharStr, cchWideChar ); + int numbytes = WideCharToMultiByte( CodePage, dwFlags, lpWideCharStr, + cchWideChar, lpMultiByteStr, cbMultiByte, lpDefaultChar, lpUsedDefaultChar ); - cbMultiByte = numbytes; lpMultiByteStr = &utf8_str[0]; + cbMultiByte = numbytes; - int result = MultiByteToWideChar( CodePage, dwFlags, lpMultiByteStr, - cbMultiByte, lpWideCharStr, cchWideChar ); + int result = WideCharToMultiByte( CodePage, dwFlags, lpWideCharStr, + cchWideChar, lpMultiByteStr, cbMultiByte, lpDefaultChar, lpUsedDefaultChar ); if (result != numbytes) { PRINT("ERROR: error converting w_char str to utf8 string"); + PRINTB("ERROR: error code %i",GetLastError()); } return utf8_str;