@@ -208,18 +208,40 @@ bool CLinkSnapshot::DeleteLink(DWORD dwLinkID)
208208 return false ;
209209}
210210
211- std::wstring utf8_to_wstring (const std::string& str )
211+ std::wstring utf8_to_wstring (const std::string& string )
212212{
213- // convert UTF-8 string to wstring
214- std::wstring_convert<std::codecvt_utf8<wchar_t >> myconv;
215- return myconv.from_bytes (str);
213+ if (string.empty ())
214+ {
215+ return L" " ;
216+ }
217+
218+ const auto size_needed = MultiByteToWideChar (CP_UTF8, 0 , string.data (), (int )string.size (), nullptr , 0 );
219+ if (size_needed <= 0 )
220+ {
221+ throw std::runtime_error (" MultiByteToWideChar() failed: " + std::to_string (size_needed));
222+ }
223+
224+ std::wstring result (size_needed, 0 );
225+ MultiByteToWideChar (CP_UTF8, 0 , string.data (), (int )string.size (), result.data (), size_needed);
226+ return result;
216227}
217228
218- std::string wstring_to_utf8 (const std::wstring& str )
229+ std::string wstring_to_utf8 (const std::wstring& wide_string )
219230{
220- // convert wstring to UTF-8 string
221- std::wstring_convert<std::codecvt_utf8<wchar_t >> myconv;
222- return myconv.to_bytes (str);
231+ if (wide_string.empty ())
232+ {
233+ return " " ;
234+ }
235+
236+ const auto size_needed = WideCharToMultiByte (CP_UTF8, 0 , wide_string.data (), (int )wide_string.size (), nullptr , 0 , nullptr , nullptr );
237+ if (size_needed <= 0 )
238+ {
239+ throw std::runtime_error (" WideCharToMultiByte() failed: " + std::to_string (size_needed));
240+ }
241+
242+ std::string result (size_needed, 0 );
243+ WideCharToMultiByte (CP_UTF8, 0 , wide_string.data (), (int )wide_string.size (), result.data (), size_needed, nullptr , nullptr );
244+ return result;
223245}
224246
225247CString GetModuleFileName (_Inout_opt_ DWORD* pdwLastError = nullptr );
0 commit comments