Login  
Search All Forums
Dart Home | PowerTCP Zip Compression for Active | Custom Development Reply | PowerTCP Zip Compression for ActiveX Topics | Forums   
AuthorForum: PowerTCP Zip Compression for ActiveX
Topic: Add Stream to Zip file using VC++
dannywatkins

From: bristol, United Kingdom
Posts: 3
Member Since: 06/11/02
posted June 11, 2002 2:05 AM

Could you give tell me where to find some sample code in VC++ for adding a stream to a file store please?

I currently have the following :

DartZip::IDartStreamPtr Stream;
Stream.CreateInstance(DartZip::CLSID_DartStream);

VARIANT v;
VariantInit(&v);
v.vt = VT_BYREF|VT_UI1;
v.pbVal = pData;
nLength = Stream->Write(v, nLength);

pZip->FileStore->Add(Stream, FALSE, FALSE, _bstr_t(""), DartZip::zipNoEncryption);

But this causes a compile error on parameter 1 of the Add operation.

Secondly, how can I set the name of the stream I've just added, as I understand it will be automatically named StreamN?

Thanks.

Danny
dannywatkins

From: bristol, United Kingdom
Posts: 3
Member Since: 06/11/02
posted June 11, 2002 4:46 AM

Sorted.
I found most of the code I was looking for in another post, plus the easy bit at the bottom. I've posted the complete function so the next person can find the solution more easily.

The solution assumes that CMainFrame is derived from IZip as suggested by the VC++ samples.

BOOL CMainFrame::AddStreamToZip(LPCTSTR sName, BYTE * pData , long nLength)
{
try
{
DartZip::IDartStreamPtr Stream;
Stream.CreateInstance(DartZip::CLSID_DartStream);

// Create safearray
SAFEARRAYBOUND rgsabound[1];
rgsabound[0].cElements = nLength;
rgsabound[0].lLbound = 1;

// Create an OLE SAFEARRAY
SAFEARRAY *array;
array = SafeArrayCreate(VT_UI1,1,rgsabound);

// Load aray
VARIANT var;
if(array != NULL)
{
if (pData != NULL)
{
void * pArrayData = NULL;
SafeArrayAccessData(array,&pArrayData);
memcpy(pArrayData, pData, nLength);
SafeArrayUnaccessData(array);
}
var.vt = VT_UI1 | VT_ARRAY;
var.parray = array;
}
else
{
var.vt = VT_NULL;
var.parray = NULL;
}

// Load buffer into stream
Stream->Write(var,nLength);

// Load stream into Zip Control
VARIANT srcData;
srcData.vt = VT_DISPATCH;
srcData.punkVal= Stream;
pZip->FileStore->Add(srcData,FALSE,FALSE,_bstr_t(""),DartZip::zipNoEncryption);

// Clean memory
if (array)
SafeArrayDestroy(array);


// Set the name of the stream. This is done by getting the last file in the
// archive.
long nFiles = pZip->FileStore->Count;
DartZip::IFilePtr File;
File = pZip->FileStore->Item(nFiles);
File->Name = sName;

// Zip the archive to disk.
pZip->FileStore->Zip(_bstr_t(m_strZipfilename),NULL);

}
  catch(_com_error e)
  {
    ShowZipErrorMessage((DartZip::ZipErrorConstants)e.HelpContext(), (char *)e.Description());
return FALSE;
  }

return TRUE;
}

Reply | PowerTCP Zip Compression for ActiveX Topics | Forums   
This site is powered by PowerTCP WebServer Tool PowerTCP WebServer for ActiveX