URL
https://opencores.org/ocsvn/openrisc/openrisc/trunk
Subversion Repositories openrisc
[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [zlib/] [old/] [visual-basic.txt] - Rev 827
Go to most recent revision | Compare with Previous | Blame | View Log
See below some functions declarations for Visual Basic.Frequently Asked Question:Q: Each time I use the compress function I get the -5 error (not enoughroom in the output buffer).A: Make sure that the length of the compressed buffer is passed byreference ("as any"), not by value ("as long"). Also check thatbefore the call of compress this length is equal to the total size ofthe compressed buffer and not zero.From: "Jon Caruana" <jon-net@usa.net>Subject: Re: How to port zlib declares to vb?Date: Mon, 28 Oct 1996 18:33:03 -0600Got the answer! (I haven't had time to check this but it's what I got, andlooks correct):He has the following routines working:compressuncompressgzopengzwritegzreadgzcloseDeclares follow: (Quoted from Carlos Rios <c_rios@sonda.cl>, in Vb4 form)#If Win16 Then 'Use Win16 calls.Declare Function compress Lib "ZLIB.DLL" (ByVal compr AsString, comprLen As Any, ByVal buf As String, ByVal buflenAs Long) As IntegerDeclare Function uncompress Lib "ZLIB.DLL" (ByVal uncomprAs String, uncomprLen As Any, ByVal compr As String, ByVallcompr As Long) As IntegerDeclare Function gzopen Lib "ZLIB.DLL" (ByVal filePath AsString, ByVal mode As String) As LongDeclare Function gzread Lib "ZLIB.DLL" (ByVal file AsLong, ByVal uncompr As String, ByVal uncomprLen As Integer)As IntegerDeclare Function gzwrite Lib "ZLIB.DLL" (ByVal file AsLong, ByVal uncompr As String, ByVal uncomprLen As Integer)As IntegerDeclare Function gzclose Lib "ZLIB.DLL" (ByVal file AsLong) As Integer#ElseDeclare Function compress Lib "ZLIB32.DLL"(ByVal compr As String, comprLen As Any, ByVal buf AsString, ByVal buflen As Long) As IntegerDeclare Function uncompress Lib "ZLIB32.DLL"(ByVal uncompr As String, uncomprLen As Any, ByVal compr AsString, ByVal lcompr As Long) As LongDeclare Function gzopen Lib "ZLIB32.DLL"(ByVal file As String, ByVal mode As String) As LongDeclare Function gzread Lib "ZLIB32.DLL"(ByVal file As Long, ByVal uncompr As String, ByValuncomprLen As Long) As LongDeclare Function gzwrite Lib "ZLIB32.DLL"(ByVal file As Long, ByVal uncompr As String, ByValuncomprLen As Long) As LongDeclare Function gzclose Lib "ZLIB32.DLL"(ByVal file As Long) As Long#End If-Jon Caruanajon-net@usa.netMicrosoft Sitebuilder Network Level 1 Member - HTML Writer's Guild MemberHere is another example from Michael <michael_borgsys@hotmail.com> that hesays conforms to the VB guidelines, and that solves the problem of notknowing the uncompressed size by storing it at the end of the file:'Calling the functions:'bracket meaning: <parameter> [optional] {Range of possible values}'Call subCompressFile(<path with filename to compress> [, <path withfilename to write to>, [level of compression {1..9}]])'Call subUncompressFile(<path with filename to compress>)Option ExplicitPrivate lngpvtPcnSml As Long 'Stores value for 'lngPercentSmaller'Private Const SUCCESS As Long = 0Private Const strFilExt As String = ".cpr"Private Declare Function lngfncCpr Lib "zlib.dll" Alias "compress2" (ByRefdest As Any, ByRef destLen As Any, ByRef src As Any, ByVal srcLen As Long,ByVal level As Integer) As LongPrivate Declare Function lngfncUcp Lib "zlib.dll" Alias "uncompress" (ByRefdest As Any, ByRef destLen As Any, ByRef src As Any, ByVal srcLen As Long)As LongPublic Sub subCompressFile(ByVal strargOriFilPth As String, Optional ByValstrargCprFilPth As String, Optional ByVal intLvl As Integer = 9)Dim strCprPth As StringDim lngOriSiz As LongDim lngCprSiz As LongDim bytaryOri() As ByteDim bytaryCpr() As BytelngOriSiz = FileLen(strargOriFilPth)ReDim bytaryOri(lngOriSiz - 1)Open strargOriFilPth For Binary Access Read As #1Get #1, , bytaryOri()Close #1strCprPth = IIf(strargCprFilPth = "", strargOriFilPth, strargCprFilPth)'Select file path and namestrCprPth = strCprPth & IIf(Right(strCprPth, Len(strFilExt)) =strFilExt, "", strFilExt) 'Add file extension if not existslngCprSiz = (lngOriSiz * 1.01) + 12 'Compression needs temporary a bitmore space then original file sizeReDim bytaryCpr(lngCprSiz - 1)If lngfncCpr(bytaryCpr(0), lngCprSiz, bytaryOri(0), lngOriSiz, intLvl) =SUCCESS ThenlngpvtPcnSml = (1# - (lngCprSiz / lngOriSiz)) * 100ReDim Preserve bytaryCpr(lngCprSiz - 1)Open strCprPth For Binary Access Write As #1Put #1, , bytaryCpr()Put #1, , lngOriSiz 'Add the the original size value to the end(last 4 bytes)Close #1ElseMsgBox "Compression error"End IfErase bytaryCprErase bytaryOriEnd SubPublic Sub subUncompressFile(ByVal strargFilPth As String)Dim bytaryCpr() As ByteDim bytaryOri() As ByteDim lngOriSiz As LongDim lngCprSiz As LongDim strOriPth As StringlngCprSiz = FileLen(strargFilPth)ReDim bytaryCpr(lngCprSiz - 1)Open strargFilPth For Binary Access Read As #1Get #1, , bytaryCpr()Close #1'Read the original file size value:lngOriSiz = bytaryCpr(lngCprSiz - 1) * (2 ^ 24) _+ bytaryCpr(lngCprSiz - 2) * (2 ^ 16) _+ bytaryCpr(lngCprSiz - 3) * (2 ^ 8) _+ bytaryCpr(lngCprSiz - 4)ReDim Preserve bytaryCpr(lngCprSiz - 5) 'Cut of the original size valueReDim bytaryOri(lngOriSiz - 1)If lngfncUcp(bytaryOri(0), lngOriSiz, bytaryCpr(0), lngCprSiz) = SUCCESSThenstrOriPth = Left(strargFilPth, Len(strargFilPth) - Len(strFilExt))Open strOriPth For Binary Access Write As #1Put #1, , bytaryOri()Close #1ElseMsgBox "Uncompression error"End IfErase bytaryCprErase bytaryOriEnd SubPublic Property Get lngPercentSmaller() As LonglngPercentSmaller = lngpvtPcnSmlEnd Property
Go to most recent revision | Compare with Previous | Blame | View Log
