Solved

How to Convert CString to BYTE

Posted on 2006-06-24
3
1,087 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need to retreive data from .TFS file exported by DVR 8 195
Running shell command from Access 3 72
wait notify demo infinite loop 3 110
wordcount challenge 11 121
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

786 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