该函数在偶的手机程序里面用过,字符串的长度就是sEncodes.GetLength() / 2(支持中英文混排)。
CString CMobile::String2HEX(CString sSource)
{
_bstr_t bstrSMS(sSource);
int nSMSLength = bstrSMS.length();
wchar_t * pwc = (wchar_t *)bstrSMS;
CString sEncode;
for(int i = 0; i < nSMSLength; i++)
{
CString sHex;
sHex.Format(_T("%04X"), pwc[i]);
sEncode += sHex;
}
return sEncode;
}