Click here to Skip to main content
15,906,341 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to convert string to BYTE array? Pin
kapardhi21-Aug-08 21:23
kapardhi21-Aug-08 21:23 
AnswerRe: How to convert string to BYTE array? Pin
SandipG 21-Aug-08 21:29
SandipG 21-Aug-08 21:29 
AnswerRe: How to convert string to BYTE array? Pin
Nibu babu thomas21-Aug-08 21:39
Nibu babu thomas21-Aug-08 21:39 
QuestionRe: How to convert string to BYTE array? Pin
CPallini21-Aug-08 21:45
mveCPallini21-Aug-08 21:45 
AnswerRe: How to convert string to BYTE array? Pin
kapardhi21-Aug-08 21:58
kapardhi21-Aug-08 21:58 
QuestionRe: How to convert string to BYTE array? Pin
CPallini21-Aug-08 22:03
mveCPallini21-Aug-08 22:03 
AnswerRe: How to convert string to BYTE array? Pin
kapardhi21-Aug-08 22:07
kapardhi21-Aug-08 22:07 
GeneralRe: How to convert string to BYTE array? Pin
Nibu babu thomas21-Aug-08 22:57
Nibu babu thomas21-Aug-08 22:57 
kapardhi wrote:
sorry i have shown in a wrong way previously i actually need in following manner
BYTE b[] = { 0xFF, 0xDA, 0x08, 0x90, 0xDA };


This function does this, do test well, you also need to handle empty string cases...

std::vector<BYTE> CStringBytes_To_RealBytes( const CString& str )
{
   const LPCTSTR pBuff = static_cast<lpctstr>( str );
   const int ByteLength = str.GetLength();

   std::vector<BYTE> Bytes;
   Bytes.reserve( ByteLength );

   for( int Index = 0; Index < ByteLength; Index+=2 )
   {
      TCHAR Temp[3] = { 0 };
      _tcsncpy_s( Temp, 3, &pBuff[Index], 2 );
      Bytes.push_back( static_cast<BYTE>( _tcstol( Temp, NULL, 16 )));
   }

   return Bytes;
}</lpctstr>


std::vector<BYTE> Bytes = CStringBytes_To_RealBytes( CString( _T( "FFDA0890DA" )));


This function assumes that two characters in the above string equals one byte.


Nibu babu thomas
Microsoft MVP for VC++


Code must be written to be read, not by the compiler, but by another human being.

Programming Blog: http://nibuthomas.wordpress.com

GeneralRe: How to convert string to BYTE array? Pin
CPallini21-Aug-08 23:02
mveCPallini21-Aug-08 23:02 
QuestionPlease Guide Connect Sqlserver with VC++6.0. thanks very much Pin
aa_zz21-Aug-08 21:05
aa_zz21-Aug-08 21:05 
AnswerRe: Please Guide Connect Sqlserver with VC++6.0. thanks very much Pin
Hamid_RT21-Aug-08 21:14
Hamid_RT21-Aug-08 21:14 
GeneralRe: Please Guide Connect Sqlserver with VC++6.0. thanks very much Pin
aa_zz21-Aug-08 21:36
aa_zz21-Aug-08 21:36 
GeneralRe: Please Guide Connect Sqlserver with VC++6.0. thanks very much Pin
Hamid_RT21-Aug-08 23:43
Hamid_RT21-Aug-08 23:43 
QuestionHow to create a 'setup' installation CD for a simple win32 C app. Pin
glyfyx21-Aug-08 21:01
glyfyx21-Aug-08 21:01 
AnswerRe: How to create a 'setup' installation CD for a simple win32 C app. Pin
Hamid_RT21-Aug-08 21:17
Hamid_RT21-Aug-08 21:17 
AnswerRe: How to create a 'setup' installation CD for a simple win32 C app. Pin
Nuri Ismail21-Aug-08 22:09
Nuri Ismail21-Aug-08 22:09 
GeneralRe: How to create a 'setup' installation CD for a simple win32 C app. Pin
Michael Schubert21-Aug-08 22:32
Michael Schubert21-Aug-08 22:32 
GeneralRe: How to create a 'setup' installation CD for a simple win32 C app. Pin
glyfyx22-Aug-08 22:26
glyfyx22-Aug-08 22:26 
GeneralRe: How to create a 'setup' installation CD for a simple win32 C app. Pin
Michael Schubert23-Aug-08 1:14
Michael Schubert23-Aug-08 1:14 
QuestionInvisible UI + background process Pin
dharani21-Aug-08 20:47
dharani21-Aug-08 20:47 
AnswerRe: Invisible UI + background process Pin
_AnsHUMAN_ 21-Aug-08 20:54
_AnsHUMAN_ 21-Aug-08 20:54 
AnswerRe: Invisible UI + background process Pin
SandipG 21-Aug-08 21:07
SandipG 21-Aug-08 21:07 
QuestionAuto number in ID field with Primary key in MS-Access !! Pin
Le@rner21-Aug-08 20:39
Le@rner21-Aug-08 20:39 
Question[Message Deleted] Pin
Dhiraj kumar Saini21-Aug-08 20:37
Dhiraj kumar Saini21-Aug-08 20:37 
AnswerRe: store LPARAM value in a char buffer of size 1000000 Pin
SandipG 21-Aug-08 20:57
SandipG 21-Aug-08 20:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.