Solved

How to Convert CString to BYTE

Posted on 2006-06-24
3
1,237 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
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.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

695 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