I you need zip compression in your development project, the zlib library is a good and free solution.
There’s however a bit of googling necessary to achieve a successful compilation with VS2013, especially for generating the 32 bits version of the library.
As I just needed it for some VB/VBA integration, I had to sort out a lot of outdated and not really useful information, for a simple solution, after all.
So here’s my receipe which will help you save some time, I hope, if you’re on the same track.
Update #2, 11/12/2013, here are my compiled binaries, zlibwapi32.dll and zlib64.dll in this zip archive, MD5: eb8932beb0360b42c6cdd1ccd79745ad
Download the library source code here: http://www.zlib.net, then:
- Uncompress the archive (in my case zlib-1.2.8.zip), you’ll find a zlibvc.sln file in the contribvstudiovc11 subfolder, that you can open with vs2013 (let it do its conversion stuff);
- The annoying part comes if you’re compiling against a Win32 target, because you then have to specify an additional linker command line switch /SAFESEH:NO. Right-click the zlibvc project and open its property pages:

- Do the same for the testzlib project
- Give it a go.
For the Win64 version, the linker switch does not apply, just go directly to the build process.
Note that you’ll end up with a zlibwapi.dll file that you can use with your vb/vba projects.
I did compile 32 and 64 bits versions of the library, and I renamed them zlibwapi32.dll and zlibwapi64.dll to avoid confusion; here are the declares for the 32 bits version:
(Updated 11/12/2013)
|
1 2 3 4 5 6 7 8 |
Private Declare Function compress Lib "zlibwapi32.dll" _ (ByVal sRetBuffer As String, ByRef lRetBufLen As Long, _ ByVal sInBuffer As String, ByVal lBufLen As Long, _ ) As Long Private Declare Function uncompress Lib "zlibwapi32.dll" _ (ByVal sRetBuffer As String, ByRef lRetBufLen As Long, _ ByVal sInBuffer As String, ByVal lBufLen As Long, _ ) As Long |
It’s then quite easy to figure out how to use the functions in your C/C++/VB/Whatever projects, samples are included with the library, but for VB/VBA, here is an excellent introduction from Mike D Sutton: http://edais.mvps.org/Tutorials/ZLib/index.html .
Happy zipping!
With VS2017 I could not get the code to build, both due to the version number problem mentioned by Davy above, and also to SAFESEH errors from the linker. The solution to those is given at
https://stackoverflow.com/questions/10599940/module-unsafe-for-safeseh-image-c
Before making those changes I removed the ASMV and ASMINF preprocessor defines, and that also perhaps was a factor in solving the problem (haven’t time just now to try adding them back to see if things still work).
Thanks Davy, I just tried it again and hit the same issue. With your fix it works again. Nice.
I got the LNK1118 error because of the version number which is in the DEF file (completely obsolete now). The solution is to remove the last number
1.2.8 becomes 1.2
Only two numbers – major.minor – are supported in a DEF file.