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,szMyS tring);
}
Any ideas?
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,szMyS
}
Any ideas?
ASKER
how does using a CString += operator help me? I'm trying to create a byte array.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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!
i knew it would something simple.
thnx!
You're welcome...
m...
About my points?
About my points?
Avoid using strcat, use a temporary CString and += operator, to avoid problems with unicode and multibyte.