bool CSimpleZip::Add( const void* src, const unsigned int& srcSize, void* dst, unsigned int& dstSize, std::string& szErrmsg) { if ( NULL==src ) { szErrmsg = "CSimpleZip: Invalid source."; return false; } bool bRet = false; CZipMemFile mfIn; CZipMemFile mfOut; CZipArchive zip; try { mfIn.Write(src, srcSize); zip.Open(mfOut, CZipArchive::zipCreate); zip.AddNewFile(mfIn, _T("temp.txt")); zip.Close(); int nLen = (int)mfOut.GetLength(); if ( NULL==dst || dstSize<nLen ) { dstSize = nLen; szErrmsg = "CSimpleZip: The size of destination buffer is too small."; return false; } BYTE* b = mfOut.Detach(); memcpy_s(dst, dstSize, b, nLen); dstSize = nLen; free(b); bRet = true; } catch(CZipException& e) { if (!zip.IsClosed()) zip.Close(); szErrmsg = e.GetErrorDescription().c_str(); } catch(...) { if (!zip.IsClosed()) zip.Close(); szErrmsg = "CSimpleZip: failed to add, catch exception."; } return bRet; }