If you are creating a new archive, the memory file will hold the resulting archive.
CZipMemFile mf;
CZipArchive zip;
zip.Open(mf, CZipArchive::zipCreate);
zip.AddNewFile(_T("C:\\Temp\\file.dat"));
zip.Close();
CZipFile f;
if (f.Open(_T("C:\\Temp\\test.zip"),
CZipFile::modeWrite | CZipFile::modeCreate, false))
{
int iLen = (int)mf.GetLength();
BYTE* b = mf.Detach();
f.Write(b, iLen);
f.Close();
free(b);
}
If you are opening an existing archive, the memory file should already hold an archive.
CZipFile f;
if (f.Open(_T("C:\\Temp\\test.zip"), CZipFile::modeRead, false))
{
int iLen = (int)f.GetLength();
BYTE* b = (BYTE*)malloc((UINT)iLen);
f.Read(b, iLen);
f.Close();
CZipMemFile mf;
mf.Attach(b, iLen);
CZipArchive zip;
zip.Open(mf);
zip.ExtractFile(0, _T("C:\\Temp"));
zip.Close();
}
LPCTSTR zipFileName = _T("C:\\Temp\\test.zip");
CZipArchive zip;
zip.Open(zipFileName, CZipArchive::zipCreate);
CZipMemFile mf;
LPCTSTR data1 = _T("Test data");
mf.Write(data1, (DWORD)(_tcslen(data1) * sizeof(TCHAR)));
zip.AddNewFile(mf, _T("file1.txt"));
zip.Close();
zip.Open(zipFileName);
CZipMemFile mfOut;
mfOut.SetLength(zip[0]->m_uUncomprSize);
((CZipAbstractFile*)&mfOut)->SeekToBegin();
zip.ExtractFile(0, mfOut);
zip.Close();
BYTE* b = mfOut.Detach();
_tprintf((LPCTSTR)b);
free(b);