I am writing an Excel plugin and should generate wchar_t output for Excel (although internally we are 100% char , and in fact the char limit is ASCII). At some point, I use swprintf to do the conversion:
static wchar_t buffer[ 32369 ]; buffer[0] = swprintf( buffer + 1, sizeof(buffer) - 1, L"#%s!", message );
Excel displays some CJK characters, although message ( char const* type char const* ) is a character string with a null terminating character with no characters outside of printable ASCII (hexadecimal values ββ0x20-0x7E).
I tried this in a small test program, flushing the generated string in hexadecimal format, and it looks like VC ++ is processing the message as if it were wchar_t const* (although it seems to correctly recognize '\0' , although it is on one byte) ; this leads to wchar_t with values ββlike 0x6568 (and not 0x0068, 0x0065 , which I expected).
According to the C99 standard for the specifier "%s" swprintf must convert characters from char const* "as if by repeated calls to the mbrtowc function [...]". Is the behavior that I see is a bug in the Visual C ++ library, or is there something in the global region that I have to change?
(FWIW: when I compile and run my small test program with g ++, I get the behavior I expect. However, g ++ is not an option for our Excel plugins, at least not now.)
source share