Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC8.0
How to convert BYTE* to CString? I will be very thankful to you...
Posted 21-Apr-11 2:18am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

My C++ foo is old and long unused, but this might work:
 
BYTE* buffer;
CString sStr((char*)buffer);
// or for unicode:
CString str((const wchar_t*)buffer);
 
You could have easily found this with google.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

What is BYTE* pointing to???
 
If it is pointing to standart string use:
BYTE* pbBuffer;
// pbBuffer initialization ...
// ...
CString sStr((char*)pbBuffer);
// sStr inculdes string pointed by pbBuffer
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

What do you need to do?
If pointer should be in the string like 0x0000ffff then use function Format.
CString local_string;
BYTE *local_pointer = (BYTE *)&local_string;
local_string.Format("%x",local_pointer);
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Others have shown you how to convert it to a string assuming the byte* is a pointer to a character array. Here's an alternate answer where I assume that you want a string of the actual bytes the pointer is pointing to.
 
int len = 4;
BYTE* pBytes = bytes;
CString byteString;
 
for(int i=0; i<len; i++)
{
    byteString.Format(L"%s %02x", byteString, *(pBytes + i));
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

BYTE x[5]; x[0] = 'A'; x[1] = 'B'; x[2] = 'C'; x[3] = 'D'; x[4] = '0';
 
CString str = TEXT("");
CString s;
for(int i=0;i<5;i++)
{
str.Format(L"%C",x[i]);
s += str;
}
 
AfxMessageBox(s);
  Permalink  
Comments
CHill60 at 29-May-14 10:41am
   
You are 3 years late with this unformatted response

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 520
1 Mathew Soji 335
2 BillWoodruff 260
3 OriginalGriff 215
4 Afzaal Ahmad Zeeshan 188
0 OriginalGriff 6,168
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,028
3 Manas Bhardwaj 4,539
4 Maciej Los 3,845


Advertise | Privacy | Mobile
Web03 | 2.8.1411019.1 | Last Updated 30 May 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100