#include "Common.h" ///////////////////// convert strings std::string ConvertWideToANSI(const std::wstring& wstr) { int count = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), wstr.length(), NULL, 0, NULL, NULL); std::string str(count, 0); WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, &str[0], count, NULL, NULL); return str; } std::wstring ConvertAnsiToWide(const std::string& str) { int count = MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length(), NULL, 0); std::wstring wstr(count, 0); MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length(), &wstr[0], count); return wstr; } std::string ConvertWideToUtf8(const std::wstring& wstr) { int count = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), wstr.length(), NULL, 0, NULL, NULL); std::string str(count, 0); WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, &str[0], count, NULL, NULL); return str; } std::wstring ConvertUtf8ToWide(const std::string& str) { int count = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), NULL, 0); std::wstring wstr(count, 0); MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), &wstr[0], count); return wstr; } //////////////////// Misc std::string GetWinErrorMessage(int id) { std::string ret(2048, 0); FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, id, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)ret.c_str(), ret.capacity(), NULL); return ret; } bool FileExists(LPCWSTR szPath) { DWORD dwAttrib = GetFileAttributes(szPath); return (dwAttrib != INVALID_FILE_ATTRIBUTES && !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)); }