Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1406
  • Last Modified:

How to Convert CString to BYTE

HI can anyone show me how to convert a CString to a BYTE array. This a a small bit of code I am using to pass a string from a textbox to a CString but I need to convert the CString to a BYTE array

CString ss = "123ABC";
BYTE* bp = (BYTE*)ss.GetBuffer(ss.GetLength());

BYTE expected[16] = bp; //"This is a test";

My code works with the string "This is a test" but I need to pass the string from a textbox I know how to pass from the textbox to a CString but cant get the conversion from CString to BYTE array.

Thanks
Nigel
0
nchannon
Asked:
nchannon
2 Solutions
 
jkrCommented:
You should rather use

CString ss = "123ABC";
BYTE* bp = (BYTE*)ss.GetBuffer(ss.GetLength());

BYTE expected[16] ;

CopyMemory(expected,bp,sizeof(expected));

Just using '=' won't work.
0
 
Raj_KauCommented:
use this


      CString strtrest = "123ABC";
      BYTE *bptr = (unsigned char*)strtrest.GetBuffer(0);


Raj
0
 
nchannonAuthor Commented:
Thanks  both solutions worked great
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now