annotate src/zlib-1.2.7/old/visual-basic.txt @ 94:d278df1123f9

Add liblo
author Chris Cannam <cannam@all-day-breakfast.com>
date Wed, 20 Mar 2013 15:25:02 +0000
parents 8a15ff55d9af
children
rev   line source
cannam@89 1 See below some functions declarations for Visual Basic.
cannam@89 2
cannam@89 3 Frequently Asked Question:
cannam@89 4
cannam@89 5 Q: Each time I use the compress function I get the -5 error (not enough
cannam@89 6 room in the output buffer).
cannam@89 7
cannam@89 8 A: Make sure that the length of the compressed buffer is passed by
cannam@89 9 reference ("as any"), not by value ("as long"). Also check that
cannam@89 10 before the call of compress this length is equal to the total size of
cannam@89 11 the compressed buffer and not zero.
cannam@89 12
cannam@89 13
cannam@89 14 From: "Jon Caruana" <jon-net@usa.net>
cannam@89 15 Subject: Re: How to port zlib declares to vb?
cannam@89 16 Date: Mon, 28 Oct 1996 18:33:03 -0600
cannam@89 17
cannam@89 18 Got the answer! (I haven't had time to check this but it's what I got, and
cannam@89 19 looks correct):
cannam@89 20
cannam@89 21 He has the following routines working:
cannam@89 22 compress
cannam@89 23 uncompress
cannam@89 24 gzopen
cannam@89 25 gzwrite
cannam@89 26 gzread
cannam@89 27 gzclose
cannam@89 28
cannam@89 29 Declares follow: (Quoted from Carlos Rios <c_rios@sonda.cl>, in Vb4 form)
cannam@89 30
cannam@89 31 #If Win16 Then 'Use Win16 calls.
cannam@89 32 Declare Function compress Lib "ZLIB.DLL" (ByVal compr As
cannam@89 33 String, comprLen As Any, ByVal buf As String, ByVal buflen
cannam@89 34 As Long) As Integer
cannam@89 35 Declare Function uncompress Lib "ZLIB.DLL" (ByVal uncompr
cannam@89 36 As String, uncomprLen As Any, ByVal compr As String, ByVal
cannam@89 37 lcompr As Long) As Integer
cannam@89 38 Declare Function gzopen Lib "ZLIB.DLL" (ByVal filePath As
cannam@89 39 String, ByVal mode As String) As Long
cannam@89 40 Declare Function gzread Lib "ZLIB.DLL" (ByVal file As
cannam@89 41 Long, ByVal uncompr As String, ByVal uncomprLen As Integer)
cannam@89 42 As Integer
cannam@89 43 Declare Function gzwrite Lib "ZLIB.DLL" (ByVal file As
cannam@89 44 Long, ByVal uncompr As String, ByVal uncomprLen As Integer)
cannam@89 45 As Integer
cannam@89 46 Declare Function gzclose Lib "ZLIB.DLL" (ByVal file As
cannam@89 47 Long) As Integer
cannam@89 48 #Else
cannam@89 49 Declare Function compress Lib "ZLIB32.DLL"
cannam@89 50 (ByVal compr As String, comprLen As Any, ByVal buf As
cannam@89 51 String, ByVal buflen As Long) As Integer
cannam@89 52 Declare Function uncompress Lib "ZLIB32.DLL"
cannam@89 53 (ByVal uncompr As String, uncomprLen As Any, ByVal compr As
cannam@89 54 String, ByVal lcompr As Long) As Long
cannam@89 55 Declare Function gzopen Lib "ZLIB32.DLL"
cannam@89 56 (ByVal file As String, ByVal mode As String) As Long
cannam@89 57 Declare Function gzread Lib "ZLIB32.DLL"
cannam@89 58 (ByVal file As Long, ByVal uncompr As String, ByVal
cannam@89 59 uncomprLen As Long) As Long
cannam@89 60 Declare Function gzwrite Lib "ZLIB32.DLL"
cannam@89 61 (ByVal file As Long, ByVal uncompr As String, ByVal
cannam@89 62 uncomprLen As Long) As Long
cannam@89 63 Declare Function gzclose Lib "ZLIB32.DLL"
cannam@89 64 (ByVal file As Long) As Long
cannam@89 65 #End If
cannam@89 66
cannam@89 67 -Jon Caruana
cannam@89 68 jon-net@usa.net
cannam@89 69 Microsoft Sitebuilder Network Level 1 Member - HTML Writer's Guild Member
cannam@89 70
cannam@89 71
cannam@89 72 Here is another example from Michael <michael_borgsys@hotmail.com> that he
cannam@89 73 says conforms to the VB guidelines, and that solves the problem of not
cannam@89 74 knowing the uncompressed size by storing it at the end of the file:
cannam@89 75
cannam@89 76 'Calling the functions:
cannam@89 77 'bracket meaning: <parameter> [optional] {Range of possible values}
cannam@89 78 'Call subCompressFile(<path with filename to compress> [, <path with
cannam@89 79 filename to write to>, [level of compression {1..9}]])
cannam@89 80 'Call subUncompressFile(<path with filename to compress>)
cannam@89 81
cannam@89 82 Option Explicit
cannam@89 83 Private lngpvtPcnSml As Long 'Stores value for 'lngPercentSmaller'
cannam@89 84 Private Const SUCCESS As Long = 0
cannam@89 85 Private Const strFilExt As String = ".cpr"
cannam@89 86 Private Declare Function lngfncCpr Lib "zlib.dll" Alias "compress2" (ByRef
cannam@89 87 dest As Any, ByRef destLen As Any, ByRef src As Any, ByVal srcLen As Long,
cannam@89 88 ByVal level As Integer) As Long
cannam@89 89 Private Declare Function lngfncUcp Lib "zlib.dll" Alias "uncompress" (ByRef
cannam@89 90 dest As Any, ByRef destLen As Any, ByRef src As Any, ByVal srcLen As Long)
cannam@89 91 As Long
cannam@89 92
cannam@89 93 Public Sub subCompressFile(ByVal strargOriFilPth As String, Optional ByVal
cannam@89 94 strargCprFilPth As String, Optional ByVal intLvl As Integer = 9)
cannam@89 95 Dim strCprPth As String
cannam@89 96 Dim lngOriSiz As Long
cannam@89 97 Dim lngCprSiz As Long
cannam@89 98 Dim bytaryOri() As Byte
cannam@89 99 Dim bytaryCpr() As Byte
cannam@89 100 lngOriSiz = FileLen(strargOriFilPth)
cannam@89 101 ReDim bytaryOri(lngOriSiz - 1)
cannam@89 102 Open strargOriFilPth For Binary Access Read As #1
cannam@89 103 Get #1, , bytaryOri()
cannam@89 104 Close #1
cannam@89 105 strCprPth = IIf(strargCprFilPth = "", strargOriFilPth, strargCprFilPth)
cannam@89 106 'Select file path and name
cannam@89 107 strCprPth = strCprPth & IIf(Right(strCprPth, Len(strFilExt)) =
cannam@89 108 strFilExt, "", strFilExt) 'Add file extension if not exists
cannam@89 109 lngCprSiz = (lngOriSiz * 1.01) + 12 'Compression needs temporary a bit
cannam@89 110 more space then original file size
cannam@89 111 ReDim bytaryCpr(lngCprSiz - 1)
cannam@89 112 If lngfncCpr(bytaryCpr(0), lngCprSiz, bytaryOri(0), lngOriSiz, intLvl) =
cannam@89 113 SUCCESS Then
cannam@89 114 lngpvtPcnSml = (1# - (lngCprSiz / lngOriSiz)) * 100
cannam@89 115 ReDim Preserve bytaryCpr(lngCprSiz - 1)
cannam@89 116 Open strCprPth For Binary Access Write As #1
cannam@89 117 Put #1, , bytaryCpr()
cannam@89 118 Put #1, , lngOriSiz 'Add the the original size value to the end
cannam@89 119 (last 4 bytes)
cannam@89 120 Close #1
cannam@89 121 Else
cannam@89 122 MsgBox "Compression error"
cannam@89 123 End If
cannam@89 124 Erase bytaryCpr
cannam@89 125 Erase bytaryOri
cannam@89 126 End Sub
cannam@89 127
cannam@89 128 Public Sub subUncompressFile(ByVal strargFilPth As String)
cannam@89 129 Dim bytaryCpr() As Byte
cannam@89 130 Dim bytaryOri() As Byte
cannam@89 131 Dim lngOriSiz As Long
cannam@89 132 Dim lngCprSiz As Long
cannam@89 133 Dim strOriPth As String
cannam@89 134 lngCprSiz = FileLen(strargFilPth)
cannam@89 135 ReDim bytaryCpr(lngCprSiz - 1)
cannam@89 136 Open strargFilPth For Binary Access Read As #1
cannam@89 137 Get #1, , bytaryCpr()
cannam@89 138 Close #1
cannam@89 139 'Read the original file size value:
cannam@89 140 lngOriSiz = bytaryCpr(lngCprSiz - 1) * (2 ^ 24) _
cannam@89 141 + bytaryCpr(lngCprSiz - 2) * (2 ^ 16) _
cannam@89 142 + bytaryCpr(lngCprSiz - 3) * (2 ^ 8) _
cannam@89 143 + bytaryCpr(lngCprSiz - 4)
cannam@89 144 ReDim Preserve bytaryCpr(lngCprSiz - 5) 'Cut of the original size value
cannam@89 145 ReDim bytaryOri(lngOriSiz - 1)
cannam@89 146 If lngfncUcp(bytaryOri(0), lngOriSiz, bytaryCpr(0), lngCprSiz) = SUCCESS
cannam@89 147 Then
cannam@89 148 strOriPth = Left(strargFilPth, Len(strargFilPth) - Len(strFilExt))
cannam@89 149 Open strOriPth For Binary Access Write As #1
cannam@89 150 Put #1, , bytaryOri()
cannam@89 151 Close #1
cannam@89 152 Else
cannam@89 153 MsgBox "Uncompression error"
cannam@89 154 End If
cannam@89 155 Erase bytaryCpr
cannam@89 156 Erase bytaryOri
cannam@89 157 End Sub
cannam@89 158 Public Property Get lngPercentSmaller() As Long
cannam@89 159 lngPercentSmaller = lngpvtPcnSml
cannam@89 160 End Property