MFC开发IM-第二十一篇、Unicode转成Utf8
2018-03-21 16:25
183 查看
//UnicodeToUtf8 Unicode转成Utf8
char* mainDlg::UnicodeToUtf8(const wchar_t* unicode)
{
int len;
len = WideCharToMultiByte(CP_UTF8, 0, unicode, -1, NULL, 0, NULL, NULL);
char *szUtf8 = (char*)malloc(len + 1);
memset(szUtf8, 0, len + 1);
WideCharToMultiByte(CP_UTF8, 0, unicode, -1, szUtf8, len, NULL, NULL);
return szUtf8;
}
int length;
wchar_t* wCharUnicode = L"中国你好";
length = wcslen(wCharUnicode); // length = 4;
char* cCharUtf = UnicodeToUtf8(wCharUnicode);
length = strlen(cCharUtf); // length = 12;
// 将UTF格式的char*转为CString
CString strUtf(cCharUtf);
length = strUtf.GetLength(); // length = 6;
//CString strUnicode = UTF82WCS(cCharUtf);
//length = strUnicode.GetLength(); // length = 4;
// wchar_t* wCharUnicode = L"中国";
// char* cCharUtf = UnicodeToUtf8(wCharUnicode);
const char* c_s ="是";
const char* cpc;
char* pc="abcde";
cpc=cCharUtf;
send(main_socket, cpc,length, 0);
char* mainDlg::UnicodeToUtf8(const wchar_t* unicode)
{
int len;
len = WideCharToMultiByte(CP_UTF8, 0, unicode, -1, NULL, 0, NULL, NULL);
char *szUtf8 = (char*)malloc(len + 1);
memset(szUtf8, 0, len + 1);
WideCharToMultiByte(CP_UTF8, 0, unicode, -1, szUtf8, len, NULL, NULL);
return szUtf8;
}
int length;
wchar_t* wCharUnicode = L"中国你好";
length = wcslen(wCharUnicode); // length = 4;
char* cCharUtf = UnicodeToUtf8(wCharUnicode);
length = strlen(cCharUtf); // length = 12;
// 将UTF格式的char*转为CString
CString strUtf(cCharUtf);
length = strUtf.GetLength(); // length = 6;
//CString strUnicode = UTF82WCS(cCharUtf);
//length = strUnicode.GetLength(); // length = 4;
// wchar_t* wCharUnicode = L"中国";
// char* cCharUtf = UnicodeToUtf8(wCharUnicode);
const char* c_s ="是";
const char* cpc;
char* pc="abcde";
cpc=cCharUtf;
send(main_socket, cpc,length, 0);
相关文章推荐
- MFC开发IM-第二十三篇、C++中 UTF-8转成Unicode
- MFC开发IM-第一篇
- MFC开发IM-第二篇、MFC picture 控件的用法
- MFC 多字节和UNICODE的相互转换(解决中文utf8-ASCNII乱码问题)
- MFC开发IM-第九篇、如何初始化LPCTSTR
- MFC(UNICODE)进行UrlEncode编码(UTF8和GB2312)
- MFC开发IM-第十六篇、如何使用其他对话框的变量
- 【VS开发】VS2013多字节工程问题uilding an MFC project for a non-Unicode character set is deprecated
- MFC开发IM-第十篇、MFC改变static text颜色
- MFC的中文路径的解决问题Ansi、Unicode、UTF8字符串之间的转换
- MFC开发IM-第六篇、MFC 文本框 用法
- MFC开发IM-第三篇、资源视图--显示在另一个编辑器中打开
- MFC开发IM-第十三篇、MFC改变字体重影的问题
- MFC开发IM-第二十七篇、如何引入acl,解决Json解析问题
- 嵌入式开发之字符叠加---gb2313 国标码,utf8 国际码,unicode 无码
- MFC开发IM-第十二篇、MFC改变static text背景色为透明
- MFC开发IM-第五篇、MFC中改变static字体颜色、大小、背景颜色(自定义类),及手动关联变量的方法
- MFC开发IM-第十五篇、打包的MFC程序别人无法启动的原因
- MFC开发IM-第八篇、调整各个控件的上下tab顺序
- MFC开发IM-第七篇、mfc设置默认编辑框内容