16进制的CString字符串怎么转成16进制char数组

16进制的CString字符串如何转成16进制char数组
如CString数据"5A 4C 18 00 00 00 3D 00 "
如何使输出为char ptr[]="0X5A,0x4C,0X18.....";
如何实现,跪求高手解答!

------解决方案--------------------
C/C++ code
    CString strText(_T("5A 4C 18 00 00 00 3D 00"));
    strText = _T("0x") + strText;
    strText.Replace(_T(" "), _T(",0x"));
    char* buf = NULL;
#ifdef UNICODE
    int nLen = WideCharToMultiByte(CP_ACP, 0, strText, -1, buf, 0, NULL, NULL);
    buf = new char[nLen];
    memset(buf, 0, sizeof(char) * nLen);
    WideCharToMultiByte(CP_ACP, 0, strText, -1, buf, nLen, NULL, NULL);
#else
    int nLen = strText.GetLength() + 1;
    buf = new char[nLen];
    memset(buf, 0, sizeof(char*) * nLen);
    sprintf(buf, "%s", strText);
#endif
    // ...
    delete[] buf;
    buf = NULL;

------解决方案--------------------
CString str = "5A 4C 18 00 00 00 3D 00 " ;
int val[8] ; 
sscanf(str , "%X %X %X %X %X %X %X %X" , &val[0], &val[1], &val[2], &val[3], &val[4], &val[5], &val[6], &val[7] );
char ptr[8]; 
for(int i = 0 ; i < 8 ; i++)
ptr[i] = val[i] ;
------解决方案--------------------
CString str;
(char *)(LPCTSTR)str
------解决方案--------------------
memset(buf, 0, sizeof(char*) * nLen);
-->
memset(buf, 0, sizeof(char) * nLen);

Sorry,这里写错了~
------解决方案--------------------
C/C++ code

  {
    CString srcStr = _T("5A 4C 18 00 00 00 3D 00 ");
    INT_PTR iLen = (srcStr.GetLength()+2)/3;
    BYTE *pByte = new BYTE[iLen];

    int iPos=0, iStart = 0;
    while(1)
    {
      CString strToken = srcStr.Tokenize(_T(" "), iStart);
      if(strToken.IsEmpty())
        break;
      pByte[iPos++] = (BYTE)_tcstol(strToken, NULL, 16);
    }

    //……

    delete []pByte;
  }