On the Windows platform, "ANSI" (
multi-byte) strings use the
char type and are
1 byte in size (per character
*), but "Unicode" (UTF-16) strings use the
wchar_t type and are
2 bytes in size (per character).
Note that, nowadays,
char-based (multi-byte) strings are usually encoded in
UTF-8, but it could be one of the "legacy" Codepages, such as
ISO 8859-1 (aka
Latin-1, aka
Windows-1252), just as well.
You use the functions
MultiByteToWideChar() and
WideCharToMultiByte() to convert between
char-based and
wchar_t-based strings. Simply
assigning a
wchar_t to the value of a
char does
not work for anything but plain ASCII – it breaks (not only) for characters that are encoded as a sequence of
multiple bytes !!!
See here for a proper example:
https://gitlab.xiph.org/xiph/opus-tools/-/blob/master/win32/unicode_support.c#L39
In MSVC, the "traditional" string functions from the C Standard Library, such as
strcpy(), are
deprecated – in favor of the "secure" versions, such as
strcpy_s(). Just use the "secure" versions, if your code will only be compiled by MSVC. Otherwise, if you need to support other compilers too, then you can ignore (or even disable) the deprecation warning.
lstrcpy() is from the Win32 API,
not C Standard Library; better
avoid using it.
Also note: If you are dealing with
wchar_t (UTF-16) strings, then you
must use the "wide string" functions
wcslen(),
wcscpy() or
wcscpy_s() instead of the "normal" functions
strlen(),
strcpy() or
strcpy_s() !!!
Likewise,
lstrcpy() exists as
lstrcpyA() and
lstrcpyW() variants, for
multi-byte and
UTF-16 strings. In fact,
lstrcpy() is just a
macro that expands to either
lstrcpyA() or
lstrcpyW(), depending on configuration.
lstrcpy((LPWSTR)Locations[0],L"Location 1"); |
Do
not cast the
char* pointer to
wchar_t* pointer. It may compile, but still is utterly wrong here :-(
* In fact, in multi-byte strings, a single character may actually occupy multiple chars (bytes) !!!