Chris@43: See below some functions declarations for Visual Basic. Chris@43: Chris@43: Frequently Asked Question: Chris@43: Chris@43: Q: Each time I use the compress function I get the -5 error (not enough Chris@43: room in the output buffer). Chris@43: Chris@43: A: Make sure that the length of the compressed buffer is passed by Chris@43: reference ("as any"), not by value ("as long"). Also check that Chris@43: before the call of compress this length is equal to the total size of Chris@43: the compressed buffer and not zero. Chris@43: Chris@43: Chris@43: From: "Jon Caruana" Chris@43: Subject: Re: How to port zlib declares to vb? Chris@43: Date: Mon, 28 Oct 1996 18:33:03 -0600 Chris@43: Chris@43: Got the answer! (I haven't had time to check this but it's what I got, and Chris@43: looks correct): Chris@43: Chris@43: He has the following routines working: Chris@43: compress Chris@43: uncompress Chris@43: gzopen Chris@43: gzwrite Chris@43: gzread Chris@43: gzclose Chris@43: Chris@43: Declares follow: (Quoted from Carlos Rios , in Vb4 form) Chris@43: Chris@43: #If Win16 Then 'Use Win16 calls. Chris@43: Declare Function compress Lib "ZLIB.DLL" (ByVal compr As Chris@43: String, comprLen As Any, ByVal buf As String, ByVal buflen Chris@43: As Long) As Integer Chris@43: Declare Function uncompress Lib "ZLIB.DLL" (ByVal uncompr Chris@43: As String, uncomprLen As Any, ByVal compr As String, ByVal Chris@43: lcompr As Long) As Integer Chris@43: Declare Function gzopen Lib "ZLIB.DLL" (ByVal filePath As Chris@43: String, ByVal mode As String) As Long Chris@43: Declare Function gzread Lib "ZLIB.DLL" (ByVal file As Chris@43: Long, ByVal uncompr As String, ByVal uncomprLen As Integer) Chris@43: As Integer Chris@43: Declare Function gzwrite Lib "ZLIB.DLL" (ByVal file As Chris@43: Long, ByVal uncompr As String, ByVal uncomprLen As Integer) Chris@43: As Integer Chris@43: Declare Function gzclose Lib "ZLIB.DLL" (ByVal file As Chris@43: Long) As Integer Chris@43: #Else Chris@43: Declare Function compress Lib "ZLIB32.DLL" Chris@43: (ByVal compr As String, comprLen As Any, ByVal buf As Chris@43: String, ByVal buflen As Long) As Integer Chris@43: Declare Function uncompress Lib "ZLIB32.DLL" Chris@43: (ByVal uncompr As String, uncomprLen As Any, ByVal compr As Chris@43: String, ByVal lcompr As Long) As Long Chris@43: Declare Function gzopen Lib "ZLIB32.DLL" Chris@43: (ByVal file As String, ByVal mode As String) As Long Chris@43: Declare Function gzread Lib "ZLIB32.DLL" Chris@43: (ByVal file As Long, ByVal uncompr As String, ByVal Chris@43: uncomprLen As Long) As Long Chris@43: Declare Function gzwrite Lib "ZLIB32.DLL" Chris@43: (ByVal file As Long, ByVal uncompr As String, ByVal Chris@43: uncomprLen As Long) As Long Chris@43: Declare Function gzclose Lib "ZLIB32.DLL" Chris@43: (ByVal file As Long) As Long Chris@43: #End If Chris@43: Chris@43: -Jon Caruana Chris@43: jon-net@usa.net Chris@43: Microsoft Sitebuilder Network Level 1 Member - HTML Writer's Guild Member Chris@43: Chris@43: Chris@43: Here is another example from Michael that he Chris@43: says conforms to the VB guidelines, and that solves the problem of not Chris@43: knowing the uncompressed size by storing it at the end of the file: Chris@43: Chris@43: 'Calling the functions: Chris@43: 'bracket meaning: [optional] {Range of possible values} Chris@43: 'Call subCompressFile( [, , [level of compression {1..9}]]) Chris@43: 'Call subUncompressFile() Chris@43: Chris@43: Option Explicit Chris@43: Private lngpvtPcnSml As Long 'Stores value for 'lngPercentSmaller' Chris@43: Private Const SUCCESS As Long = 0 Chris@43: Private Const strFilExt As String = ".cpr" Chris@43: Private Declare Function lngfncCpr Lib "zlib.dll" Alias "compress2" (ByRef Chris@43: dest As Any, ByRef destLen As Any, ByRef src As Any, ByVal srcLen As Long, Chris@43: ByVal level As Integer) As Long Chris@43: Private Declare Function lngfncUcp Lib "zlib.dll" Alias "uncompress" (ByRef Chris@43: dest As Any, ByRef destLen As Any, ByRef src As Any, ByVal srcLen As Long) Chris@43: As Long Chris@43: Chris@43: Public Sub subCompressFile(ByVal strargOriFilPth As String, Optional ByVal Chris@43: strargCprFilPth As String, Optional ByVal intLvl As Integer = 9) Chris@43: Dim strCprPth As String Chris@43: Dim lngOriSiz As Long Chris@43: Dim lngCprSiz As Long Chris@43: Dim bytaryOri() As Byte Chris@43: Dim bytaryCpr() As Byte Chris@43: lngOriSiz = FileLen(strargOriFilPth) Chris@43: ReDim bytaryOri(lngOriSiz - 1) Chris@43: Open strargOriFilPth For Binary Access Read As #1 Chris@43: Get #1, , bytaryOri() Chris@43: Close #1 Chris@43: strCprPth = IIf(strargCprFilPth = "", strargOriFilPth, strargCprFilPth) Chris@43: 'Select file path and name Chris@43: strCprPth = strCprPth & IIf(Right(strCprPth, Len(strFilExt)) = Chris@43: strFilExt, "", strFilExt) 'Add file extension if not exists Chris@43: lngCprSiz = (lngOriSiz * 1.01) + 12 'Compression needs temporary a bit Chris@43: more space then original file size Chris@43: ReDim bytaryCpr(lngCprSiz - 1) Chris@43: If lngfncCpr(bytaryCpr(0), lngCprSiz, bytaryOri(0), lngOriSiz, intLvl) = Chris@43: SUCCESS Then Chris@43: lngpvtPcnSml = (1# - (lngCprSiz / lngOriSiz)) * 100 Chris@43: ReDim Preserve bytaryCpr(lngCprSiz - 1) Chris@43: Open strCprPth For Binary Access Write As #1 Chris@43: Put #1, , bytaryCpr() Chris@43: Put #1, , lngOriSiz 'Add the the original size value to the end Chris@43: (last 4 bytes) Chris@43: Close #1 Chris@43: Else Chris@43: MsgBox "Compression error" Chris@43: End If Chris@43: Erase bytaryCpr Chris@43: Erase bytaryOri Chris@43: End Sub Chris@43: Chris@43: Public Sub subUncompressFile(ByVal strargFilPth As String) Chris@43: Dim bytaryCpr() As Byte Chris@43: Dim bytaryOri() As Byte Chris@43: Dim lngOriSiz As Long Chris@43: Dim lngCprSiz As Long Chris@43: Dim strOriPth As String Chris@43: lngCprSiz = FileLen(strargFilPth) Chris@43: ReDim bytaryCpr(lngCprSiz - 1) Chris@43: Open strargFilPth For Binary Access Read As #1 Chris@43: Get #1, , bytaryCpr() Chris@43: Close #1 Chris@43: 'Read the original file size value: Chris@43: lngOriSiz = bytaryCpr(lngCprSiz - 1) * (2 ^ 24) _ Chris@43: + bytaryCpr(lngCprSiz - 2) * (2 ^ 16) _ Chris@43: + bytaryCpr(lngCprSiz - 3) * (2 ^ 8) _ Chris@43: + bytaryCpr(lngCprSiz - 4) Chris@43: ReDim Preserve bytaryCpr(lngCprSiz - 5) 'Cut of the original size value Chris@43: ReDim bytaryOri(lngOriSiz - 1) Chris@43: If lngfncUcp(bytaryOri(0), lngOriSiz, bytaryCpr(0), lngCprSiz) = SUCCESS Chris@43: Then Chris@43: strOriPth = Left(strargFilPth, Len(strargFilPth) - Len(strFilExt)) Chris@43: Open strOriPth For Binary Access Write As #1 Chris@43: Put #1, , bytaryOri() Chris@43: Close #1 Chris@43: Else Chris@43: MsgBox "Uncompression error" Chris@43: End If Chris@43: Erase bytaryCpr Chris@43: Erase bytaryOri Chris@43: End Sub Chris@43: Public Property Get lngPercentSmaller() As Long Chris@43: lngPercentSmaller = lngpvtPcnSml Chris@43: End Property