Compiling the zlib compression library with Visual Studio 2013

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.

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)

Visual Basic

1

2

3

4

5

6

7

8

PrivateDeclareFunctioncompress Lib"zlibwapi32.dll"_

(ByValsRetBuffer AsString,ByReflRetBufLen AsLong,_

ByValsInBuffer AsString,ByVallBufLen AsLong,_

)AsLong

PrivateDeclareFunctionuncompress Lib"zlibwapi32.dll"_

(ByValsRetBuffer AsString,ByReflRetBufLen AsLong,_

ByValsInBuffer AsString,ByVallBufLen AsLong,_

)AsLong

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!