Re: CString to LPCSTR



Actually, it does take that into account; the string = string.Right(...) handles lopping
off the first part. Of course, since it isn't Unicode-aware, it gets it wrong in a number
of ways, but once fixed for Unicode-awareness, it should handle that situation (I would
have done .Mid(cb/sizeof(TCHAR)) which seems easier, but Right(), done right, should work)
joe

On Sat, 29 Dec 2007 14:40:14 GMT, "David Ching" <dc@xxxxxxxxxxxxxxxxxxxxxx> wrote:

"Al" <Al@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:3E2D7296-DB98-4F4E-8A73-D0D161E859CF@xxxxxxxxxxxxxxxx
Thanks for the help and the extra help. I was thinking that I had to
convert
the CString to a LPCSTR and I wasn't getting the fact that I could just
change the code to LPCTSTR. Thanks for clearing that up.
--
Just Al


The proper thing to do depends on what format of text the RichEdit control
is expecting. Since you're apparently building the project with UNICODE
(since CString doesn't cast to LPCSTR), I assume the RichEdit control is
expecting Unicode text. In that case, yes, you do can cast the CString to
LPCTSTR (which translates to LPCWSTR) and put that into the byte buffer of
the RichEdit control. But the memcpy() last parameter needs to be limited
by the minimum size of the byte buffer, or the length of the string. I like
to use StringCbCopy() to ensure the destination buffer does not get
overwritten.

Also, the RichEdit callback works such that if the entire contents can't fit
into the byte buffer, then you get called back again to put the next chunk
of contents into the byte buffer. Your callback needs to remember where it
left off the previous time so it can start at that point in the string. I
don't see the code to do that here.

-- David

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages


Loading