原文链接 http://blog.sina.com.cn/s/blog_590be5290100euaq.html
CString转化为CByteArray:
CString str="我的世界 abcdefg";
CByteArray ba;
int nSize = str.GetLength() * sizeof(CHAR);
ba.SetSize(nSize);
lstrcpy((LPTSTR)ba.GetData(),str);
或
CString str="我的世界 abcdefg";
CByteArray ba;
int nSize = str.GetLength() * sizeof(CHAR);ba.SetSize(nSize+1);
memcpy( ba.GetData(), str.GetBuffer(10), nSize );
str.ReleaseBuffer();
再将CByteArray转化为CString:
CString str2('x',nSize);
for(int i=0;i<nSize;i++)
str2.SetAt(i,ba.GetAt(i));
或
CString str2;
char ch;
for(int i=0;i<nSize;i++)
{
ch=ba[i];
str2+=ch;
}