UTF8ToANSI UTF8ToUnicode UnicodeToANSI

来源:互联网 发布:广州租房信息网软件 编辑:程序博客网 时间:2024/04/28 09:39
char * UnicodeToANSI( const wchar_t* str )
{
char* result;
int textlen;
textlen = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
result =(char *)malloc((textlen+1)*sizeof(char));
memset( result, 0, sizeof(char) * ( textlen + 1 ) );
WideCharToMultiByte( CP_ACP, 0, str, -1, result, textlen, NULL, NULL );
return result;
}




wchar_t * UTF8ToUnicode( const char* str )
{
int textlen ;
wchar_t * result;
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* UTF8ToANSI(const char* str)
{
wchar_t* temp = UTF8ToUnicode(str);
char* res = UnicodeToANSI(temp);
delete []temp;
return res;
}
原创粉丝点击