Base64Encode

CString CUpLoadData::_Base64EncodeEx(const CStringA& strData)
{
std::string strA = CA2A(strData, CP_UTF8); //一定一定要记得这一步!之前改的时候把这一句删了,编译运行不报错,但是结果一直有错误。。。
int nLenIn = strA.size();
int nLenOut = strA.size() * 2;
char* pData = new char[nLenOut];
ZeroMemory(pData, nLenOut );

ATL::Base64Encode((BYTE *)(strA.c_str()), nLenIn, pData, &nLenOut);

CString strOut(pData);

int n = strOut.Find('\r');
while (n != -1)         //删除strOut在构造之后出现的几个\r\n
{
    strOut.Delete(n,2);
    n = strOut.Find('\r');  //如果找不到,返回-1
}

if (pData != NULL)
{
    delete[] pData;
    pData = NULL;
}
Debug_View(DEF_UPLOAD_DATA,L"Base64之后的结果:%s",strOut.GetBuffer(strOut.GetLength()));
return strOut;

}

你可能感兴趣的:(Base64Encode)