1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
inline wchar_t* AnsiToUnicode( const char* szStr ) { int nLen = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, szStr, -1, NULL, 0 ); if (nLen == 0) { return NULL; } wchar_t* pResult = new wchar_t[nLen]; MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, szStr, -1, pResult, nLen ); return pResult; }
inline char* UnicodeToAnsi( const wchar_t* szStr ) { int nLen = WideCharToMultiByte( CP_ACP, 0, szStr, -1, NULL, 0, NULL, NULL ); if (nLen == 0) { return NULL; } char* pResult = new char[nLen]; WideCharToMultiByte( CP_ACP, 0, szStr, -1, pResult, nLen, NULL, NULL ); return pResult; }
inline void Ascii2WideString( const std::string& szStr, std::wstring& wszStr ) { int nLength = MultiByteToWideChar( CP_ACP, 0, szStr.c_str(), -1, NULL, NULL ); wszStr.resize(nLength); LPWSTR lpwszStr = new wchar_t[nLength]; MultiByteToWideChar( CP_ACP, 0, szStr.c_str(), -1, lpwszStr, nLength ); wszStr = lpwszStr; delete [] lpwszStr; }
|