原文地址:http://hi.baidu.com/zj41342626/item/6a951c437c094315886d107b
windows上unicode与utf8之间的转换
wchar_t* TransformUTF8ToUnicodeM(const char* _str)
{
int textlen =0;
wchar_t * result = NULL;
if (_str)
{
textlen = MultiByteToWideChar( CP_UTF8, 0, _str,-1, NULL,0 );
result = (wchar_t *)malloc((textlen+1)*sizeof(wchar_t));
memset(result,0,(textlen+1)*sizeof(wchar_t));
MultiByteToWideChar(CP_UTF8, 0,_str,-1,(LPWSTR)result,textlen );
}
return result;
}
char* TransformUnicodeToUTF8M(const wchar_t* _str)
{
char* result = NULL;
int textlen = 0;
if (_str)
{
textlen = WideCharToMultiByte( CP_UTF8, 0, _str, -1, NULL, 0, NULL, NULL );
result =(char *)malloc((textlen+1)*sizeof(char));
memset(result, 0, sizeof(char) * ( textlen + 1 ) );
WideCharToMultiByte( CP_UTF8, 0, _str, -1, result, textlen, NULL, NULL );
}
return result;
}