16,471
社区成员
发帖
与我相关
我的任务
分享
char* CAotoCallDlg::G2U(const char* gb2312)
{
int len = MultiByteToWideChar(CP_ACP, 0, gb2312, -1, NULL, 0);
wchar_t* wstr = new wchar_t[len+1];
memset(wstr, 0, len+1);
MultiByteToWideChar(CP_ACP, 0, gb2312, -1, wstr, len);
len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
char* str = new char[len+1];
memset(str, 0, len+1);
WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, len, NULL, NULL);
if(wstr)
delete[] wstr;
return str;
}
//**************************************
// unicode字符串转utf8字符串
// 返回大于0成功,小于0失败
//**************************************
int
ustr_u8str( WCHAR *unicodestr, char *utf8str )
{
int result = 0;
try
{
int needlen = WideCharToMultiByte( CP_UTF8, 0, unicodestr, -1, NULL, 0, NULL, NULL );
if( needlen < 0 )
{
return needlen;
}
result = WideCharToMultiByte( CP_UTF8, 0, unicodestr, -1, utf8str, needlen + 1, NULL, NULL );
if( result < 0 )
{
return result;
}
return ( result - 1 );
}
catch( ... )
{
ShowError();
}
return result;
}
//**************************************
// ansi字符串转unicode字符串
// 返回大于0成功,小于0失败
//**************************************
int
astr_ustr( char *ansistr, WCHAR *unicodestr )
{
int result = 0;
try
{
int needlen = MultiByteToWideChar( g____ansi_codepage, 0, ansistr, -1, NULL, 0 );
if( needlen < 0 )
{
return needlen;
}
result = MultiByteToWideChar( g____ansi_codepage, 0, ansistr, -1, unicodestr, needlen );
if( result < 0 )
{
return result;
}
return result;
}
catch( ... )
{
ShowError();
}
return result;
}