//实现编码由utf-8到ANSI的转换
char*Utf2ANSI(char*srcCode)
{
int srcCodeLen=0 ;
srcCodeLen=MultiByteToWideChar(CP_UTF8,NULL,srcCode,strlen(srcCode),NULL,0);
wchar_t*result_t=new wchar_t[srcCodeLen+1];
MultiByteToWideChar(CP_UTF8,NULL,srcCode,strlen(srcCode),result_t,srcCodeLen);
//utf-8转换为Unicode
result_t[srcCodeLen]='\0' ;
srcCodeLen=WideCharToMultiByte(CP_ACP,NULL,result_t,wcslen(result_t),NULL,0,NULL,NULL);
char*result=new char[srcCodeLen+1];
WideCharToMultiByte(CP_ACP,NULL,result_t,wcslen(result_t),result,srcCodeLen,NULL,NULL);
//Unicode转换为ANSI
result[srcCodeLen]='\0' ;
delete result_t ;
return result ;
}
原文地址:http://bbs.sciencenet.cn/thread-107913-1-1.html