# VBForums CodeBank > CodeBank - Visual Basic 6 and earlier >  [VB6] 7-zip support

## wqweto

Here is an open source project that provides support for 7-zip in your VB6 projects.

https://github.com/wqweto/VszLib

Using VszLib.dll + 7z.dll your applications can create and extract 7z, zip, tar.gz, tar.bz2 and many more compression formats. Latest versions of 7z format include LZMA2 method for faster multi-core compression.

Post your comments and questions here.

cheers,
</wqw>

----------


## Bonnie West

Excellent code!   :Thumb:   Thanks for making it Open-Source!

BTW, are there plans to support Unicode?

----------


## wqweto

@Bonnie West: You mean unicode API for file handling and for creating long path+filenames?

Unicode support depends on archive entries handling by archive format. For instance original ZIP format does not support unicode file names.

I'll think about it, probably will have to use conditional compilation to support non-unicode filenames on 9x OSes.

cheers,
</wqw>

----------


## Bonnie West

@ wqweto

Yes. Since your project deals primarily with adding support for the 7-Zip format for VB6, I thought, why not include Unicode-aware file handling as well? I've just tested the 7-Zip File Manager and it can deal with Unicode filenames pretty well. But of course, it's up to you if you want to implement it or not. Consider my _'request'_ as a suggestion only.  :Alien Frog:

----------


## Zeev

Hello, thanks for your effort, I have searched for many months something like this.

I have few questions:
1. Does it work with zip\rar?
2. How can you check, after extract proccess, if all files were extracted successfuly?

Thanks again! and good job!  :Smilie:  :Thumb:

----------


## wqweto

Hi,

1. 7z.dll can compress/decompress zip files and only decompress rar files. There is a smaller version (7za.dll) of the 7-zip library that handles only 7z format.

2. Usually `Extract` method will return False. You can sink `Error` event too.

cheers,
</wqw>

----------


## sergelac

VszLib do not work when i compile the classes inside a normal EXE, the .7z file is smaller and corrupt
but it works when inside the IDE or when compiled inside a DLL, strange

----------


## wqweto

@sergelac: Probably threading issues. 7-zip spawns threads and does not care to initialize COM on these but insists on doing I/O on the supplied callback interfaces.

Never managed to make it stable in Standard Exe, so I'm using it as an ActiveX Dll in my apps. P-code compilation (always used in IDE) alleviates problems somehow but still is not production stable.

cheers,
</wqw>

----------


## mjohnlq

Very Very good work! 
I need 7z support for vb6 and find vszlib.
I only need  single thread to extract .7z file
So I only need use m_oInArchive.Extract, I needn't use pvWaitThread for mult threads.
So I think i can use it in Standard exe.
Thanks  wqweto.

----------


## mjohnlq

After I tried, I found vszlib can't extract exe file in 7z file.

----------


## wqweto

> After I tried, I found vszlib can't extract exe file in 7z file.


Did you try referencing the VszLib.dll (not using the sources)? What king of archive are you trying to extract from -- 7z, zip, rar?

cheers,
</wqw>

----------


## wqweto

> @ wqweto
> 
> Yes. Since your project deals primarily with adding support for the 7-Zip format for VB6, I thought, why not include Unicode-aware file handling as well? I've just tested the 7-Zip File Manager and it can deal with Unicode filenames pretty well. But of course, it's up to you if you want to implement it or not. Consider my _'request'_ as a suggestion only.


Unicode filename handling is implemented in latest version 1.0.2 -- mostly `CreateFile` and `Get/SetFileAttributes` are checking for unicode FS support.

It turns out zip file format has an extension for unicode filenames that 7-zip supports through `-mcu` parameter. I just also updated the sample showing how to set this parameter for creating unicode zips.

cheers,
</wqw>

----------


## Romeo91

wqweto, There is still a solution for std exe-project? With linking the library everything works fine. But, for me important to have a project without additional libraries
I also tried to add your code to my project. In the IDE, all works fine, but after compiling unpacking archive does not go.
If i try to use the same function as in the IDE, the program crashes

----------


## Schmidt

> wqweto, There is still a solution for std exe-project? With linking the library everything works fine. But, for me important to have a project without additional libraries
> I also tried to add your code to my project. In the IDE, all works fine, but after compiling unpacking archive does not go.
> If i try to use the same function as in the IDE, the program crashes


Are you aware of regfree-COM?
Using that you can ship your OCXes and Dlls alongside your compiled executable
for true XCopy-deployment of your App-Folder.

Olaf

----------


## Romeo91

I am creating a standalone-application (as portable). No installation and registration of components. From external files I only resources (language files and images). But while I use 7za.exe to work with 7z-archives

But it is an external application, not a library, and it does not have the ability to manage. The result of the application only error code. Implementation progress either.

While there is no desire to link VszLib.dll, since added another library to 7z.dll
Source code is accompanied by more difficult as you need to edit VszLib to add new features. Distribute the application will be more difficult as the final version of the library on the client side can be different

----------


## Schmidt

> I am creating a standalone-application (as portable).


Yep - directly running from e.g. an USB-Stick without any Setup - I know...

But this App is enclosed in an AppFolder on your USB-Stick e.g.:
[MyApp]
.... MyApp.exe
.... 7z.dll
.... [MyImageResources]
.... [MyLanguageResources]

So, where exactly (since you said, it works with the checked-in reference to the AX-Binary) 
is the problem with putting also VszLib.Dll beside MyApp.exe and 7z.dll, and use it within 
your App without registering it (or touching the registry at all)?

If you make (binary-compatiblility-breaking) changes on the COM-Interface of VszLib - 
then rename the Project-Internal LibName to VszLib2 - and compile the new Dll 
(with its new interface) to VszLib2.dll - then again - just place it (when deploying
your new version) beside your Exe - it will not collide with an existing VszLib.dll.

Your USB-Stick-Folder could then look like:
[MyApp]
.... MyApp.exe
.... 7z.dll
.... VszLib.dll
.... VszLib2.dll
.... [MyImageResources]
.... [MyLanguageResources]

And you could even reference and use both VszLib-Versions within your 
MyApp-Exe at the same time - as said, no registering would be needed, 
when you use the right tools (either manifest-based SxS-COM-instancing - 
or when you have to support machines below XP-targets, then DirectCOM.dll
can be used as well, to accomplish your regfree - and earlybound! - instancing).

Olaf

----------


## Romeo91

Is it possible to place the library is not next to a file in a subdirectory?
To get just such a structure.
[MyApp]
.... MyApp.exe
.... [Tools]\7z.dll
.... [Tools]\VszLib.dll
.... [Tools]\VszLib2.dll
.... [Tools]\[MyImageResources]
.... [Tools]\[MyLanguageResources]

7z.dll i can put in subfolder, vszlib has init procedure which specifies the location of the library.
But what about the library vszlib.dll?

----------


## Schmidt

You can put everything into a \Bin\ or a \Tools\ folder of course - in fact that's the way to go,
because it avoids (in case of OCXes) any attempts of a VB6-compiled -Executable, to try to 
dynamically register any OCXes it may find in its App.Path (it does this unasked and automatically
only for OCXes, not for ActiveX-Dlls - but that's not regfree-COM, but a dynamic registering-
attempt which could cause all kind of troubles on your system, when it succeeds, which is
mostly not the case anymore on System >= Vista due to UAC)

So, yeah - a separate SubFolder for your Binaries is definitely a good idea.
See also this thread here:
http://www.vbforums.com/showthread.p...=1#post4476329

As for usage of e.g. DirectCOM.dll for regfree-purposes:
There's an example how to use it on a Bin-Subfolder... On:
http://vbrichclient.com/#/en/Demos/GUI/
And there, the MandelBrotThreaded.7z (1.6MB) archive...

For your own regfree purposes you will not need the vbRichClient5.dll or the vb_cairo_sqlite.dll - 
just the small DirectCOM.dll is enough - just make sure that DirectCOM.dll is contained in 
your \Tools\ Folder alongside all other Dlls - and then preload DirectCOM.dll per LoadLibrary,
as shown in the Mandelbrot-Demo, before you make use of its GetInstance-Function.

Olaf

----------


## wqweto

@Romeo91: Unfortunately VszLib is not as stable as I would like it to be even as separate ActiveX DLL. 7-zip does not use COM multi-threading and VB6 has troubles with COM multi-threading let alone when COM is even not initialized on new threads. I don't think I can debug the issues with the current version of VszLib anymore.

The way I see it for all-VB6 wrapper component that can be using in Std EXEs is VB6+ASM. The multi-threading part has to injected ASM or always remain plagued with issues. (For instance current VszLib cannot produce RARs for whatever reason)

cheers,
</wqw>

----------


## diegosendra

Hi, we are planning starting some small VB6 implementation of a C++ propiertary set of DLLs. Basically at some point, we have to compress a set of files, produced by our own dlls, for which your <VszLib.dll> does an amazing work and saves having to code our GUI-based sample in something like C++ or C#, which is painful. We don't plan running any multi-thread or anything.

However, we have two questions. I've read VszLib.dll is not working well when being called from a compiled .exe. Can you please confirm is it the case even on a very small, single-threaded usage as we plan to do? It's important, because we will be distributing this demo and it will have to include both, your VszLib.dll and 7z.dll

Finally, please confirm if we have to accompany our demo with both, \src folder and 7-Zip source code. As far as I read both ar GNU/LGPL

Thanks
Diego





> @Romeo91: Unfortunately VszLib is not as stable as I would like it to be even as separate ActiveX DLL. 7-zip does not use COM multi-threading and VB6 has troubles with COM multi-threading let alone when COM is even not initialized on new threads. I don't think I can debug the issues with the current version of VszLib anymore.
> 
> The way I see it for all-VB6 wrapper component that can be using in Std EXEs is VB6+ASM. The multi-threading part has to injected ASM or always remain plagued with issues. (For instance current VszLib cannot produce RARs for whatever reason)
> 
> cheers,
> </wqw>

----------


## wqweto

@diegosendra: I'm using VszLib.dll in some of my compiled applications to compress/extract .7z archives with no problems as of now. Still some other formats are not stable enough (e.g. .rar support) but I don't plan on debugging these anymore.

For LGPL (Lesser GPL) you can redistribute binary .dll in your closed source application just fine. Even attribution in about box is optional.

The fun starts when you want to add features upon my source code -- you have to open source your new functionality as I did in first place. If you are not recompiling the library you are safe to redistribute VszLib in only binary, only source or both with your closed/open source solution.

HTH,
</wqw>

----------


## Tech99

property Get FileInfo in cVszArchive Class does not work as intended.
Originally returns only array of first file info.
Here is sample how to get filename(s) from compressed volume ie. .7z or other compressed file supported by 7-zip. 

Property Get FileInfo(ByVal FileIdx As Long) As Variant
    If FileIdx >= 0 And FileIdx < m_lCount Then
        With m_uFiles(FileIdx)
            'FileInfo = Array (.FileName, .Attributes, .Size, .Encrypted, .Crc, .Comment, .CreationTime, .LastAccessTime, .LastWriteTime)
            FileInfo = m_uFiles(FileIdx).FileName
        End With
    End If
End Property

----------


## Tech99

> property Get FileInfo in cVszArchive Class does not work as intended.
> Originally returns only array of first file info.
> Here is sample how to get filename(s) from compressed volume ie. .7z or other compressed file supported by 7-zip. 
> 
> Property Get FileInfo(ByVal FileIdx As Long) As Variant
>     If FileIdx >= 0 And FileIdx < m_lCount Then
>         With m_uFiles(FileIdx)
>             'FileInfo = Array (.FileName, .Attributes, .Size, .Encrypted, .Crc, .Comment, .CreationTime, .LastAccessTime, .LastWriteTime)
>             FileInfo = m_uFiles(FileIdx).FileName
> ...


to clarify comment and replace line
'FileInfo = Array (.FileName, .Attributes, .Size, .Encrypted, .Crc, .Comment, .CreationTime, .LastAccessTime, .LastWriteTime)

with
 FileInfo = m_uFiles(FileIdx).FileName

----------


## wqweto

> property Get FileInfo in cVszArchive Class does not work as intended.
> Originally returns only array of first file info.


It returns file info based on the parameter `FileIdx` -- that's what `With m_uFiles(FileIdx)` is about. You can get the file name by accessing the first element of each array like this: `sMyFileName = FileInfo(lIdx)(0)` will return the file name of file with index `lIdx`.

cheers,
</wqw>

----------


## RelaAlterEgo

Hi wqweto, hoping you're still here around  :Smilie: 
First of all, thanks for sharing this great project and code, it's really an useful and good source!  :Wink: 
Then, i have a problem: when i try to compress files larger than a certain size (for example > 5mb) vb6 ide hangs after compress method call from any vb6 project...
Looking for GitHub site, it seems that your project hasn't been updated from many time: now i don't know if you have spare time to look inside it and you want to, but if you will i really appreciate it!  :Smilie: 
Hovewer, thanks in advance!  :Wink:

----------


## wqweto

Hi RelaAlterEgo,

What output format do you produce? What version of 7-zip SDK do you use? Show some code around CompressArchive method call if possible.

I'm using VszLib with companion 7za.dll version 9.22 in production to compress DB backups larger than 5MB w/ no problems so far.

cheers,
</wqw>

----------


## RelaAlterEgo

> Hi RelaAlterEgo,
> 
> What output format do you produce? What version of 7-zip SDK do you use? Show some code around CompressArchive method call if possible.
> 
> I'm using VszLib with companion 7za.dll version 9.22 in production to compress DB backups larger than 5MB w/ no problems so far.
> 
> cheers,
> </wqw>


Hi wqweto, and thanks for quick reply!  :Wink: 
Output format is 7zip archive (.7z) and i don't install any 7-zip SDK source, i only downloaded 7zip packages on official site, copy 7z.dll or 7za.dll into src folder inside your sample project; setting compression level to ultra (switch -mx9), when i try to compress an xml file of 5.5mb with 9.20 dll version, vb application hangs, while with fastest or fast compression (-mx1 or -mx3) works...If i don't set 'm' parameter application hangs, too. Tried with latest 7z.dll / 7za.dll 16.04), hangs hovewer, omitting parametter setting or with -mx1 and -mx3, too.
This is code i use:



```
Private Sub cmdCompress_Click()
    With New cVszArchive
        .AddFile App.Path & "\database.xml" 'XML FILE SIZE=5.5MB
        'NOTE: OMITTING FOLLOWING INSTRUCTION CAUSE APPLICATION HANGING WITH BOTH 7z/7za.dll 9.20 AND 7z/7za.dll 16.04 ON CompressArchive CALL
        .Parameter("x") = 3 '-- CompressionLevel = Fast - WORKING WITH 7z/7za.dll 9.20, HANGING WITH 7z/7za.dll 16.04 ON CompressArchive CALL
        '.Parameter("x") = 9 '-- CompressionLevel = Ultra - HANGING WITH BOTH 7z/7za.dll 9.20 AND 7z/7za.dll 16.04 ON CompressArchive CALL
        .CompressArchive App.Path & "\test.7z"
    End With
    MsgBox "test.7z created ok", vbExclamation
End Sub
```

Again, thanks!  :Wink:

----------


## Tech99

Currently does not extract .rar packages. Vszlib reports .Filecount as zero (0) for rar package.
7z.dll version 18.5.0.0 (18.4.2018) 



```
    With New cVszArchive
        .Init Makepath(App.Path, "7z.dll")
        .OpenArchive SevenZipFile 'file name tested test.rar
        
  Debug.Print .FileCount

        .Extract App.Path & "\Unpacked"
    End With
```

7zip file manager opens and extracts rar file OK.

----------


## wqweto

@Tech99: I haven't tweaked this project past 7-zip 9.22 and it degraded even further with each new version of the parent project.

The original effort was plagued with threading problems I'm unable to resolve and unwilling to debug further.

An idea I have is for the I/O class to be rewritten in VbRtcc if possible.

cheers,
</wqw>

----------


## Tech99

> @Tech99: I haven't tweaked this project past 7-zip 9.22 and it degraded even further with each new version of the parent project.
> 
> The original effort was plagued with threading problems I'm unable to resolve and unwilling to debug further.
> 
> An idea I have is for the I/O class to be rewritten in VbRtcc if possible.
> 
> cheers,
> </wqw>


Thanks wqweto, looked your VbRTcc project - very interesting, however found it quicker to modify app by calling 7z.exe using CreatePipe, CreateProcessA, Readfile functions (ie. getting stdout response from 7z.exe).

btw. That problematic rar file was rar5 format.

----------


## Mith

i opened the file "test.tar.gz" and i get a filecount=1 but .fileinfo(1) with the name of the tar-file is empty.
using .Extract App.Path & "\Unpacked" creates a file with the corrrect tar-file-name but 0 bytes.

any idea how to fix that?

btw: the original 7zip-app can open the file "test.tar.gz" and list the name of the tar file and further list all the files inside the tar file.

----------


## wqweto

Try using 7z.dll from 7-zip version 9.22 not the latest.

This might still not work though. . .

Did you know there is built-in *tar.exe* in latest versions of Win10?

Use c:> tar -czf d:\temp\aaa.tar.gz *.json to compress.

Use c:> tar -xzf d:\temp\aaa.tar.gz to uncompress.

cheers,
</wqw>

----------


## Mith

i downloaded the 7z package v9.22 and used the older 7z.dll with your test project but the file name if still empty:



but with "extract" i can extract the tar file from inside the gz file with the correct filename!

any ideas whats wrong here?

----------


## wqweto

> any ideas whats wrong here?


This is by design. GNU zip (the .gz extension) file format is a single file compression format that does *not* store original filename/date or any other info. The original filename by convention is everything before the .gz suffix, i.e. in your case the openfp-1.3.2(1).tar is the best guess what target filename should be.

After decompressing the .gz to a .tar you can use 7-zip to untar this "tape archive" to a destination folder. TAR file format includes files and directories structure in contrast to .gz and that's why both of these are used in tandem to create "solid" archives of whole directories of files.

cheers,
</wqw>
p.s. Sorry for the late reply.

----------


## xiaoyao

dear wqweto:
i have 4 questtions:
how to add folder to make a "*.7z" file?
how to  Add comment text？

how to Extract a file to byte() like:dim buffer() as byte
how to check *.7z file have password?

thank you for your help

----------


## wqweto

> how to add folder to make a "*.7z" file?

You want to make a single 7z file with the contents of a folder or compress each file in a folder to a separate 7z archive?

Take a look add the AddFile(File As String, [Name As String], [Comment As String]) As Boolean method. File is the filename on disk e.g. c:\path\tp\myfiles.doc while the optional Name is the name this file will get in the archive e.g. myfolder/report.doc and Comment is an optional text associated w/ the entry (which might not be supported by all archive types).

> how to Extract a file to byte() like:dim buffer() as byte

Nothing built-in. (This is not as versatile as the ZipArchive class.)

> how to check *.7z file have password?

7-zip has a very rudimentary way to check archive password. If a password is required for an operation (list, extract, whatever) it raises an error with "Data Error. Wrong password?" error message. Have to capture this and provide value in Password property.

cheers,
</wqw>

----------


## xiaoyao

My question now is:
I want to generate a 7z or zip format compressed file, open it to show the comments, not for each file comments.
In addition, if you can directly add the entire directory, into a compressed file is the best.
This I can also achieve through the code.
Now the question is, how do I add an empty folder to the zip file?
Can you upgrade it to support the revision of compressed files, delete the inside part of the document, folder.
Also whether you can set the file list does not display, only enter the password can be displayed.
What's the easiest way to check if a zip file has a password?
Instead of unzipping the file and receiving an error message that contains a password.
The translation software is not accurate, attach the original Chinese：我现在的问题是:
我要生成一个7z或者zip格式压缩文件，打开之后就显示注释，不是针对每个文件的注释。
另外如果可以直接添加整个目录，变成一个压缩文件就是最好了。
这个我也可以自己通过代码实现。
现在问题是，如何添加一个空文件夹到压缩文档？
可不可以升级一下，支持修改压缩文件，删除里面的部分文件，文件夹。
另外是否可以设置不显示文件列表，只有输入密码才可以显示。
有什么最简单的方法检测一个压缩文件是否有密码？
而不是通过解压文件收到错误信息才能知道包含了密码。

----------


## wqweto

You are on your own to implement any or all of these requirements. If you find any issues with the project feel free to share them here.

Good luck!
</wqw>

----------


## L'mars

*Hello WQWETO*  :wave: 

Can your code be used to create tar files? 

I have the problem of packing multiple XML files with TAR format.

I am using the language Visual Basic 6, with which I create from one to less than 500 XML files, to later want to pack them with the TAR format, generating a file called *package.tar*, which in turn I will have to compress with GZIP to finally build a file called *package.tar.gz*

I tried the code of this website https://github.com/wqweto/VszLib, but I can only create files called package.7z

Or do you know other ways to do it, for example with dll libraries made with C++?  :Ehh: 

Thanks for the space to consult you.

----------


## wqweto

> *Hello WQWETO* 
> 
> Can your code be used to create tar files? 
> 
> I have the problem of packing multiple XML files with TAR format.
> 
> I am using the language Visual Basic 6, with which I create from one to less than 500 XML files, to later want to pack them with the TAR format, generating a file called *package.tar*, which in turn I will have to compress with GZIP to finally build a file called *package.tar.gz*
> 
> I tried the code of this website https://github.com/wqweto/VszLib, but I can only create files called package.7z
> ...


I don't think 7-zip has support for *compressing* in tar.gz format, most probably only extraction is available.

The good news is there is a copy of tar.exe utility bundled with every instance of Windows 10 already since a couple of years now, so you have to figure out its command-line options only :-))

Try this:

C:\> tar -cvzf C:\TARS\sqlbackup.tar.gz *.sql

cheers,
</wqw>

----------


## wqweto

> I don't think 7-zip has support for *compressing* in tar.gz format, most probably only extraction is available.


No, 7-zip supports both .tar and .gz and both compression and decompression. Replied with more details to your other thread.

cheers,
</wqw>

----------


## L'mars

Hi  :Smilie: 
 That command line looks interesting, how can I use it in Visual Basic 6?, In the 'Immediate' window?, How do you use the tar.exe? 

   I thank you for solving my doubt in the question I asked here: https://www.vbforums.com/showthread....Visual-Basic-6, I was almost about to have to relearn C++ or Java to make libraries and I don't know what else, to find the best way to get it afloat.

   Thank you, go ahead, I wish you all the best, if I have another question in the future I will let you know, sorry for the inconvenience. 

  L'mars

----------

