From: Eddards on
Again CStringA doest not work with VC6

"David Lowndes" <DavidL(a)example.invalid> wrote in message
news:v4h9c5h5usnivhlh6sd0eh4e9ut15014k9(a)4ax.com...
>
>>Is there a way to copy a CByteArray to a CString?
>
> Something like this:
>
> CByteArray ba;
> ba.Add('H');
> ba.Add('e');
> ba.Add('l');
> ba.Add('l');
> ba.Add('o');
>
> CStringA str( reinterpret_cast<LPCSTR>( ba.GetData() ),
> ba.GetSize() );
>
> Dave


From: Eddards on
I also need to replace any 0x00 (NULL) chars with 0x01 when copying to the
CString
Is this possible ?

"Eddards" <eddards(a)verizon.net> wrote in message
news:9fGdnWZaLPg3J1nXnZ2dnUVZ_u6dnZ2d(a)giganews.com...
>I am using VC6.
> Is there a way to copy a CByteArray to a CString?
>
>


From: David Lowndes on
>Again CStringA doest not work with VC6

Then ensure you build for non-Unicode (ANSI/MBCS) and just use
CString.

Dave
From: David Lowndes on
>I also need to replace any 0x00 (NULL) chars with 0x01 when copying to the
>CString

Are you sure you really want this to be a string?

>Is this possible ?

You might be best doing what Tom suggests and handle each character
individually in a loop.

Dave
From: Joseph M. Newcomer on
If you are building a Unicode app, you can't use CStringA.

One solution is to abandon a 12-year old and seriously out-of-date compiler and MFC.

If you have an ANSI NUL-terminated string (no embedded NUL characters, 8-bit character
set) the solution is

CByteArray buffer;
....set bytes in CByteArray
CString result;
LPWSTR p = T2CW(buffer.GetData());
result = p;
return result;

Read my essay on my MVP Tips site on CString techniques.
joe

On Thu, 1 Oct 2009 15:03:03 -0400, "Eddards" <eddards(a)verizon.net> wrote:

>As I said, I am using VC6 and CStringA doesnt work
>
>"Joseph M. Newcomer" <newcomer(a)flounder.com> wrote in message
>news:33h9c59jt650o15tei2qq5gbfbje5ghj32(a)4ax.com...
>> Does the CByteArray contain any embedded NUL characters? What is the
>> character encoding
>> used in the CByteArray (ANSI, Unicode UTF-8, Unicode UTF-16?)
>>
>> For example, if I have a message from an embedded controller (ANSI), then
>> I would do
>>
>> CByteArray msg;
>> ...
>> msg.SetSize(SOME_VALUE_HERE);
>> ReadDevice(msg);
>> ...
>> // I could do this
>>
>> CStringA text((LPCSTR)msg.GetData());
>> CString result(text);
>> return result;
>>
>>
>> Note that this works correctly in Unicode and ANSI builds.
>>
>> In the above example, the byte array is a NUL-terminated sequence of 8-bit
>> characters.
>>
>> But you need to say a *lot* more than you did about what is in the
>> CByteArray!
>> joe
>>
>> On Thu, 1 Oct 2009 10:18:24 -0400, "Eddards" <eddards(a)verizon.net> wrote:
>>
>>>I am using VC6.
>>>Is there a way to copy a CByteArray to a CString?
>>>
>> Joseph M. Newcomer [MVP]
>> email: newcomer(a)flounder.com
>> Web: http://www.flounder.com
>> MVP Tips: http://www.flounder.com/mvp_tips.htm
>
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm