字符和TCHAR之间的区别 [英] The difference between characters and TCHARs

查看:115
本文介绍了字符和TCHAR之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过MSDN返回的API返回的缓冲区大小,有时是字符,有时是TCHAR,能否告诉我字符和TCHAR(在UNICODE项目或多字节项目上)之间的区别.

Have a look at this[^] nice CP Tip/Trick. TCHAR is well explained there. :)


TCHAR is defined as char in a non-Unicode project, and as WCHAR (16 bit character) in a Unicode project. This allows the same code to be ported from non-Unicode to Unicode fairly easily.


For the first: TCHAR is not a type themselves - its a placeholder for the character type you use. This can be:
* unicode characters (unsigned short or wchar_t)
* ANSI characters (char).
this depends on your project settings. You can plan your module to support both of them. Therefore you have to generate a project configuration for each. But now what can do TCHAR for you? if you use TCHAR as type for character or string operations you can compile both versions in the same way. The only thing you have to is to include <tchar.h> that maps (#define) the necessary function for you.
i.e.:
* _tcscmp: strcmp or wcscmp
* _tcslen: strlen or wcslen
* and so on.
Regards.


这篇关于字符和TCHAR之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆