Unicode

在MSDN中,关于函数中字符串长度参数,有这么一段描述:

When a function has a length parameter for a character string, the length should be documented as a count of TCHAR values in the string. This data type refers to bytes for Windows code page versions of the function or 16-bit words for Unicode versions. However, functions that require or return pointers to untyped memory blocks, such as the GlobalAlloc function, generally take a size in bytes, regardless of the prototype that is used. If the allocation of untyped memory is for a string, the application must multiply the number of characters by sizeof(TCHAR).                                      PS:搜索关键词 为 Conventions for Function Prototypes

这段描述是说,当一个函数的参数指的是字符串长度时,这个长度指的是该字符串中TCHAR的个数。也就是说,这个数据类型对于Windows code page版本(基本可以理解为ANSI,但略有不同)是byte的个数,对于Unicode版本是word(16bit)的个数。但是,对于那些需要或返回指向无类型内存块的指针的函数,例如GlobalAlloc,通常指的就是byte的个数了,而无须去理会原型是什么。如果无类型内存是为一个string分配的,那么,在分配的时候,空间的大小是(等于)string字符数目乘以TCHAR的大小。



WideCharToMultiByte:从Unicode到多字节可能存在部分字符的丢失,因为多字节的字符谱是Unicode字符谱的子集。

用该函数进行转换,可以首先用该函数得到待转换的字节数,然后再用该函数进行转换。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值