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