Solved

How to Convert CString to BYTE

Posted on 2006-06-24
3
988 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
Comment Utility
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
Comment Utility
use this


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


Raj
0
 

Author Comment

by:nchannon
Comment Utility
Thanks  both solutions worked great
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Decoding 32 bit binary streams 6 29
Replacement selected text 2 47
Window placement 17 64
mapBully challenge 6 88
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now