1

Possible Duplicate:
Why both UNICODE and _UNICODE?

What is the difference between UNICODE and _UNICODE? Do we need to define both if compiling the program to use unicode characters? Is there a reason we have 2 different identifiers for using unicode characters?

Community
  • 1
  • 1
patentfox
  • 1,436
  • 2
  • 13
  • 28

1 Answers1

4

Raymond Chen has an answer:

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

Community
  • 1
  • 1
Joey
  • 344,408
  • 85
  • 689
  • 683
  • ...and you usually define neither or both in a project. – Anders Jun 17 '12 at 16:00
  • While true, looking at the other question's answer reveals that `UNICODE` is defined when `_UNICODE` is defined, so it *should* suffice to define `_UNICODE` alone. – Joey Jun 17 '12 at 16:03
  • @Joey - Well, not exactly. If only _UNICODE is defined, TCHAR is defined to be char (and not WCHAR) – patentfox Jun 17 '12 at 16:13
  • Then I perhaps have misunderstood the code snippet posted [in that answer](http://stackoverflow.com/a/7953476/73070) which appears to set `UNICODE` whenever `_UNICODE` is defined without `UNICODE`. – Joey Jun 17 '12 at 16:16
  • That code snippet might occur in some header file not included via Windows.h or TCHAR.h. That seems to be the only logical explanation to me. – patentfox Jun 17 '12 at 16:24
  • Note that if any of the standard C headers respond to `UNICODE` being defined or not, this renders the implementation badly non-conformant. – R.. GitHub STOP HELPING ICE Jun 17 '12 at 16:39