Re: _stprintf



The documentation for StringCchPrintf talks about counts of characters. In
an ANSI compilation each character occupies one or two TCHARs depending on
the actual character. The documentation for StringCchPrintf doesn't say
that TCHARs are counted where it does say that characters are counted.
....
Dr. Newcomer, you KNOW how, in an ANSI compilation, one 2-TCHAR character
will overflow a buffer which has enough space for only one 1-TCHAR
character.

I suspect it is the typical MSDN confusion when talking about characters.
Since in strsafe.h I can find both StringCchPrintfA and StringCchPrintfW,
I assume it works like all the Win32 API with regard to buffer lengths.
Meaning that when they say "character" in ANSI context, one should really
understand char. So 2 TCHAR character in a 1 TCHAR buffer will trigger
a "not enough space" error (not tested, but I am quite sure).
If this is not the case, it is definitely a bug.
When the documentation talks about character, then is a char in ANSI and
wchar_t/WCHAT in Unicode, totaly unaware of DBCS, surrogates, combining
chars.
There are in fact very few APIs that deal with what the "user character"


--
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
.



Relevant Pages

  • Re: _stprintf
    ... I don't have the source code to StringCchPrintf. ... any bit value of your choice for the character value, ... ANSI code page 932 is an encoding just like other ANSI code pages such ... code pages in special cases, e.g., %lc or %C format. ...
    (microsoft.public.vc.mfc)
  • Re: _stprintf
    ... I don't have the source code to StringCchPrintf. ... does NOT interpret the word 'character' this way. ... Try %c, in an ANSI ... code pages in special cases, e.g., %lc or %C format. ...
    (microsoft.public.vc.mfc)
  • Re: _stprintf
    ... The documentation for StringCchPrintf talks about counts of characters. ... In the ANSI ... each character occupies exactly one TCHAR. ...
    (microsoft.public.vc.mfc)
  • Re: Two bugs in GetPrivateProfileSectionNamesA
    ... The return value specifies the number of characters copied to the specified buffer, not including the terminating null character. ... If the buffer is not large enough to contain all the section names associated with the specified initialization file, the return value is equal to the length specified by nSize minus two. ... When bug 1 doesn't occur, i.e. when the buffer is either larger than necessary or too small, the return value is not the number of characters, it is the number of TCHARs. ...
    (microsoft.public.win32.programmer.tools)
  • Re: HDITEM and LVITEM
    ... >>> Yes an ANSI character and a Unicode character are both characters. ... >>> outside of Kernel Mode programming, most Windows functions count TCHARs. ...
    (microsoft.public.win32.programmer.ui)