If the string is successfully encoded, the return value
is the number of characters copied to the output buffer. If the text
cannot be encoded, or the output buffer is not large enough to store
all of the encoded text, the function will return zero. To get
extended error information, call GetLastError.
There are two versions of this function, UnicodeEncodeTextA
which converts a multi-byte string to UTF-8 encoded text, and
UnicodeEncodeTextW
which converts a UTF-16 string to a UTF-8 string. Your project
configuration typically determines which version of this function is
used by default.
If the value of the nLength parameter is larger than the
number of characters in lpString, the function will not check beyond
the terminating null character. If the length of lpString is
unknown, specify a length of -1 and the function will encode the entire
contents of the string up to the terminating null character.
When calling UnicodeEncodeTextA to convert a multi-byte string
to UTF-8 encoding, it is recommended that
you specify CP_ACP (zero) as the code page value unless you know it
contains ANSI characters from a different code page. Using CP_ACP will ensure the
string is encoded using the current locale and
language settings.
This function performs a strict check on the multi-byte input
string and
will fail if it contains a malformed multi-byte sequence or characters that cannot be converted to UTF-8
using the specified code page. It will not simply replace invalid character
sequences with a default character.
When calling UnicodeEncodeTextW to convert UTF-16 text
to UTF-8 encoded text, the code page parameter is ignored and
should always be a value of zero. The text will be normalized prior to
being converted to UTF-8 using canonical composition, where decomposed
characters are combined to create their canonical precomposed
equivalent.