unicode 的体会

关于windows下使用的函数:
1:windows api 涉及到字符串参数的 ANSI版本函数,均是在函数内部转换为 unicode,然后使用unicode版本函数进行调用,来完成函数功能,所以使用windows api使用 unicode较好。

2:ansi 函数有unicode版本的函数,但是其内部是把unicode转换为 ansi c单字节,使用,故调用ansi c函数,则使用ansi 编码较好

这样做,估计是为了稳定。
unicode 部分编码:
UTF-8:
     0x00 -  0x7f           1B
     0x008f - 0x07ff      2B
     0X0800 - 0XFFFFFF      3B
                                   4B 
     节省空间,适合于网络传输

UTF-16:
     windows 标准
     2B   4B  
     中庸之道。

UTF-32:
     统一4字节,解码快,内存占用多,一般在本地使用


//code
// from  ansi to unico
void CStringTostring(CString theCString, std::string &thestring, DWORD theType)
{
     int len = WideCharToMultiByte(theType, 0, theCString, -1, NULL, 0, NULL, NULL);
     char* pCxml = new char[len + 1];
     len = WideCharToMultiByte(theType, 0, theCString, theCString.GetLength(), pCxml, len + 1, NULL, NULL);
     pCxml[len] = 0;
     std::string tString(pCxml);
     thestring = tString;
     delete[] pCxml;
    
}

void stringToCString(std::string thestring, CString &theCString, int theType))
{
     int len = MultiByteToWideChar(theType, 0, thestring.c_str(), -1, NULL, 0);
     WCHAR* pCxml = new WCHAR[len + 1];
     len = MultiByteToWideChar(theType, 0, thestring.c_str(), thestring.length(), pCxml, len);
     pCxml[len] = 0;
     CString tString(pCxml);
     theCString = tString;
     delete[] pCxml;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值