为什么有不同的TEXT类似的宏在win32同样的东西? [英] Why are there different TEXT like macros for the same thing in win32?

查看:247
本文介绍了为什么有不同的TEXT类似的宏在win32同样的东西?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么有宏,如T,TEXT,_TEXT,__TEXT或__T,当他们都最终做同样的事情。



ie



如果定义了UNICODE,则将string映射到Lstring。



感谢您的答案。在一个更实用的方法,有人可以解释我下面给出的代码的行为?

  #include< stdio.h> 
#include< conio.h>
#include< tchar.h> // For _T and _TEXT
#include< windows.h> // For __TEXT

int __cdecl main()

{

printf(%s,_TEXT(__ FILE__)); // Works fine

printf(%s,_T(__ FILE__)); // Works fine

printf(%s,__TEXT(__ FILE__)); // error C2065:'L__FILE__':undeclared identifier

_getwch();

}

更新:
我认为我的代码有东西与C预处理器标记化有关。我为此发布了一个单独的问题。

解决方案

由于奥术事情经常发生,Raymond Chen 提供一些信息(增加了强调):


那么,所有这些不同的方式说同样的事情是什么?
实际上有一个方法背后的疯狂。



纯文本(不带下划线)影响字符集
Windows头文件视为默认
。所以如果你定义UNICODE,那么
GetWindowText将映射到GetWindowTextW,而不是GetWindowTextA,
。类似地,TEXT宏将映射到L...而不是
...。



带有下划线的版本影响字符集
C运行时头文件处理为默认
。因此,如果你定义_UNICODE,
然后_tcslen将映射到wcslen而不是strlen,例如。
类似地,_TEXT宏将映射到L...而不是...。 _T什么
?好吧,我不知道那个。也许只是为了节省
某人打字。



I want to know the reason why there are macros such as T, TEXT, _TEXT, __TEXT or __T when they all ultimately do the same thing.

i.e.

mapping "string" to L"string" if UNICODE is defined.

Thanks for the answers. On a more practical approach, can somebody explain me the behavior of the code given below?

#include <stdio.h>
#include <conio.h>
#include <tchar.h>   // For _T and _TEXT
#include <windows.h> // For __TEXT 

int __cdecl main ()

{

  printf ("%s", _TEXT(__FILE__ ));  // Works fine

  printf ("%s", _T(__FILE__));      // Works fine

  printf ("%s", __TEXT(__FILE__ )); // error C2065: 'L__FILE__': undeclared identifier

  _getwch();

}

Update: I think my code has something to do with C preprocessor tokenization. I am posting a separate question for that. Thanks.

解决方案

As it is often the case with "arcane" things, Raymond Chen gives some information (emphasis added):

So what's with all these different ways of saying the same thing? There's actually a method behind the madness.

The plain versions without the underscore affect the character set the Windows header files treat as default. So if you define UNICODE, then GetWindowText will map to GetWindowTextW instead of GetWindowTextA, for example. Similarly, the TEXT macro will map to L"..." instead of "...".

The versions with the underscore affect the character set the C runtime header files treat as default. So if you define _UNICODE, then _tcslen will map to wcslen instead of strlen, for example. Similarly, the _TEXT macro will map to L"..." instead of "...". What about _T? Okay, I don't know about that one. Maybe it was just to save somebody some typing.

这篇关于为什么有不同的TEXT类似的宏在win32同样的东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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