Click here to Skip to main content
13,052,342 members (57,593 online)
Click here to Skip to main content
Add your own
alternative version


23 bookmarked
Posted 31 May 2003

MS-Cabinet File WrapperClasses

, 31 May 2003
Rate this:
Please Sign up or sign in to vote.
Two classes using cabinet.dll to create or extract from MS-Cabinet Files
<!-- Add the rest of your HTML here -->


Apologies in advance about my English and the brief descriptions, as my native language is German.

Two classes to wrap compression / extraction with cabinet.dll.  It will not allow add files to, remove files from or modify Cabinets.

Using the code

Class TCompress

The main Functions :

<PRE lang=c++>tCreateError Create (PCHAR CabFile,PCHAR Path,ULONG Size = CAB_MAXDISK)

Initialize a TCompressObject.CabFile is the name for the (first) Cabinet.  If the file(s) exists it will be overwritten Path is the directory to store the Cabinet.  Size is the maximum size for a single Cabinet file.

<PRE lang=c++>BOOL Add (const PCHAR File,BOOL bExec = false)

Add File to the Cabinet. Set bExec true when the file should be executed after the extraction. A application must detect this flag and execute the file.

<PRE lang=c++>BOOL Store (void);

Store the Cabinet to disk.

<PRE lang=c++>void Destroy (void);

Free resources allocated by Create().

The simplest way to use :

<PRE lang=c++>#include "TCompress.hpp" class cMyCompress : TCompress { friend void main (void); }; void main (void) { cMyCompress *cmp = new cMyCompress(); if (cmp->Create("","c:\\compressed") == errSuccess) { cmp->Add ("AnyFileThatShouldExists.001"); cmp->Add ("AnyFileThatShouldExists.002"); cmp->Add ("AnyFileThatShouldExists.003"); cmp->Store (); cmp->Destroy (); } delete cmp; }

Control TCompress :

<PRE lang=c++>void SetCompression (bool b)

Turn compression on/off.

<PRE lang=c++>void SetStoredPath (tStoredPath sp)

Set how the path for files should be stored in Cabinet.

Control TCompress more :

<PRE lang=c++>virtual void CBOpenInfo (const PCHAR File,FILETIME *Time,USHORT &Attrib)

Called to allow set Time and Attributes stored in cabinet for File.

<PRE lang=c++>virtual void CBTempName (PCHAR szTemp,int nTemp)

Called when the path for temporary files is needed.

<PRE lang=c++>virtual void CBCabName (tCabName NextCabName,INT Count)

Called when the name for the next Cabinetfile in a set is needed.

<PRE lang=c++>virtual void CBDiskName (tCabDisk NextDiskName,INT Count)

Called when the name for the next disk (stored in Cabinet to prompt the user) is needed.

Feedback on various points at work :

<PRE lang=c++>virtual void CBReplaced (const PCHAR File,BOOL IsContinued) virtual void CBFile (const tcFileStatus &Status) virtual void CBFolder (tcFolderStatus s,USELESS ul1,USELESS ul2) virtual void CBCabinet (ULONG CabinetSizeWritten)

Class TExpand

The main functions :

<PRE lang=c++>tCreateError Create (PCHAR CabFile,PCHAR BasePath = NULL)

Initialize a TExpandObject. CabFile is the name of the Cabinet. BasePath is the directory to store the extracted files. Default is the SystemTempDirectory.

<PRE lang=c++>BOOL Copy (void)

Start extraction.

<PRE lang=c++> void Destroy (void)

Free resources allocated by Create().

The simplest way to use :

<PRE lang=c++>#include "TExpand.hpp" class cMyExpand : TExpand { friend void main (void); }; void main (void) { cMyExpand *exp = new cMyExpand(); if (exp->Create ("c:\\compressed\\") == errSuccess) { exp->Copy (); exp->Destroy (); } delete exp; }

Control TExpand :

<PRE lang=c++>void SetExpandStoredPath(tStoredPath s)

Set how the path stored in Cabinet should be restored.

<PRE lang=c++>void SetSubsequent (bool e)

Set / unset Continuation on subsequent Cabinets in a set.

<PRE lang=c++>bool GetCurrentFile (PCHAR File,UINT nFile)

Copy the name from the current extracted File to File.

<PRE lang=c++>bool HasIncomplete (PCHAR File,UINT nFile)

When Copy() fails check for incomplete files continued in a not available Cabinet

<PRE lang=c++>bool GetFirstCab (PCHAR AnyCabinet,tPath FirstCabinet)

Get the first Cabinet from a set of Cabinet files beginning from any Cabinet in this set.

<PRE lang=c++>bool CreatePath (tConstPath Path)

Create the full path pointed by Path.

<PRE lang=c++>bool FileAvaliable (tConstPath Path)

Try to open the file pointed by Path for reading.

<PRE lang=c++>bool DirectoryExists (tConstPath Path)

Look for the directory pointed by Path.

Control TExpand more :

<PRE lang=c++>virtual void CBCloseInfo (const PCHAR FileName_OnDisk, USHORT FileTime_ToSet, USHORT FileDate_ToSet, USHORT FileAttribute_ToSet)

Called to set date, time and attributes for the file extracted to disk.

<PRE lang=c++>virtual bool CBCopyFile ( tPath FileName, LONG UncompressedSize, SYSTEMTIME SysTime_InCab, USHORT Attribs_InCab, bool &Error)

Called to ask for extract the File named FileName. You should look for available space on disk and you can modify the FileName here. Return false to skip the File. If Error not eeNone a previous extraction has failed. In this case set Error to eeNone and return false to continue extraction with the next file, otherwise Copy() terminates immediately.

<PRE lang=c++>virtual void CBNextCabinet(const PCHAR CabFile_Needed, const PCHAR Disk_Needed, tCabPath CabinetPath, teError &Error)

A continued file should be extracted and the Cabinet is not available. Prompt user for the disk named Disk_Needed or set CabinetPath to point on CabFile_Needed. If it called with Error not eeNone a previous call has failed. Set Error to eeNone and try again or leave Error in this case Copy() terminates immediately.

Feedback on various points at work :

<PRE lang=c++>virtual void CBProgress (void)

Points of Interest

Additional information about the FDI/FCI interface :

Download cabsdk.exe for documents that describe the internal structures of CabinetFiles, samples to use from C and a description of cabinet.dll.


  • June 1st, 2003: Initial release.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Stefan Voitel
Germany Germany
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralA better solution Pin
Elmue26-Jul-06 3:47
memberElmue26-Jul-06 3:47 
GeneralRe: A better solution Pin
.dan.g.25-Jun-08 14:10
member.dan.g.25-Jun-08 14:10 
GeneralRe: A better solution Pin
Elmue30-Jun-08 6:55
memberElmue30-Jun-08 6:55 
GeneralRe: A better solution Pin
mirik12320-Nov-11 5:28
membermirik12320-Nov-11 5:28 
GeneralRe: A better solution Pin
Elmue22-Nov-11 3:38
memberElmue22-Nov-11 3:38 or version? Pin
chenhuisheng23-Mar-04 20:26
memberchenhuisheng23-Mar-04 20:26 
AnswerRe: .net(c# or version? Pin
Stefan Voitel24-Mar-04 0:54
memberStefan Voitel24-Mar-04 0:54 
GeneralRe: .net(c# or version? Pin
J.B16-Aug-04 14:12
memberJ.B16-Aug-04 14:12 
GeneralRe: .net(c# or version? Pin
steven Deng19-Jan-05 9:55
susssteven Deng19-Jan-05 9:55 
GeneralRe: .net(c# or version? Pin
sd_alberta20-Jan-05 8:03
membersd_alberta20-Jan-05 8:03 
GeneralRe: .net(c# or version? Pin
Elmue31-Aug-06 0:41
memberElmue31-Aug-06 0:41 
AnswerRe: .net(c# or version? Pin
Elmue31-Aug-06 0:41
memberElmue31-Aug-06 0:41 
GeneralAccessing Folders in MFC Pin
vgandhi13-Jun-03 8:33
membervgandhi13-Jun-03 8:33 
QuestionHow to digitally sign cab from code ??? Pin
AntonS1-Jun-03 21:41
memberAntonS1-Jun-03 21:41 
AnswerRe: How to digitally sign cab from code ??? Pin
Stefan Voitel3-Jun-03 8:32
sussStefan Voitel3-Jun-03 8:32 
QuestionHow to extract from .MSI? Pin
harinath1-Jun-03 18:48
memberharinath1-Jun-03 18:48 
AnswerRe: How to extract from .MSI? Pin
Stefan Voitel3-Jun-03 8:39
sussStefan Voitel3-Jun-03 8:39 
GeneralRe: How to extract from .MSI? Pin
Anonymous8-Feb-04 6:50
sussAnonymous8-Feb-04 6:50 
AnswerRe: How to extract from .MSI? Pin
Matteo Mike Peluso27-Sep-05 8:34
memberMatteo Mike Peluso27-Sep-05 8:34 
AnswerRe: How to extract from .MSI? Pin
Ellery Pierce7-Aug-06 22:43
memberEllery Pierce7-Aug-06 22:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170713.1 | Last Updated 1 Jun 2003
Article Copyright 2003 by Stefan Voitel
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid