Most Windows APIs that take strings have two versions: one that accepts char *
and one that accepts WCHAR *
(the latter is equivalent to wchar_t *
).
SetWindowText
, for example, is actually a macro that expands to SetWindowTextA
(which accepts char *
) or SetWindowTextW
(which accepts WCHAR *
).
In your project, it looks like all of these macros are referencing versions of -W. This is controlled by the UNICODE
preprocessor macro (which is determined if you select the "Use Unicode Character Set" project option in Visual Studio). (Some of the Microsoft C and C ++ runtime library functions also have ANSI and wider versions. Which you get is selected by a macro with the same name _UNICODE
, which is also determined by this setting of the Visual Studio project.)
Typically, both -A and -W functions exist in libraries and are available even if your application is compiled for Unicode. (There are exceptions, some new features are only available in the "wide" versions.)
If you have a char *
containing the text on the corresponding ANSI code page, you can explicitly invoke the -A version (e.g. SetWindowTextA
). Versions of -A are typically wrappers that create wide copies of characters in string parameters and transfer control to the -W version.
An alternative is to create your own custom character characters. You can do this with MultiByteToWideChar . Calling this can be tricky because you need to manage buffers. If you can get away with a call to the -A version directly, which is usually simpler and already verified. But if your char *
string uses UTF-8 or any encoding other than the current ANSI code page, you must do the conversion yourself.
Bonus Information
The suffix -A means "ANSI", which is a general Windows term for a single-byte character set for a code page.
The suffix -W means "Wide" (which means that the coding units are wider than one byte). In particular, Windows uses small-end UTF-16 for wide strings. The MSDN documentation just calls this Unicode, which is a bit wrong.
source share