How should you use unicode strings in VC++? Of course you should to #define UNICODE, but what about your strings?
Should the TEXT() or _T() macro be used around all text or should you just put an L in front of strings? Its my belief that all programs should use unicode these days, so wouldn't it be cleanest to use use the L prefix?
Opinions?
It depends on what you want to achieve. If you want to make sure your code will compile and work correctly both with and without Unicode, use the TEXT
or _T
macros, and call the "default" Win32 function names (for example CreateWindow
).
If you want to make sure your program always uses the Unicode API, then you should use a L
prefix in front of your strings, and call the wide versions of Win32 functions (such as CreateWindowW
).
In the latter case, you'll get unicode behavior whether or not UNICODE
is defined.
In the former case, your application will change its behavior based on whether UNICODE
is defined.
I agree with you that the non-unicode versions haven't really been relevant since Win98, so I'd go with the second approach.
Declare Unicode string literals with L
prefix.
The TEXT()
or _T()
macros were for the bad old days when you wanted single source to compile for both Unicode and non-Unicode versions of Windows (Windows 9x). Thankfully you can safely ignore Windows 9x today.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With