Why is this failing in an ANSI build ?
sprintf_s is returning -1, szBuf is set to an empty string.
I can totally understand that it can't convert the chinese character in there to the ANSI set and that it would either print nothing or a placeholder character in that spot, but why does it fail?
Is it supposed to fail under this condition?
Is there a way to work around it so it does at least give me either "abc -- def" or "abc -x- def" (with x being whatever placeholder char to signify no matching ANSI char)
I checked how the MSVC library handles this, and can't see a way to avoid this behaviour (unless you write your own sprintf.)
If the "C" locale is set, any two byte character above 255 will cause sprintf to fail with no ouptput and errno = EILSEQ (A wide-character code that does not correspond to a valid character has been detected.)
Using another locale, MSVC will call WideCharToMultiByte to convert to the system codepage. If this fails, or if the default character is used, sprintf will fail with no output and errno = EILSEQ.