Solved

How to Convert CString to BYTE

Posted on 2006-06-24
3
1,159 Views
Last Modified: 2013-11-20
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
Comment
Question by:nchannon
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 63 total points
ID: 16977196
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
 
LVL 3

Assisted Solution

by:Raj_Kau
Raj_Kau earned 62 total points
ID: 16981407
use this


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


Raj
0
 

Author Comment

by:nchannon
ID: 16982473
Thanks  both solutions worked great
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Show shut-down message as Windows 8 shuts down. 9 106
ASCII Non-Printable characters/codes and their HTML equivalents 6 143
canBalance challenge 34 105
changeXy challenge 13 93
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question