diff --git a/include/libtorrent/utf8.hpp b/include/libtorrent/utf8.hpp index 2a812b5d9..d0da1a686 100644 --- a/include/libtorrent/utf8.hpp +++ b/include/libtorrent/utf8.hpp @@ -121,7 +121,7 @@ static OutputIterator wchar_utf8(InputIterator first, InputIterator last, Output static void utf8_wchar(const std::string &utf8, std::wstring &wide) { wide.clear(); - utf8_wchar(utf8.begin(), utf8.end(), std::insert_iterator(wide, wide.end())); + detail::utf8_wchar(utf8.begin(), utf8.end(), std::insert_iterator(wide, wide.end())); } static std::wstring utf8_wchar(const std::string &str) { @@ -132,7 +132,7 @@ static std::wstring utf8_wchar(const std::string &str) { static std::string wchar_utf8(const std::wstring &wide, std::string &utf8) { utf8.clear(); - wchar_utf8(wide.begin(), wide.end(), std::insert_iterator(utf8, utf8.end())); + detail::wchar_utf8(wide.begin(), wide.end(), std::insert_iterator(utf8, utf8.end())); } static std::string wchar_utf8(const std::wstring &str) { diff --git a/src/file_win.cpp b/src/file_win.cpp index d6c0a1b04..5f0d2da30 100644 --- a/src/file_win.cpp +++ b/src/file_win.cpp @@ -57,15 +57,19 @@ namespace void throw_exception(const char* thrower) { - char *buffer = 0; int err = GetLastError(); - #ifdef _UNICODE + #ifdef UNICODE + wchar_t *wbuffer = 0; FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_ALLOCATE_BUFFER - , 0, err, 0, (LPWSTR)(LPCSTR)&buffer, 0, 0); + , 0, err, 0, (LPWCSTR)&wbuffer, 0, 0); + std::string tmp_utf8; + wchar_utf8(wbuffer, tmp_utf8); + char* buffer = tmp_utf8.c_str(); #else + char* buffer = 0; FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_ALLOCATE_BUFFER @@ -116,7 +120,7 @@ namespace libtorrent assert(access_mask & (GENERIC_READ | GENERIC_WRITE)); - #ifdef _UNICODE + #ifdef UNICODE std::wstring wfile_name(utf8_wchar(file_name)); HANDLE new_handle = CreateFile( (LPCWSTR)wfile_name.c_str()