Norman Diamond
2006-10-20 05:01:19 UTC
StringCchPrintf is broken, verified with the debugger in Visual Studio 2005
on Windows XP Pro, target running on a Windows Mobile 5 Pocket PC.
All machines, Windows versions, and Visual Studio 2005 are the same language
version, Japanese. The Windows Mobile 5 Pocket PC SDK is US-English.
char devnm[50]; // ANSI because gethostname doesn't handle Unicode
char *mdlnm = "Pocket PC"; // ANSI for no reason at the moment
gethostname(devnm, sizeof devnm);
#ifdef _UNICODE
StringCchPrintf(szTraceInfo, ARRAYSIZE(szTraceInfo),
_T("device type \"%S\", hostname \"%S\""), mdlnm, devnm);
#else
StringCchPrintf(szTraceInfo, ARRAYSIZE(szTraceInfo),
_T("device type \"%s\", hostname \"%s\""), mdlnm, devnm);
#endif
// breakpoint on the next line of code
...
The Unicode version of StringCchPrintf was executed, as expected in
Windows CE.
mdlnm was a constant this time as shown:
Pocket PC
devnm was an ANSI string 15 bytes long including the NUL terminator:
ソフト開発iPaq
The result:
device type "Pocket PC", hostname ""
StringCchPrintf really can't handle conversion between ANSI and Unicode, so
maybe that's why MSDN doesn't say it can. (Except that StringCchPrintf
managed to handle one conversion, where a string only used a small subset of
all the characters that exist in the default and current code page.)
on Windows XP Pro, target running on a Windows Mobile 5 Pocket PC.
All machines, Windows versions, and Visual Studio 2005 are the same language
version, Japanese. The Windows Mobile 5 Pocket PC SDK is US-English.
char devnm[50]; // ANSI because gethostname doesn't handle Unicode
char *mdlnm = "Pocket PC"; // ANSI for no reason at the moment
gethostname(devnm, sizeof devnm);
#ifdef _UNICODE
StringCchPrintf(szTraceInfo, ARRAYSIZE(szTraceInfo),
_T("device type \"%S\", hostname \"%S\""), mdlnm, devnm);
#else
StringCchPrintf(szTraceInfo, ARRAYSIZE(szTraceInfo),
_T("device type \"%s\", hostname \"%s\""), mdlnm, devnm);
#endif
// breakpoint on the next line of code
...
The Unicode version of StringCchPrintf was executed, as expected in
Windows CE.
mdlnm was a constant this time as shown:
Pocket PC
devnm was an ANSI string 15 bytes long including the NUL terminator:
ソフト開発iPaq
The result:
device type "Pocket PC", hostname ""
StringCchPrintf really can't handle conversion between ANSI and Unicode, so
maybe that's why MSDN doesn't say it can. (Except that StringCchPrintf
managed to handle one conversion, where a string only used a small subset of
all the characters that exist in the default and current code page.)