Unicode

来源:互联网 发布:dhcp服务器需要mac 编辑:程序博客网 时间:2024/06/06 21:02

在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 theGlobalAlloc 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