Why both UNICODE and _UNICODE?

后端 未结 3 572
梦谈多话
梦谈多话 2020-12-02 17:07

I\'ve been looking at the command line generated by Visual Studio, and for one of my project it defines two symbols: _UNICODE and UNICODE. Now if

3条回答
  •  無奈伤痛
    2020-12-02 17:23

    Raymond Chen explains it here: TEXT vs. _TEXT vs. _T, and UNICODE vs. _UNICODE:

    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 "...".

    Looking into Windows SDK you will find things like this:

    #ifdef _UNICODE
    #ifndef UNICODE
    #define UNICODE
    #endif
    #endif
    

提交回复
热议问题