VC2005下CString.Format问题!!

来源:百度知道 编辑:UC知道 时间:2024/05/24 12:49:57
//Store final state in 'lpszMD5'
const int nMD5Size = 16;
unsigned char lpszMD5[ nMD5Size ];
DWordToByte( lpszMD5, m_lMD5, nMD5Size );

//Convert the hexadecimal checksum to a CString
CString strMD5;
for ( int i=0; i < nMD5Size; i++)
{
CString Str;
if (lpszMD5[i] == 0) {
Str = CString("00");
}
else if (lpszMD5[i] <= 15) {
Str.Format("0%x",lpszMD5[i]);←在VC2005下编译不过去
}
else {
Str.Format("%x",lpszMD5[i]);←这个也是
}
ASSERT( Str.GetLength() == 2 );
strMD5 += Str;
}

这是网上下载的MD5加密算法源码 VC2005下编译不过 请问怎么改啊?

VS2005默认使用了UNICODE双字节的字符串,需要使用_T把显式定义的字符串扩起来或者在工程设置中将其改成ANSI。
如:Str.Format(_T("0%x"),...);
如果确定不需要使用双字节,在使用CString时可以指定CStringA。
如: CStringA Str;

强制转换应该是可以的

改成这样就可以了
Str.Format(L"0%x",lpszMD5[i]);