Link to home
Start Free TrialLog in
Avatar of howardsd
howardsd

asked on

CString w/ hex values > byte array

I have a CString with hex values "0122C24D".  I need to create a byte array where each index of the array corresponds to each of the 2 respective hex characters in the CString.

arr[0]=0x01
arr[1]=0x22
arr[2]=0xC2
arr[3]=0x4D

So far I have the code below, but blows up on the strcat_s.

char *szMyString = NULL;
char szWrite[512];
CString cs = "0122C24D", tmp;

for(int i=0; i<cs.GetLength(); i+=2)
{
    tmp = cs.Mid(i,2);
    szMyString = (char*) (LPCTSTR) tmp;
    strcat_s(szWrite,512,szMyString);
}

Any ideas?
Avatar of anmalaver
anmalaver

Hi

Avoid using strcat, use a temporary CString and += operator, to avoid problems with unicode and multibyte.
Avatar of howardsd

ASKER

how does using a CString += operator help me?  I'm trying to create a byte array.
ASKER CERTIFIED SOLUTION
Avatar of anmalaver
anmalaver

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
had to change the szWrite to a BYTE array rather than a char array.  but after that, it works like a charm.

i knew it would something simple.

thnx!
You're welcome...
m...
About my points?