troubleshooting Question

CString w/ hex values > byte array

Avatar of howardsd
howardsd asked on
C++System Programming
6 Comments1 Solution1736 ViewsLast Modified:
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?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros