Inflates compressed data using the ZLIB uncompress algorithm.
Public Declare Function ZLIB_Inflate Lib "diCryptoSys.dll"
(ByRef lpOutput As Byte, ByVal nOutBytes As Long,
ByRef lpInput As Byte, ByVal nInputLen As Long) As Long
nRet = ZLIB_Inflate(lpOutput(0), nOutBytes, abInput(0), nInputLen)
' Note the "(0)" after the byte array parameters
long __stdcall ZLIB_Inflate(unsigned char *lpOutput, long nOutBytes, const unsigned char *lpInput, long nBytes);
The number of bytes successfully copied into the output buffer or the required size in bytes. If an error occurs, it returns a negative error code.
Public Function zlibInflate
(lpInput() As Byte) As Byte()
Zlib.Inflate Method (Byte[])
Zlib.Inflate Method (Byte[], Int32)
[New in v5.3] This function will now compute the required output length for the output buffer. In earlier versions you needed to know the size by other means.
To determine the required size of the output buffer, call the function with nOutBytes set to zero (or lpOutput set to NULL).
See ZLIB_Deflate
.
Dim strPlain As String
Dim lpToCompress() As Byte
Dim lpCompressed() As Byte
Dim lpUncompressed() As Byte
strPlain = "hello, hello, hello. This is a 'hello world' message " & _
"for the world, repeat, for the world."
lpToCompress = StrConv(strPlain, vbFromUnicode)
lpCompressed = zlibDeflate(lpToCompress)
Debug.Print "OK= " & "789CCB48CDC9C9D751C840A2F4144232328B15802851411D2CA2509E5F9493A2AE909B5A5C9C989EAA90965FA45092910A11D651284A2D484D2CD14115D6030086D11F4E"
Debug.Print "COMPRESSED=" & cnvHexStrFromBytes(lpCompressed)
lpUncompressed = zlibInflate(lpCompressed)
Debug.Print "'" & StrConv(lpUncompressed, vbUnicode); "'"