pisky said:
Thanks Karl. This library is what I am looking for. I downloaded it but
cannot seem to get a reference to it in Excel. I tried running RegSvr32 but
get the message "zlibwapi.dll was loaded, but the DllRegisterServer entry
point was not found". What do I need to do to use the dll?
It's not based on COM. You just call it directly. Details are very C-oriented, and
can be found in the zlib.h file. Here are the VB(A) declarations for the two main
functions I've used:
Private Declare Function compress Lib "zlibwapi.dll" (dest As Any, destLen As
Any, src As Any, ByVal srcLen As Long) As Long
Private Declare Function uncompress Lib "zlibwapi.dll" (dest As Any, destLen As
Any, src As Any, ByVal srcLen As Long) As Long
Then I wrote these two functions to handle the housekeeping:
Private Function DecompressData(Data() As Byte, ByVal OriginalSize As Long) As
Long
Dim BufferSize As Long
Dim Buffer() As Byte
Dim nResult As Long
' Allocate the smallest allowed compression buffer
' (1% larger than the uncompressed data plus 12 bytes).
BufferSize = (OriginalSize * 1.01) + 12
ReDim Buffer(0 To BufferSize - 1) As Byte
' Decompress data
nResult = uncompress(Buffer(0), BufferSize, Data(LBound(Data)), UBound(Data) -
LBound(Data) + 1)
' Truncate buffer to compressed size
ReDim Data(0 To BufferSize - 1) As Byte
CopyMemory Data(0), Buffer(0), BufferSize
' Return error code (if any)
DecompressData = nResult
End Function
Public Function CompressData(Data() As Byte) As Long
Dim OriginalSize As Long
Dim BufferSize As Long
Dim Buffer() As Byte
Dim nResult As Long
' Build working buffer for ZLib must be at
' least 101% of original plus 12 bytes.
OriginalSize = (UBound(Data) - LBound(Data) + 1)
BufferSize = OriginalSize * 1.01 + 12
ReDim Buffer(0 To BufferSize - 1) As Byte
' Compress byte array (data).
nResult = compress(Buffer(0), BufferSize, Data(LBound(Data)), OriginalSize)
' Truncate original array to compressed size.
ReDim Data(0 To BufferSize - 1) As Byte
CopyMemory Data(0), Buffer(0), BufferSize
' Return error code (if any).
CompressData = nResult
End Function
It's a bit involved. As you can see, you must insure that your container's file
format is self-descriptive enough to reveal the original size of the uncompressed
data.