For example, inside the WinUser.h header you'll find this MessageBox definition:
#ifdef UNICODE
#define MessageBox MessageBoxW
#else
#define MessageBox MessageBoxA
#endif // !UNICODE
These agnostic definitions help if you want the code to compile as both 32 bit and 64 bit without code changes. #ifdef UNICODE
#error This is written only for ANSI windows.
#endif
Or you can use TCHAR and _T().If you are dealing with user-created files you should always use the *W functions as filenames are not guaranteed to be valid UTF-16 and thus might not be accessible via UTF-8 *A calls. At least until Microsoft adds WTF-8 [0] support to the *A functions. You can use WTF-8 yourself internally of course so no need for wide strings outside your platform abstraction code.
During modern Windows development you should probably default to wide characters, of course.
> In 2001 Microsoft released an add-on for Windows 9x called the Microsoft Layer for Unicode (MSLU), which changed the W functions from failing-stubs to thunking proxies which converted the strings back into an 8-bit format and then called the A functions, so programs explicitly using W functions could run on Windows 9x.
Also lots of 16-bit character stuff all over COM.
Also, some APIs use buffers with a fixed maximum size, and the A API's buffer isn't big enough to handle the maximum possible data size for the W API.
And some APIs are Unicode-only, and don't have A versions.
For maximum reliability, better to use W APIs only and do the UTF-8<->UTF-16 conversion yourself.
However, in practice, if you just use A APIs only and let Windows do the UTF-8 conversion for you, it is going to work 95% of the time. But maybe at some point you'll hit that 5% where it doesn't. It is more likely if you are using more obscure APIs (like my example at the start of manipulating Windows Terminal Server sessions). More likely for system-level stuff than application-level.
You mean the WTF-8<->WTF-16 conversion.
> Until recently, Windows has emphasized "Unicode" -W variants over -A APIs. However, recent releases have used the ANSI code page and -A APIs as a means to introduce UTF-8 support to apps. If the ANSI code page is configured for UTF-8, then -A APIs typically operate in UTF-8. This model has the benefit of supporting existing code built with -A APIs without any code changes.
Or if you make it Windows 10+ only and add a particular manifest.