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