TCHAR is defined as wchar_t in a Unicode build, but as char in a non Unicode build. So if you’re not using Unicode (i.e. don’t have _UNICODE defined in the project’s preprocessor settings), then you can simply pass in the TCHAR str[256] to a function that expects a char * , otherwise you will have to convert the string from Unicode to non-Unicode using wcstombs function.
当你编译UNICODE 版本的程序时,TCHAR 被定义为wchar_t (宽字符),在非unicode编译版本中它就相当于ansi C中的char .
因此,如果你没有使用Unicode(比如你没有在项目的预处理设置里面定义_UNICODE ),那么你可以简单地将 TCHAR str[256] 传递给一个需要char * 类型参数的函数,否则你不得不用wcstombs (荒野无灯注:这个函数已经不推荐使用了,推荐使用wcstombs_s)函数将这个字符串从Unicode转换为非unicode字符串。
from: http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/0073fa7b-5cf5-469c-978f-2961f9d4ecb2/
喜欢这篇文章吗?
请订阅本站 RSS feed 或




回复 (0)