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