Zlib and VB6...

  • Follow


Good morning...

I try to uncompress .gz files created by GnuZip, with the Zlib.dll in
VB6, but I get a -3 error (file corrupted).
What's wrong with my prog ?
Thanks...
Ben.



Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory"
(hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
Private Declare Function ZUncompress Lib "zlib.dll" Alias "uncompress"
(dest As Any, destLen As Any, src As Any, ByVal srcLen As Long) As Long

Public Sub UncompressFile(pSrc As String, pTgt As String)
   Dim lOrigSize As Long  'original size
   Dim bOrigData() As Byte  'output buffer
   Dim lCompSize As Long  'compressed size
   Dim bCompData() As Byte  'data buffer
   Dim lPosSize As Long
   Dim fnum As Integer
   Dim zRet As Long

   ' Load the source file into a byte array.
   lCompSize = FileLen(pSrc)
   ReDim bCompData(0 To lCompSize - 1)
   fnum = FreeFile
   Open pSrc For Binary Access Read As #fnum
   Get #fnum, , bCompData()
   Close #fnum

   ' get the original size
   lPosSize = lCompSize - 4
   CopyMemory lOrigSize, bCompData(lPosSize), 4

   ReDim bOrigData(0 To lOrigSize - 1)

   zRet = ZUncompress(bOrigData(0), lOrigSize - 1, bCompData(0),
lCompSize)
   MsgBox Str(zRet)  'retourne erreur -3 **********************
   Erase bCompData 'deallocate data buffer

   ' Remove the existing file, then write buffer in it.
   On Error Resume Next
   Kill pTgt
   On Error GoTo 0
   Open pTgt For Binary Access Write As #fnum
   Put #fnum, , bOrigData()
   Close #fnum

   Erase bOrigData 'deallocate return buffer
End Sub

0
Reply benfbox-google (2) 10/7/2005 8:05:47 AM


0 Replies
452 Views

(page loaded in 0.28 seconds)

Similiar Articles:







7/17/2012 7:53:49 PM


Reply: