This is
a very simple library that wraps the built-in Windows ability to create and extract
cab files with the ZLIB library's ability to create & extract zip files.
The library contains 18 simple functions and has been
tested on all 32-bit windows platforms.
'===============================================================
'Function: CabAbout()
'Variables: None
'Return:
' Returns
' About String -- Credits for the Library
'===============================================================
Declare Function
CabAbout Lib
"cab10.dll"
Alias _
"CABABOUT" ()
As String
'===============================================================
'Function: CabCompressInitilize()
'Variables: None
'Return:
' Returns
' 0 -- failed
' 1 -- success
'===============================================================
Declare Function CabCompressInitialize Lib
"cab10.dll"
Alias _
"CABCOMPRESSINITIALIZE" ()
As Long
'===============================================================
'Function: CabDecompressInitialize()
'Variables: none
'Return:
' 0 -- fail
' 1 -- success
'===============================================================
Declare Function CabDecompressInitialize Lib
_
"cab10.dll"
Alias "CABDECOMPRESSINITIALIZE"
()
As Long
'================================================================
'Function: CabCreate
'Description: This function creates the physical cab file.
Usage would be the following
' IF CabCreate("c:\cabtest.cab")
then ..... End if
' NOTE: To use this function, you must first call
CabCompressInitialize
'Variables:
' sSource: String
'Return:
' Returns
' 0 -- fail
' filehandle -- successful (greater then 0)
'================================================================
Declare Function CabCreate Lib
"cab10.dll"
Alias "CABCREATE" _
(byval sSource as string) As Long
'================================================================
'Function: CabAddFile
'Description: This is the function that one uses to add files to a
Cab file.
'Usage: If CabAddFile(hCabFile, "c:\test.txt",
"c:\renamed.txt")
then ....
'NOTE: This function requires that you first call
CabCompressInitialize
'Variables:
'hCabFile -- This is the file handle returned by CabCreate
'sSource -- This is the full path to a file to add (NOTE: this must
be a file path, not a
'
directory.
'sRename -- This will rename the source file to the name provided
(must include full path)
'Return:
' 0 -- fail
' 1 -- succeeded
'================================================================
Declare Function CabAddFile Lib
"cab10.dll"
Alias "CABADDFILE" _
(byval hCabFile as long, byval sSource as string, byval sRename as
string) As Long
'===================================================================
'Function: CabClose
'Description: Closes the CabFile Opened by CabCreate.
'NOTE: This function requires that you first call
CabCompressInitialize
'Variables:
' hCabFile -- File Handle returned by CabCreate
'Returns:
' 0 -- failed
' 1 -- succeeded
'===================================================================
Declare Function CabClose Lib
"cab10.dll"
Alias "CABCLOSE" _
(ByVal hCabFile As
Long) As Long
'=================================================================
'Function: CabEnum
'Description: Will return a tab delimited list of files currently in
a cab file.
'NOTE: This function requires that you first call
CabDecompressInitialize
'Variables:
' sSource -- Full path to the Cab file
'Returns:
' empty -- Failed
' string -- succeeded
'==================================================================
Declare Function CabEnum Lib
"cab10.dll"
Alias "CABENUM" _
(ByVal sSource as String) As
String
'=================================================================
'Function: CabExtract
'Description: Extracts the contexts of a cab to a specified
folder
'NOTE: This function requires that you first call
CabDecompressInitialize
'Variables:
' sSource -- This is the full path to a cab file
' sDestDir -- This is a destination directory (note, directory will
be created if it doesn't
'
exist.
'Returns:
' 0 -- failed
' 1 -- successful
'==================================================================
Declare Function CabExtract Lib
"cab10.dll"
Alias "CABEXTRACT" _
(ByVal sSource as STRING, byval
sDestDir as STRING) _
As Long
'===================================================================
'Function: CabCompressTerminate
'Description: This must be called to clean up allocated memory if
the
'
CabCompressInitialized function has been called. Note calling
this function
'
may cause a General Protection Fault.
'Variables: none
'Returns:
' 0 -- failed
' 1 -- successful
'====================================================================
Declare Function CabCompressTerminate Lib
_
"cab10.dll"
Alias
"CABCOMPRESSTERMINATE" ()
As Long
'===================================================================
'Function: CabDecompressTerminate
'Description: This must be called to clean up allocated memory if
the
'
CabDecompressInitialized function has been called. Note
calling this function
'
may cause a General Protection Fault.
'Variables: none
'Returns:
' 0 -- failed
' 1 -- successful
'====================================================================
Declare Function CabDecompressTerminate Lib
_
"cab10.dll"
Alias
"CABDECOMPRESSTERMINATE"
()
As Long
'===================================================================
'Function: ZLIB_Initialize
'Description: This must be called to initialize the ZLIB functions.
'Variables: none
'Returns:
' 0 -- failed
' 1>= -- succeeded
'====================================================================
Declare Function ZLIB_Initialize Lib
_
"cab10.dll"
Alias
"ZLIB_INITIALIZE"
()
As Long
'===================================================================
'Function: ZLIB_CompressString
'Description: Compresses A string using the ZLIB Compression
Standard -- Note, this
' function, and the decompression function use an algorithem to
remove null characters
' from the return string to ease use by c style programming
languages if flag is set to 1.
'NOTE: This function requires that you first call ZLIB_Initialize
'Variables:
' pString -- Pointer to the String path
' strlen -- length of pString
' flag -- This flag will activate an algorithem to strip null
characters
' 0 -- keep null characters
' 1 -- remove null characters
'Returns:
' string -- if string is numeric, then the function
failed (numeric equals error)
'====================================================================
Declare Function ZLIB_CompressString Lib
_
"cab10.dll"
Alias
"ZLIB_COMPRESSSTRING" (byval pString as long, _
byval strlen as long, byval flag as long)
As string
'===================================================================
'Function: ZLIB_DecompressString
'Description: Decompresses A string using the ZLIB decompression
Standard --
'Note, this
' function, and the decompression function use an algorithem to
remove null characters
' from the return string to ease use by c style programming
languages if flag is set to 1.
'NOTE: This function requires that you first call ZLIB_Initialize
'Variables:
' pString -- Pointer to a string holding file path
' strlen -- length of the string referenced to pString
' originalsize -- Original size (about) of the Compressed
string
' flag -- Tells program is null characters were allowed or
removed.
' 0 -- null characters were kept
' 1 -- null characters were removed.
'Returns:
' string -- if string is numeric, then the function
failed (numeric equals error)
'====================================================================
Declare Function ZLIB_DecompressString Lib
_
"cab10.dll"
Alias
"ZLIB_DECOMPRESSSTRING" (byval pString as long, _
byval strlen as long, byval originalsize as long, byval flag
as long)
As string
'===================================================================
'Function: ZLIB_AddToZip
'Description: Adds file to a new ZIP (if zip exists, it will be
overwritten
'Useage: ZLIB_ADDTOZIP "c:\testfile.txt",
"c:\testzip.zip"
'NOTE: This function requires that you first call ZLIB_Initialize
'Variables:
' source -- File to be added to the zip (full path)
' zipfile -- Zip file
'Returns:
' 0 -- Succeeds
' >< -- failed
'====================================================================
Declare Function ZLIB_AddToZip Lib
_
"cab10.dll"
Alias
"ZLIB_ADDTOZIP" (byval source as string, _
byval zipfile as string)
As Long
'===================================================================
'Function: ZLIB_AddToZipEx
'Description: Adds a file either to an existing zip or a new zip.
'Useage: ZLIB_ADDTOZIPEX "c:\testfile.txt",
"c:\testzip.zip", 0
'NOTE: This function requires that you first call ZLIB_Initialize
'Variables:
' source -- file to be added to a zip (full path)
' zipfile -- Zip file to be created/added to
' dflag --
' Flag can be one of the
following:
'
0 -- Default
'
&h0001 -- Save path (will save the file structure in zip)
'
&h0002 -- Close the Zip after adding the file
'Returns:
' 0 -- Succeeds
' >< -- failed
'====================================================================
Declare Function ZLIB_AddToZipEx Lib
_
"cab10.dll"
Alias
"ZLIB_ADDTOZIPEx" (byval source as string, _
byval zipfile as string, byval dflag as Dword)
As Long
'===================================================================
'Function: ZLIB_Close
'Description: Closes the Zip File
'NOTE: This function requires that you first call ZLIB_Initialize
'Variables: none
'Returns:
' 0 -- Succeeds
' >< -- failed
'====================================================================
Declare Function ZLIB_Close Lib
_
"cab10.dll"
Alias
"ZLIB_CLOSE" ()
As Long
'===================================================================
'Function: ZLIB_Terminate
'Description: Unloads the Zlib functions from memory
'NOTE: This function requires that you first call ZLIB_Initialize
'Variables: none
'Returns:
' 0 -- failed
' 1 -- failed
'====================================================================
Declare Function ZLIB_Terminate Lib
_
"cab10.dll"
Alias
"ZLIB_TERMINATE" ()
As Long
Examples:
I've
created two examples. The first example, vbCab,
is a program written 4 VB 6 that illustrates a number of the above
commands. The second example, iba_cab.zip
is a program wirtten 4 IBASIC
that illustrates how to compress files into a cab.
Header
Files: