Prev: Let 's talk about how to custom draw a window caption bar,any one interesting?
Next: CFileDialog Exception
From: Giovanni Dicanio on 8 Jan 2009 10:42
Tom Serface wrote:
> I was looking at the documentation. I apologize. I didn't think I had
> to read into the code to get the actual scoop and from that prototype I
> agree totally that it looks like it's asking for number of characters.
> In the doco it said "size of the buffer" and didn't even list a wide
> version at all.
Tom: you don't have to apologize! The documentation writers should!
One is supposed to read the documentation and trust it, instead of
studying the header files (like I've done).
From: Tom Serface on 8 Jan 2009 11:05
Yeah, but I should know better. I've been around the coffee cup enough
times to know where the handle is :o)
"Giovanni Dicanio" <giovanniDOTdicanio(a)REMOVEMEgmail.com> wrote in message
> Tom: you don't have to apologize! The documentation writers should!
> One is supposed to read the documentation and trust it, instead of
> studying the header files (like I've done).
From: Giovanni Dicanio on 8 Jan 2009 11:08
Tom Serface wrote:
> I've been around the coffee cup enough
> times to know where the handle is :o)
The second time you write that!
From: Giovanni Dicanio on 8 Jan 2009 11:20
Giovanni Dicanio wrote:
> So, the code logic is simpler and there is no need for the loop:
> TCHAR szBuf[ 64*1024 ]; // 64K TCHAR buffer
> WORD cchBufMax = _countof(szBuf) - 1;
BTW: A small side note... I think that it should be fine to allocate
this size (64KB on ANSI builds, or 2*64KB = 128KB on Unicode builds) on
the stack (I think that C++ stack is big enough...).
However, as an alternative, that memory could be allocated on the heap
as well, using convenient std::vector:
std::vector< TCHAR > szBuf( 64*1024 );
TCHAR * pszBuf = &szBuf;
From: Mihai N. on 8 Jan 2009 22:34
> I think that Tom was mislead by this documentation (if I read 'cb'
> prefix, I think of sizeof(), too, like Tom did; instead, if I read 'cch'
> prefix, I think about _countof()).
See, the safest way to not be mislead by the documentation is to not
read it at all (like me :-)
Thing is, in general strings taking a buffer of "characters"
(char/TCHAR/wchar_t/WCHAR/whatever) also take a "character count",
and the buffer size is in characters.
The only exception that I know is the "safe strings" API
that has a set of APIs using byte counts (StringCbWhatever).
Weird, it feels upside-down.
Mihai Nita [Microsoft MVP, Visual C++]
Replace _year_ with _ to get the real email