From: Giovanni Dicanio on
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).

G



From: Tom Serface on
Yeah, but I should know better. I've been around the coffee cup enough
times to know where the handle is :o)

Tom

"Giovanni Dicanio" <giovanniDOTdicanio(a)REMOVEMEgmail.com> wrote in message
news:uS1HVfacJHA.1760(a)TK2MSFTNGP05.phx.gbl...
>
> 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).
>
> G
>
>
>

From: Giovanni Dicanio on
Tom Serface wrote:
> I've been around the coffee cup enough
> times to know where the handle is :o)

:D

The second time you write that!

G
From: Giovanni Dicanio on
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 );

and

TCHAR * pszBuf = &szBuf[0];

Giovanni




From: Mihai N. on

> 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++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email