Results 1 to 33 of 33

Thread: VB6 - Zipper & ZipWriter, Zipping from VB programs

  1. #1

    Thread Starter
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Lightbulb VB6 - Zipper & ZipWriter, Zipping from VB programs

    Background

    A lot of us find the need to create ZIP archives programmatically from time to time. There are a number of techniques we can use, from spawning external utility programs to 3rd party components to Shell automation.

    Here is yet another way to accomplish this: using the free, open source zlibwapi.dll


    Minizip

    In addition to providing a STDCALL version of ZLib that we can call easily from VB6 programs zlibwapi.dll includes the Minizip project code as well.

    Like a lot of open source hacked out by C coders this can be rough in many places, but it is widely used and well proven. It should have few if any bugs in the most recent version.

    I'm using version 1.25 here. You can get this from:

    Minizip: Zip and UnZip additionnal library

    See the typo there? This is just one symptom of some of the issues, but fortunately the code at least seems to work fine even if its source is wonky with lots of flaws in comments and general documentation issues.

    This DLL is not included in the attachment. You must download it yourself.

    In zlib125dll.zip there is the Win32 Windows DLL of my Windows DLL named Zlibwapi.dll that contains both zLib and Minilib.
    The file you want from this ZIP archive is:

    zlib125dll.zip\dll32\zlibwapi.dll


    ZipWriter

    ZipWriter is a VB6 Class that wraps zlibwapi.dll to provide you with a way to create a ZIP archive and actually write data into it as archived files with no intermediate disk I/O steps.

    You can use this as-is in many cases without the other code offered here.


    Zipper

    Zipper is a VB6 UserControl that wraps ZipWriter and a small helper ZipFile Class to give you the ability to create a ZIP archive (or add to an existing one) and add a list of disk files to it.

    Zipper.Zip is an async operation and reports back progress, errors, and completion through several events. There is a Zipper.Cancel method if you need that.


    ZipDemo

    ZipDemo is a VB6 project that demonstrates use of the items described above.

    You must download zlibwapi.dll and copy it into this project folder to run the program.

    Much of the bulk of this attachment consists of the sample files in the "samples2" folder included.


    There is a "ZipWriter" button that does a simple test of ZipWriter, creating a new ZIP archive "test.zip" with two files written to it. When that step completes the "Zipper" button is enabled.

    The "Zipper" button tests Zipper, adding the files it finds in the "samples2" folder to the "test.zip" created in the first stage of the demo. While running a progressbar is updated and a "Cancel" button is enabled.

    The "samples2" folder as supplied has just a few small files. Be sure to copy some larger files into it and rerun the program to see how things go with large files. The performance is fairly good.


    Remarks

    While you need to deploy zlibwapi.dll with your programs this is a standard DLL that you can feel free to place next to your EXE. No registration is required.

    The results are better than those achieved using most other common techniques. Progress/Cancel/Complete can be really nice to have. There is no need for the shaky, convoluted, hackish window spelunking people often resort to when automating Shell objects.

    There is a lot more you can do with zlibwapi.dll too. You can read from ZIP archives, unzip them, compress separate files outside of ZIP archives, compress/expand data in memory, etc. Even the huge-file Zip64 format is supported.

    All you need is to write additional wrappers or just make the calls directly.
    Attached Files Attached Files

  2. #2

    Thread Starter
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    Here is another demo. This one just shows creating a ZIP archive from a folder, but it also includes subfolders if any are present.

    That is something not spelled out in the previous example.


    Name:  sshot.png
Views: 5259
Size:  5.5 KB

    Demo upon completion


    The sample data is included.
    Attached Files Attached Files

  3. #3

    Thread Starter
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    This is an update: Zipper 2 (version 2).

    This expands the ZipWriter class to handle password encryption of archived files, and the ability to specify the timestamp to be recorded in the archive for each file.

    The Zipper UserControl is expanded to accept file passwords and offers the option to use the disk file's LastUpdate timestamp instead of the result of the Now() function. This means Zipper has two helper classes now: ZipFile as before as well as the new ZipDateTimes. Nothing prevents the code in ZipDateTimes from being folded into Zipper itself, but keeping it separate helps keep Zipper at least a little easier to understand.


    Once again, the point of Zipper is to make it easy to ZIP up one or more files asynchronously with progress updates and completion notification. The result is far cleaner than using hacks to try to detect when (and even if) a Shell32 ZIP process completes and completes properly.

    A further enhancement might be the option to use the ZIP64 format to allow you to automate archiving of huge files. Note that until Windows Vista there was no File Explorer (Shell32) support for ZIP64.
    Attached Files Attached Files

  4. #4

    Thread Starter
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    Version 2.1, which adds ZipperSync.

    ZipperSync is a synchronous "clone" (very close copy) of the Zipper UserControl. ZipperSync may be a little easier to read because it doesn't have to use a time-slicing Timer to drive the I/O and processing.

    If your files to ZIP up into an archive are fairly small so that you do not need async operation to remain responsive you might choose ZipperSync instead of Zipper.

    The demo is very similar to the Zipper 2 Demo above.


    Edit:

    While hilarious if nobody had already downloaded it (not so funny since several people had), the attachment was a bit of a mess. It had a broken version of the new ZipperSync and was still using the Zipper control.

    Attachment replaced. Sorry for the error.
    Attached Files Attached Files
    Last edited by dilettante; Dec 19th, 2014 at 03:01 PM. Reason: replaced attachment

  5. #5

    Thread Starter
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    ZipperSync posted above is full of serious bugs!

    These have been corrected, and a new AddBLOB() method has been added in version 2.2 posted here. This is being posted in a minimal project showing how easy it can be to use.

    Note that the new AddBLOB() means I had to extend the ZipFile class. While Zipper.ctl has not had a similar AddBLOB() method added it should still work with the new ZipFile 2.2 as well.

    AddBLOB() means you can add any arbitrary Byte array (BLOB) data as a "file" in the archive without writing it out as a temporary disk file.


    A little confusing, but:

    You can take (1.) the previous code posted above as version 2.1, (2.) replace all of the Zip*.* files by the new ones from this archive, and then (3.) everything should work fine (both Zipper 2 and ZipperSync 2.2).

    In other words... I have not included Zipper.cls this time since it did not change. If I add BLOB support to it later I'll repost all of the Zip*.* files in a future attachment.


    This ZipperSync class is very easy to use:

    Code:
    Private Sub cmdZipIt_Click()
        Dim TextBLOB() As Byte
    
        Text1.Enabled = False
        cmdZipIt.Enabled = False
    
        'Zip Text1.Text as "Text.txt" in "Sample.zip" archive:
        With New ZipperSync
            TextBLOB = StrConv(Text1.Text, vbFromUnicode) 'Store as ANSI.
            .AddBLOB TextBLOB, "Text.txt"
            .Zip App.Path & "\Sample.zip"
        End With
    
        lblStatus.Caption = "Complete"
    End Sub
    Attached Files Attached Files

  6. #6

    Thread Starter
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    A reminder:

    See post #1 above, since you need a recent version of zlibwapi.dll for this to work. As mentioned above this is a "flat DLL" i.e. not an ActiveX DLL so it does not require registration.

  7. #7

    Thread Starter
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    BTW:

    I you can't or don't want to compile it yourself, there is a precompiled zlibwapi.dll version 1.2.8 at:

    GlobalPlatform

    This has zlib fixes beyond 1.2.5, and seems to work fine with my wrapper classes posted above.


    Edit:

    The page at that link no longer appears to offer precompiled binaries.
    Last edited by dilettante; Sep 30th, 2016 at 03:01 AM.

  8. #8

    Thread Starter
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    In case it isn't clear, you can just skip the additional classes and use ZipWriter.cls alone if you are doing something very simple. Those other classes are used to abstract and "batch" the process of zipping multiple files. For a single file or two they may be more than you need.


    Here I'm using the same ZipWriter version 2 from the last few uploads (again without error handling for simplification - don't do that!) to accomplish the same thing as the example in post #5 above:

    Code:
    Private Sub cmdZipIt_Click()
        Dim TextBLOB() As Byte
    
        Text1.Enabled = False
        cmdZipIt.Enabled = False
    
        'Zip Text1.Text as "Text.txt" in "Sample.zip" archive:
        With New ZipWriter
            TextBLOB = StrConv(Text1.Text, vbFromUnicode) 'Store as ANSI.
            .OpenZip App.Path & "\Sample.zip"
            .OpenFileInZip "Text.txt"
            .WriteBytes TextBLOB
            .CloseFileInZip
            .CloseZip
        End With
    
        lblStatus.Caption = "Complete"
    End Sub
    So you can just bypass the extra classes that wrap ZipWriter, write your own wrapper, or pull the definitions and logic from ZipWriter and use them inline within some other module (.BAS, .FRM, etc.).

    ZipWriter itself contains the zlibwapi.dll definitions and wrapper logic, i.e. a "VB6 API binding" for the subset of zlibwapi.dll functionality required to create/write Zip archives.
    Attached Files Attached Files

  9. #9
    Addicted Member
    Join Date
    May 2021
    Posts
    131

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    Hi. Thank you for this, and for all your other posts and sample code (especially re: WIA).

    I stumbled across this, and was intrigued. I've converted it to VBA 64bit, and have obtained a copy of the 64bit version of zlibwapi.dll. Using the most recent ZipWriter class, I can get it to create and compress a ZIP file. That part works perfectly.

    The password element doesn't seem for me though. I can set a password, and unable to open the file until I enter the right password - but the problem is that even when I enter the correct password, it won't work. It presents an error message saying that what I've entered is incorrect.

    Not sure if you've encountered this before, but just thought I'd flag it.

  10. #10
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    Quote Originally Posted by Dan_W View Post
    Hi. Thank you for this, and for all your other posts and sample code (especially re: WIA).

    I stumbled across this, and was intrigued. I've converted it to VBA 64bit, and have obtained a copy of the 64bit version of zlibwapi.dll. Using the most recent ZipWriter class, I can get it to create and compress a ZIP file. That part works perfectly.

    The password element doesn't seem for me though. I can set a password, and unable to open the file until I enter the right password - but the problem is that even when I enter the correct password, it won't work. It presents an error message saying that what I've entered is incorrect.

    Not sure if you've encountered this before, but just thought I'd flag it.
    can you upload a VBA X64 DEMO XLSM demo? THANK YOU
    it's also can use on twinbasic x64

  11. #11
    Fanatic Member HackerVlad's Avatar
    Join Date
    Nov 2023
    Posts
    681

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    I would really like to have such a code only for the reverse action - for unpacking a ZIP file. Where can I find this code using this library?

  12. #12
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    Quote Originally Posted by HackerVlad View Post
    I would really like to have such a code only for the reverse action - for unpacking a ZIP file. Where can I find this code using this library?
    MiniZip.cls , vb6 unzip File Class by zlibwapi.dll-VBForums
    https://www.vbforums.com/showthread....y-zlibwapi-dll

  13. #13
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    i unzip a excel file:test.xlsx,for download images,xml files:

    unzip file by shell.application:

    Duration: 866.4118 milliseconds [decompression 1]
    Duration: 248.3394 milliseconds [decompression 2]
    Duration: 395.8231 milliseconds [Extract image]
    Duration: 489.3050 milliseconds [Extract image]

    unzip by zlibwapi:

    Duration: 2.9302 milliseconds [decompression 1]
    Duration: 1.5231 milliseconds [decompression 2]
    Duration: 1.5084 milliseconds [Extract image]
    Duration: 1.7378 milliseconds [Extract image]

  14. #14
    Fanatic Member HackerVlad's Avatar
    Join Date
    Nov 2023
    Posts
    681

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    Quote Originally Posted by xiaoyao View Post
    i unzip a excel file:test.xlsx,for download images,xml files:

    unzip file by shell.application:

    Duration: 866.4118 milliseconds [decompression 1]
    Duration: 248.3394 milliseconds [decompression 2]
    Duration: 395.8231 milliseconds [Extract image]
    Duration: 489.3050 milliseconds [Extract image]

    unzip by zlibwapi:

    Duration: 2.9302 milliseconds [decompression 1]
    Duration: 1.5231 milliseconds [decompression 2]
    Duration: 1.5084 milliseconds [Extract image]
    Duration: 1.7378 milliseconds [Extract image]
    And where is the class speed test from the wqeweto?
    https://github.com/wqweto/ZipArchive

  15. #15
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    Quote Originally Posted by HackerVlad View Post
    And where is the class speed test from the wqeweto?
    https://github.com/wqweto/ZipArchive
    It's just the simplest excel file. You can add a few pictures and then copy the table. The entire file is actually a few hundred kilobytes.

  16. #16
    Fanatic Member
    Join Date
    Jul 2022
    Location
    Buford, Ga USA
    Posts
    629

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    Quote Originally Posted by HackerVlad View Post
    And where is the class speed test from the wqeweto?
    https://github.com/wqweto/ZipArchive
    I use this with twinBASIC for my super simply twinBASIC installer. It works great and super simple to use.

  17. #17
    Fanatic Member HackerVlad's Avatar
    Join Date
    Nov 2023
    Posts
    681

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    Quote Originally Posted by jdelano View Post
    I use this with twinBASIC for my super simply twinBASIC installer. It works great and super simple to use.
    I also really like this class, but using it leads to an excessively large increase in the size of the EXE file. Therefore, it is better to use more compact (small) codes for simple unpacking.

  18. #18
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,167

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    Quote Originally Posted by HackerVlad View Post
    I also really like this class, but using it leads to an excessively large increase in the size of the EXE file. Therefore, it is better to use more compact (small) codes for simple unpacking.
    You can try declaring ZIP_NOCOMPRESS = 1 in your project's Conditional Compilation if you are only going to extract files. Check out the source code near the begining, there are some more conditional compilation options.

    Btw, nowadays Win10+ comes with libarchive built-in (in stdcall archiveint.dll) so this can be used to zip/unzip (or ungzip) and reduce cZipArchive's footprint on output binary by removing most of the ASM thunk *and* increase [de]compression performance in the meantime.

    Another option on Win10+ is to shell tar.exe to zip/unzip e.g. c:> tar -caf d:\temp\aaa.zip d:\temp\bbb\*.*

    cheers,
    </wqw>

  19. #19
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    Quote Originally Posted by wqweto View Post
    You can try declaring ZIP_NOCOMPRESS = 1 in your project's Conditional Compilation if you are only going to extract files. Check out the source code near the begining, there are some more conditional compilation options.

    Btw, nowadays Win10+ comes with libarchive built-in (in stdcall archiveint.dll) so this can be used to zip/unzip (or ungzip) and reduce cZipArchive's footprint on output binary by removing most of the ASM thunk *and* increase [de]compression performance in the meantime.

    Another option on Win10+ is to shell tar.exe to zip/unzip e.g. c:> tar -caf d:\temp\aaa.zip d:\temp\bbb\*.*

    cheers,
    </wqw>
    Libarchive (archiveint. DLL in stdcall). Is there a simple example? If this DLL is copied, can it be used on win7 and win8?

    shell.application,This is equivalent to clicking on the decompression in the Explorer, all the same. It can take up to a second to extract a small file from an 20kb Excel file.
    If the file is too large, a dialog box will pop up when he decompresses it, which will affect the user experience.
    In fact, I feel that Microsoft should have added a zip decompression function in 1998 or even 2002. Every time Microsoft updates the system, it won't let us install the new framework of.net on top of the old system.
    Adopting this kind of deep binding forces us to buy new computers.As a result, there are 10 different versions of.net SDK, all kinds of incompatibilities. (???????10??????.net sdk???????)

    The zlib. DLL takes only 5 milliseconds to decompress.
    So pure decompression, this is really convenient.
    Last edited by xiaoyao; Feb 16th, 2025 at 11:53 AM.

  20. #20
    Fanatic Member HackerVlad's Avatar
    Join Date
    Nov 2023
    Posts
    681

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    Quote Originally Posted by xiaoyao View Post
    I feel that Microsoft should have added a zip decompression function in 1998 or even 2002.
    Yes, Microsoft did this in 2001, starting with Windows XP, there is a ZipFldr.dll library for this. But there is no documentation anywhere on how to use it, but The trick was able to make it work, and I'm currently studying its code and redoing it.

  21. #21
    Fanatic Member HackerVlad's Avatar
    Join Date
    Nov 2023
    Posts
    681

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    Quote Originally Posted by wqweto View Post
    You can try declaring ZIP_NOCOMPRESS = 1 in your project's
    Following this advice helped reduce the size of the EXE by 30 KB. However, the class itself adds about 100 KB to the EXE anyway (which is quite a lot) and I don't like it. That's why I said that it's better to use other simpler and shorter codes for simple unpacking.

  22. #22
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    Quote Originally Posted by HackerVlad View Post
    Following this advice helped reduce the size of the EXE by 30 KB. However, the class itself adds about 100 KB to the EXE anyway (which is quite a lot) and I don't like it. That's why I said that it's better to use other simpler and shorter codes for simple unpacking.
    You can make a universal interface. Use different DLLs, ZipFldr. DLL, zlib. DLL,
    Implement compression or decompression.
    Because different DLLs have different functions, each has its own advantages.
    I support his password, and some versions are updated with stronger functions. Some of them are stable and very small.
    If you want to draw a picture, you can use the gdiplus. DLL gdi32.dll, htmlcanv, SVG.?
    For drawing ordinary graphics, we can make some general interfaces.
    Let the old VB6 play more functions.

  23. #23
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,167

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    Quote Originally Posted by HackerVlad View Post
    That's why I said that it's better to use other simpler and shorter codes for simple unpacking.
    Btw, which simpler and shorter codes do you talk about? Is there a simpler/shorter deflate algorithm implemented in VB6? Or PKWare ZIP format handling?

  24. #24
    Fanatic Member HackerVlad's Avatar
    Join Date
    Nov 2023
    Posts
    681

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    Quote Originally Posted by wqweto View Post
    Btw, which simpler and shorter codes do you talk about? Is there a simpler/shorter deflate algorithm implemented in VB6? Or PKWare ZIP format handling?
    Well, I think the easiest way is to use the built-in Windows library ZipFldr.dll. Well, the simplest code from The Trick is generally few lines of code, but it requires a dependency in the form of olelib.tlb. Here is the code:

    Code:
    Option Explicit
    Private Declare Function SHParseDisplayName Lib "shell32" (ByVal pszName As Long, ByVal IBindCtx As Long, ByRef ppidl As Long, sfgaoIn As Long, sfgaoOut As Long) As Long
    Private Declare Function ILFree Lib "shell32" (ByVal pidlFree As Long) As Long
    Private Declare Function lstrcpyn Lib "kernel32" Alias "lstrcpynW" (ByVal lpString1 As Long, ByVal lpString2 As Long, ByVal iMaxLength As Long) As Long
    Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenW" (ByVal lpString As Long) As Long
    
    Private Const ZipFldrCLSID = "{E88DCCE0-B7B3-11d1-A9F0-00AA0060FA31}"
    Private Const IID_IShellExtInit = "{000214E8-0000-0000-C000-000000000046}"
     
    Private Sub Form_Load()
        Dim clsid   As UUID
        Dim iidSh   As UUID
        Dim shExt   As IShellExtInit
        Dim pf      As IPersistFolder2
        Dim pidl    As Long
        Dim file    As String
        Dim cb      As Long
        
        file = "D:\Temp\temp.zip"
        CLSIDFromString ZipFldrCLSID, clsid
        CLSIDFromString IID_IShellExtInit, iidSh
        
        If CoCreateInstance(clsid, Nothing, CLSCTX_INPROC_SERVER, iidSh, shExt) <> S_OK Then Exit Sub
        Set pf = shExt
        SHParseDisplayName StrPtr(file), 0, pidl, 0, 0
        pf.Initialize pidl
        ILFree pidl
        
        Dim srg     As IStorage
        Dim stm     As IStream
        Dim enm     As IEnumSTATSTG
        Dim itm     As STATSTG
        Dim nam     As String
        Dim buf()   As Byte
        Dim fnum    As Integer
        
        Set srg = pf
        Set enm = srg.EnumElements
        
        ReDim buf(&HFFFF&)
        
        enm.Reset
        Do While enm.Next(1, itm) = S_OK
            cb = lstrlen(itm.pwcsName)
            nam = Space(cb)
            lstrcpyn StrPtr(nam), itm.pwcsName, cb + 1
            CoTaskMemFree itm.pwcsName
            
            If itm.Type <> STGTY_STORAGE Then
                fnum = FreeFile
                Open "D:\temp\Testzip\" & nam For Binary As fnum
                
                Set stm = srg.OpenStream(nam, 0, STGM_READ, 0)
                
                Do
                    cb = stm.Read(buf(0), UBound(buf) + 1)
                    If cb = 0 Then Exit Do
                    If cb <= UBound(buf) Then ReDim Preserve buf(cb - 1)
                    Put #fnum, , buf()
                Loop
                Close fnum
            End If
        Loop
    End Sub
    And a more advanced same code from fafalone: https://www.vbforums.com/showthread....IStorage-based

    But I was very upset that this code requires a TLB dependency. I tried to rewrite this code for myself to get rid of the addiction, but it didn't work out, it turned out to be too difficult.

  25. #25
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    Quote Originally Posted by HackerVlad View Post
    Well, I think the easiest way is to use the built-in Windows library ZipFldr.dll. Well, the simplest code from
    Code:
    Option Explicit
        Do While enm.Next(1, itm) = S_OK
            cb = lstrlen(itm.pwcsName)
            nam = Space(cb)
            lstrcpyn StrPtr(nam), itm.pwcsName, cb + 1
            CoTaskMemFree itm.pwcsName
            
            If itm.Type <> STGTY_STORAGE Then
                fnum = FreeFile
                Open "D:\temp\Testzip\" & nam For Binary As fnum
                
                Set stm = srg.OpenStream(nam, 0, STGM_READ, 0)
                
                Do
                    cb = stm.Read(buf(0), UBound(buf) + 1)
                    If cb = 0 Then Exit Do
                    If cb <= UBound(buf) Then ReDim Preserve buf(cb - 1)
                    Put #fnum, , buf()
                Loop
                Close fnum
            End If
        Loop
    End Sub
    And a more advanced same code from fafalone: https://www.vbforums.com/showthread....IStorage-based

    But I was very upset that this code requires a TLB dependency. I tried to rewrite this code for myself to get rid of the addiction, but it didn't work out, it turned out to be too difficult.
    Your method is very good. Compression and decompression are implemented with minimal code, and the running speed is still very fast.

    it's by ai,I don't know if it's right.

    Code:
    Private Declare Function CreateZip Lib "ZipFldr.dll" (ByVal ZipFile As String) As Long
    Private Declare Function AddZip Lib "ZipFldr.dll" (ByVal ZipFile As String, ByVal FileName As String, ByVal FilePath As String) As Long
    Private Declare Function CloseZip Lib "ZipFldr.dll" (ByVal ZipFile As String) As Long
    Sub CreateZipFile()
        Dim zipPath As String
        Dim filePath As String
        zipPath = "C:\test.zip"
        filePath = "C:\test.txt"
        Dim result As Long
        result = CreateZip(zipPath)
        If result = 0 Then
            result = AddZip(zipPath, "test.txt", filePath)
            If result = 0 Then
                result = CloseZip(zipPath)
                If result = 0 Then
                    MsgBox "????"
                Else
                    MsgBox "????????"
                End If
            Else
                MsgBox "??????????"
            End If
        Else
            MsgBox "????????"
        End If
    End Sub
    Last edited by xiaoyao; Feb 16th, 2025 at 04:27 PM.

  26. #26

  27. #27
    Fanatic Member HackerVlad's Avatar
    Join Date
    Nov 2023
    Posts
    681

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    By the way, I found the simplest and shortest code in that topic: https://www.vbforums.com/showthread....=1#post5081447

    Code:
        Dim oShell As Object
        Dim oFile As Object
        Dim Ret As Long
        
        Set oShell = CreateObject("Shell.Application")
        
        For Each oFile In oShell.NameSpace("D:\Temp\temp.zip").Items
            Ret = (oShell.NameSpace("D:\temp\Testzip\").CopyHere(oFile))
        Next
    I just checked - everything is working! Oh my God, why did I bother with other codes then?..

    P. S. But in XP, for some reason, this code didn't work for me.

  28. #28
    Fanatic Member HackerVlad's Avatar
    Join Date
    Nov 2023
    Posts
    681

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    Quote Originally Posted by xiaoyao View Post
    it's by ai,I don't know if it's right.

    Code:
    Private Declare Function CreateZip Lib "ZipFldr.dll" (ByVal ZipFile As String) As Long
    Private Declare Function AddZip Lib "ZipFldr.dll" (ByVal ZipFile As String, ByVal FileName As String, ByVal FilePath As String) As Long
    Private Declare Function CloseZip Lib "ZipFldr.dll" (ByVal ZipFile As String) As Long
    Sub CreateZipFile()
        Dim zipPath As String
        Dim filePath As String
        zipPath = "C:\test.zip"
        filePath = "C:\test.txt"
        Dim result As Long
        result = CreateZip(zipPath)
        If result = 0 Then
            result = AddZip(zipPath, "test.txt", filePath)
            If result = 0 Then
                result = CloseZip(zipPath)
                If result = 0 Then
                    MsgBox "????"
                Else
                    MsgBox "????????"
                End If
            Else
                MsgBox "??????????"
            End If
        Else
            MsgBox "????????"
        End If
    End Sub
    Your artificial intelligence is complete nonsense! Such functions are included in libraries ZipFldr.dll It doesn't exist. There is no import table at all, this library is most likely implemented as a COM server.

  29. #29
    Fanatic Member HackerVlad's Avatar
    Join Date
    Nov 2023
    Posts
    681

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    Quote Originally Posted by wqweto View Post
    Btw, nowadays Win10+ comes with libarchive built-in (in stdcall archiveint.dll) so this can be used to zip/unzip (or ungzip) and reduce cZipArchive's footprint on output binary by removing most of the ASM thunk *and* increase [de]compression performance in the meantime.

    Another option on Win10+ is to shell tar.exe to zip/unzip e.g. c:> tar -caf d:\temp\aaa.zip d:\temp\bbb\*.*

    cheers,
    </wqw>
    Do you have an example of how the code for calling the library archiveint.dll works? I need an example of declarations and how to call them. Where can I see such a code?

  30. #30
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,167

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    Quote Originally Posted by HackerVlad View Post
    Do you have an example of how the code for calling the library archiveint.dll works? I need an example of declarations and how to call them. Where can I see such a code?
    I have sample code for ungzip (linked above) only.

    Quote Originally Posted by HackerVlad View Post
    I just checked - everything is working! Oh my God, why did I bother with other codes then?..
    Well, then we'll let you found out the problems with this code on your own :-)) It works on XP, that's not it. . .

    cheers,
    </wqw>

  31. #31
    Fanatic Member HackerVlad's Avatar
    Join Date
    Nov 2023
    Posts
    681

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    Quote Originally Posted by wqweto View Post
    I have sample code for ungzip (linked above) only.
    Is there such a code just for packaging? Yes, thanks for finding it. Does this work on both 32-bit and 64-bit systems?

    Code:
    Private Declare Function archive_read_data Lib "archiveint" Alias "_archive_read_data@12" (ByVal hArchive As Long, pBuffer As Any, ByVal lSize As Long) As Long

  32. #32
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,167

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    It's a Win10+ only feature. There is archiveint.dll in both C:\Windows\System32 and C:\Windows\SysWOW64 on my Win11 x64 box so it works from VB6 here.

    Not sure if there is 32-bit version of Win11 though but if it existed it sure would have worked there too.

    Btw, for API documentation you'll have to dig in https://github.com/libarchive/libarchive -- search for their bsdunzip.c sample code, it uses archive_read_support_format_zip in similar way gunzip sample code above does.

    cheers,
    </wqw>

  33. #33
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    It's too hard. It feels like Microsoft just turned off our access to compressed files. Unless we use C , VB. net

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width