annotate src/zlib-1.2.8/win32/DLL_FAQ.txt @ 81:7029a4916348

Merge build update
author Chris Cannam
date Thu, 31 Oct 2019 13:36:58 +0000
parents 5ea0608b923f
children
rev   line source
Chris@43 1
Chris@43 2 Frequently Asked Questions about ZLIB1.DLL
Chris@43 3
Chris@43 4
Chris@43 5 This document describes the design, the rationale, and the usage
Chris@43 6 of the official DLL build of zlib, named ZLIB1.DLL. If you have
Chris@43 7 general questions about zlib, you should see the file "FAQ" found
Chris@43 8 in the zlib distribution, or at the following location:
Chris@43 9 http://www.gzip.org/zlib/zlib_faq.html
Chris@43 10
Chris@43 11
Chris@43 12 1. What is ZLIB1.DLL, and how can I get it?
Chris@43 13
Chris@43 14 - ZLIB1.DLL is the official build of zlib as a DLL.
Chris@43 15 (Please remark the character '1' in the name.)
Chris@43 16
Chris@43 17 Pointers to a precompiled ZLIB1.DLL can be found in the zlib
Chris@43 18 web site at:
Chris@43 19 http://www.zlib.net/
Chris@43 20
Chris@43 21 Applications that link to ZLIB1.DLL can rely on the following
Chris@43 22 specification:
Chris@43 23
Chris@43 24 * The exported symbols are exclusively defined in the source
Chris@43 25 files "zlib.h" and "zlib.def", found in an official zlib
Chris@43 26 source distribution.
Chris@43 27 * The symbols are exported by name, not by ordinal.
Chris@43 28 * The exported names are undecorated.
Chris@43 29 * The calling convention of functions is "C" (CDECL).
Chris@43 30 * The ZLIB1.DLL binary is linked to MSVCRT.DLL.
Chris@43 31
Chris@43 32 The archive in which ZLIB1.DLL is bundled contains compiled
Chris@43 33 test programs that must run with a valid build of ZLIB1.DLL.
Chris@43 34 It is recommended to download the prebuilt DLL from the zlib
Chris@43 35 web site, instead of building it yourself, to avoid potential
Chris@43 36 incompatibilities that could be introduced by your compiler
Chris@43 37 and build settings. If you do build the DLL yourself, please
Chris@43 38 make sure that it complies with all the above requirements,
Chris@43 39 and it runs with the precompiled test programs, bundled with
Chris@43 40 the original ZLIB1.DLL distribution.
Chris@43 41
Chris@43 42 If, for any reason, you need to build an incompatible DLL,
Chris@43 43 please use a different file name.
Chris@43 44
Chris@43 45
Chris@43 46 2. Why did you change the name of the DLL to ZLIB1.DLL?
Chris@43 47 What happened to the old ZLIB.DLL?
Chris@43 48
Chris@43 49 - The old ZLIB.DLL, built from zlib-1.1.4 or earlier, required
Chris@43 50 compilation settings that were incompatible to those used by
Chris@43 51 a static build. The DLL settings were supposed to be enabled
Chris@43 52 by defining the macro ZLIB_DLL, before including "zlib.h".
Chris@43 53 Incorrect handling of this macro was silently accepted at
Chris@43 54 build time, resulting in two major problems:
Chris@43 55
Chris@43 56 * ZLIB_DLL was missing from the old makefile. When building
Chris@43 57 the DLL, not all people added it to the build options. In
Chris@43 58 consequence, incompatible incarnations of ZLIB.DLL started
Chris@43 59 to circulate around the net.
Chris@43 60
Chris@43 61 * When switching from using the static library to using the
Chris@43 62 DLL, applications had to define the ZLIB_DLL macro and
Chris@43 63 to recompile all the sources that contained calls to zlib
Chris@43 64 functions. Failure to do so resulted in creating binaries
Chris@43 65 that were unable to run with the official ZLIB.DLL build.
Chris@43 66
Chris@43 67 The only possible solution that we could foresee was to make
Chris@43 68 a binary-incompatible change in the DLL interface, in order to
Chris@43 69 remove the dependency on the ZLIB_DLL macro, and to release
Chris@43 70 the new DLL under a different name.
Chris@43 71
Chris@43 72 We chose the name ZLIB1.DLL, where '1' indicates the major
Chris@43 73 zlib version number. We hope that we will not have to break
Chris@43 74 the binary compatibility again, at least not as long as the
Chris@43 75 zlib-1.x series will last.
Chris@43 76
Chris@43 77 There is still a ZLIB_DLL macro, that can trigger a more
Chris@43 78 efficient build and use of the DLL, but compatibility no
Chris@43 79 longer dependents on it.
Chris@43 80
Chris@43 81
Chris@43 82 3. Can I build ZLIB.DLL from the new zlib sources, and replace
Chris@43 83 an old ZLIB.DLL, that was built from zlib-1.1.4 or earlier?
Chris@43 84
Chris@43 85 - In principle, you can do it by assigning calling convention
Chris@43 86 keywords to the macros ZEXPORT and ZEXPORTVA. In practice,
Chris@43 87 it depends on what you mean by "an old ZLIB.DLL", because the
Chris@43 88 old DLL exists in several mutually-incompatible versions.
Chris@43 89 You have to find out first what kind of calling convention is
Chris@43 90 being used in your particular ZLIB.DLL build, and to use the
Chris@43 91 same one in the new build. If you don't know what this is all
Chris@43 92 about, you might be better off if you would just leave the old
Chris@43 93 DLL intact.
Chris@43 94
Chris@43 95
Chris@43 96 4. Can I compile my application using the new zlib interface, and
Chris@43 97 link it to an old ZLIB.DLL, that was built from zlib-1.1.4 or
Chris@43 98 earlier?
Chris@43 99
Chris@43 100 - The official answer is "no"; the real answer depends again on
Chris@43 101 what kind of ZLIB.DLL you have. Even if you are lucky, this
Chris@43 102 course of action is unreliable.
Chris@43 103
Chris@43 104 If you rebuild your application and you intend to use a newer
Chris@43 105 version of zlib (post- 1.1.4), it is strongly recommended to
Chris@43 106 link it to the new ZLIB1.DLL.
Chris@43 107
Chris@43 108
Chris@43 109 5. Why are the zlib symbols exported by name, and not by ordinal?
Chris@43 110
Chris@43 111 - Although exporting symbols by ordinal is a little faster, it
Chris@43 112 is risky. Any single glitch in the maintenance or use of the
Chris@43 113 DEF file that contains the ordinals can result in incompatible
Chris@43 114 builds and frustrating crashes. Simply put, the benefits of
Chris@43 115 exporting symbols by ordinal do not justify the risks.
Chris@43 116
Chris@43 117 Technically, it should be possible to maintain ordinals in
Chris@43 118 the DEF file, and still export the symbols by name. Ordinals
Chris@43 119 exist in every DLL, and even if the dynamic linking performed
Chris@43 120 at the DLL startup is searching for names, ordinals serve as
Chris@43 121 hints, for a faster name lookup. However, if the DEF file
Chris@43 122 contains ordinals, the Microsoft linker automatically builds
Chris@43 123 an implib that will cause the executables linked to it to use
Chris@43 124 those ordinals, and not the names. It is interesting to
Chris@43 125 notice that the GNU linker for Win32 does not suffer from this
Chris@43 126 problem.
Chris@43 127
Chris@43 128 It is possible to avoid the DEF file if the exported symbols
Chris@43 129 are accompanied by a "__declspec(dllexport)" attribute in the
Chris@43 130 source files. You can do this in zlib by predefining the
Chris@43 131 ZLIB_DLL macro.
Chris@43 132
Chris@43 133
Chris@43 134 6. I see that the ZLIB1.DLL functions use the "C" (CDECL) calling
Chris@43 135 convention. Why not use the STDCALL convention?
Chris@43 136 STDCALL is the standard convention in Win32, and I need it in
Chris@43 137 my Visual Basic project!
Chris@43 138
Chris@43 139 (For readability, we use CDECL to refer to the convention
Chris@43 140 triggered by the "__cdecl" keyword, STDCALL to refer to
Chris@43 141 the convention triggered by "__stdcall", and FASTCALL to
Chris@43 142 refer to the convention triggered by "__fastcall".)
Chris@43 143
Chris@43 144 - Most of the native Windows API functions (without varargs) use
Chris@43 145 indeed the WINAPI convention (which translates to STDCALL in
Chris@43 146 Win32), but the standard C functions use CDECL. If a user
Chris@43 147 application is intrinsically tied to the Windows API (e.g.
Chris@43 148 it calls native Windows API functions such as CreateFile()),
Chris@43 149 sometimes it makes sense to decorate its own functions with
Chris@43 150 WINAPI. But if ANSI C or POSIX portability is a goal (e.g.
Chris@43 151 it calls standard C functions such as fopen()), it is not a
Chris@43 152 sound decision to request the inclusion of <windows.h>, or to
Chris@43 153 use non-ANSI constructs, for the sole purpose to make the user
Chris@43 154 functions STDCALL-able.
Chris@43 155
Chris@43 156 The functionality offered by zlib is not in the category of
Chris@43 157 "Windows functionality", but is more like "C functionality".
Chris@43 158
Chris@43 159 Technically, STDCALL is not bad; in fact, it is slightly
Chris@43 160 faster than CDECL, and it works with variable-argument
Chris@43 161 functions, just like CDECL. It is unfortunate that, in spite
Chris@43 162 of using STDCALL in the Windows API, it is not the default
Chris@43 163 convention used by the C compilers that run under Windows.
Chris@43 164 The roots of the problem reside deep inside the unsafety of
Chris@43 165 the K&R-style function prototypes, where the argument types
Chris@43 166 are not specified; but that is another story for another day.
Chris@43 167
Chris@43 168 The remaining fact is that CDECL is the default convention.
Chris@43 169 Even if an explicit convention is hard-coded into the function
Chris@43 170 prototypes inside C headers, problems may appear. The
Chris@43 171 necessity to expose the convention in users' callbacks is one
Chris@43 172 of these problems.
Chris@43 173
Chris@43 174 The calling convention issues are also important when using
Chris@43 175 zlib in other programming languages. Some of them, like Ada
Chris@43 176 (GNAT) and Fortran (GNU G77), have C bindings implemented
Chris@43 177 initially on Unix, and relying on the C calling convention.
Chris@43 178 On the other hand, the pre- .NET versions of Microsoft Visual
Chris@43 179 Basic require STDCALL, while Borland Delphi prefers, although
Chris@43 180 it does not require, FASTCALL.
Chris@43 181
Chris@43 182 In fairness to all possible uses of zlib outside the C
Chris@43 183 programming language, we choose the default "C" convention.
Chris@43 184 Anyone interested in different bindings or conventions is
Chris@43 185 encouraged to maintain specialized projects. The "contrib/"
Chris@43 186 directory from the zlib distribution already holds a couple
Chris@43 187 of foreign bindings, such as Ada, C++, and Delphi.
Chris@43 188
Chris@43 189
Chris@43 190 7. I need a DLL for my Visual Basic project. What can I do?
Chris@43 191
Chris@43 192 - Define the ZLIB_WINAPI macro before including "zlib.h", when
Chris@43 193 building both the DLL and the user application (except that
Chris@43 194 you don't need to define anything when using the DLL in Visual
Chris@43 195 Basic). The ZLIB_WINAPI macro will switch on the WINAPI
Chris@43 196 (STDCALL) convention. The name of this DLL must be different
Chris@43 197 than the official ZLIB1.DLL.
Chris@43 198
Chris@43 199 Gilles Vollant has contributed a build named ZLIBWAPI.DLL,
Chris@43 200 with the ZLIB_WINAPI macro turned on, and with the minizip
Chris@43 201 functionality built in. For more information, please read
Chris@43 202 the notes inside "contrib/vstudio/readme.txt", found in the
Chris@43 203 zlib distribution.
Chris@43 204
Chris@43 205
Chris@43 206 8. I need to use zlib in my Microsoft .NET project. What can I
Chris@43 207 do?
Chris@43 208
Chris@43 209 - Henrik Ravn has contributed a .NET wrapper around zlib. Look
Chris@43 210 into contrib/dotzlib/, inside the zlib distribution.
Chris@43 211
Chris@43 212
Chris@43 213 9. If my application uses ZLIB1.DLL, should I link it to
Chris@43 214 MSVCRT.DLL? Why?
Chris@43 215
Chris@43 216 - It is not required, but it is recommended to link your
Chris@43 217 application to MSVCRT.DLL, if it uses ZLIB1.DLL.
Chris@43 218
Chris@43 219 The executables (.EXE, .DLL, etc.) that are involved in the
Chris@43 220 same process and are using the C run-time library (i.e. they
Chris@43 221 are calling standard C functions), must link to the same
Chris@43 222 library. There are several libraries in the Win32 system:
Chris@43 223 CRTDLL.DLL, MSVCRT.DLL, the static C libraries, etc.
Chris@43 224 Since ZLIB1.DLL is linked to MSVCRT.DLL, the executables that
Chris@43 225 depend on it should also be linked to MSVCRT.DLL.
Chris@43 226
Chris@43 227
Chris@43 228 10. Why are you saying that ZLIB1.DLL and my application should
Chris@43 229 be linked to the same C run-time (CRT) library? I linked my
Chris@43 230 application and my DLLs to different C libraries (e.g. my
Chris@43 231 application to a static library, and my DLLs to MSVCRT.DLL),
Chris@43 232 and everything works fine.
Chris@43 233
Chris@43 234 - If a user library invokes only pure Win32 API (accessible via
Chris@43 235 <windows.h> and the related headers), its DLL build will work
Chris@43 236 in any context. But if this library invokes standard C API,
Chris@43 237 things get more complicated.
Chris@43 238
Chris@43 239 There is a single Win32 library in a Win32 system. Every
Chris@43 240 function in this library resides in a single DLL module, that
Chris@43 241 is safe to call from anywhere. On the other hand, there are
Chris@43 242 multiple versions of the C library, and each of them has its
Chris@43 243 own separate internal state. Standalone executables and user
Chris@43 244 DLLs that call standard C functions must link to a C run-time
Chris@43 245 (CRT) library, be it static or shared (DLL). Intermixing
Chris@43 246 occurs when an executable (not necessarily standalone) and a
Chris@43 247 DLL are linked to different CRTs, and both are running in the
Chris@43 248 same process.
Chris@43 249
Chris@43 250 Intermixing multiple CRTs is possible, as long as their
Chris@43 251 internal states are kept intact. The Microsoft Knowledge Base
Chris@43 252 articles KB94248 "HOWTO: Use the C Run-Time" and KB140584
Chris@43 253 "HOWTO: Link with the Correct C Run-Time (CRT) Library"
Chris@43 254 mention the potential problems raised by intermixing.
Chris@43 255
Chris@43 256 If intermixing works for you, it's because your application
Chris@43 257 and DLLs are avoiding the corruption of each of the CRTs'
Chris@43 258 internal states, maybe by careful design, or maybe by fortune.
Chris@43 259
Chris@43 260 Also note that linking ZLIB1.DLL to non-Microsoft CRTs, such
Chris@43 261 as those provided by Borland, raises similar problems.
Chris@43 262
Chris@43 263
Chris@43 264 11. Why are you linking ZLIB1.DLL to MSVCRT.DLL?
Chris@43 265
Chris@43 266 - MSVCRT.DLL exists on every Windows 95 with a new service pack
Chris@43 267 installed, or with Microsoft Internet Explorer 4 or later, and
Chris@43 268 on all other Windows 4.x or later (Windows 98, Windows NT 4,
Chris@43 269 or later). It is freely distributable; if not present in the
Chris@43 270 system, it can be downloaded from Microsoft or from other
Chris@43 271 software provider for free.
Chris@43 272
Chris@43 273 The fact that MSVCRT.DLL does not exist on a virgin Windows 95
Chris@43 274 is not so problematic. Windows 95 is scarcely found nowadays,
Chris@43 275 Microsoft ended its support a long time ago, and many recent
Chris@43 276 applications from various vendors, including Microsoft, do not
Chris@43 277 even run on it. Furthermore, no serious user should run
Chris@43 278 Windows 95 without a proper update installed.
Chris@43 279
Chris@43 280
Chris@43 281 12. Why are you not linking ZLIB1.DLL to
Chris@43 282 <<my favorite C run-time library>> ?
Chris@43 283
Chris@43 284 - We considered and abandoned the following alternatives:
Chris@43 285
Chris@43 286 * Linking ZLIB1.DLL to a static C library (LIBC.LIB, or
Chris@43 287 LIBCMT.LIB) is not a good option. People are using the DLL
Chris@43 288 mainly to save disk space. If you are linking your program
Chris@43 289 to a static C library, you may as well consider linking zlib
Chris@43 290 in statically, too.
Chris@43 291
Chris@43 292 * Linking ZLIB1.DLL to CRTDLL.DLL looks appealing, because
Chris@43 293 CRTDLL.DLL is present on every Win32 installation.
Chris@43 294 Unfortunately, it has a series of problems: it does not
Chris@43 295 work properly with Microsoft's C++ libraries, it does not
Chris@43 296 provide support for 64-bit file offsets, (and so on...),
Chris@43 297 and Microsoft discontinued its support a long time ago.
Chris@43 298
Chris@43 299 * Linking ZLIB1.DLL to MSVCR70.DLL or MSVCR71.DLL, supplied
Chris@43 300 with the Microsoft .NET platform, and Visual C++ 7.0/7.1,
Chris@43 301 raises problems related to the status of ZLIB1.DLL as a
Chris@43 302 system component. According to the Microsoft Knowledge Base
Chris@43 303 article KB326922 "INFO: Redistribution of the Shared C
Chris@43 304 Runtime Component in Visual C++ .NET", MSVCR70.DLL and
Chris@43 305 MSVCR71.DLL are not supposed to function as system DLLs,
Chris@43 306 because they may clash with MSVCRT.DLL. Instead, the
Chris@43 307 application's installer is supposed to put these DLLs
Chris@43 308 (if needed) in the application's private directory.
Chris@43 309 If ZLIB1.DLL depends on a non-system runtime, it cannot
Chris@43 310 function as a redistributable system component.
Chris@43 311
Chris@43 312 * Linking ZLIB1.DLL to non-Microsoft runtimes, such as
Chris@43 313 Borland's, or Cygwin's, raises problems related to the
Chris@43 314 reliable presence of these runtimes on Win32 systems.
Chris@43 315 It's easier to let the DLL build of zlib up to the people
Chris@43 316 who distribute these runtimes, and who may proceed as
Chris@43 317 explained in the answer to Question 14.
Chris@43 318
Chris@43 319
Chris@43 320 13. If ZLIB1.DLL cannot be linked to MSVCR70.DLL or MSVCR71.DLL,
Chris@43 321 how can I build/use ZLIB1.DLL in Microsoft Visual C++ 7.0
Chris@43 322 (Visual Studio .NET) or newer?
Chris@43 323
Chris@43 324 - Due to the problems explained in the Microsoft Knowledge Base
Chris@43 325 article KB326922 (see the previous answer), the C runtime that
Chris@43 326 comes with the VC7 environment is no longer considered a
Chris@43 327 system component. That is, it should not be assumed that this
Chris@43 328 runtime exists, or may be installed in a system directory.
Chris@43 329 Since ZLIB1.DLL is supposed to be a system component, it may
Chris@43 330 not depend on a non-system component.
Chris@43 331
Chris@43 332 In order to link ZLIB1.DLL and your application to MSVCRT.DLL
Chris@43 333 in VC7, you need the library of Visual C++ 6.0 or older. If
Chris@43 334 you don't have this library at hand, it's probably best not to
Chris@43 335 use ZLIB1.DLL.
Chris@43 336
Chris@43 337 We are hoping that, in the future, Microsoft will provide a
Chris@43 338 way to build applications linked to a proper system runtime,
Chris@43 339 from the Visual C++ environment. Until then, you have a
Chris@43 340 couple of alternatives, such as linking zlib in statically.
Chris@43 341 If your application requires dynamic linking, you may proceed
Chris@43 342 as explained in the answer to Question 14.
Chris@43 343
Chris@43 344
Chris@43 345 14. I need to link my own DLL build to a CRT different than
Chris@43 346 MSVCRT.DLL. What can I do?
Chris@43 347
Chris@43 348 - Feel free to rebuild the DLL from the zlib sources, and link
Chris@43 349 it the way you want. You should, however, clearly state that
Chris@43 350 your build is unofficial. You should give it a different file
Chris@43 351 name, and/or install it in a private directory that can be
Chris@43 352 accessed by your application only, and is not visible to the
Chris@43 353 others (i.e. it's neither in the PATH, nor in the SYSTEM or
Chris@43 354 SYSTEM32 directories). Otherwise, your build may clash with
Chris@43 355 applications that link to the official build.
Chris@43 356
Chris@43 357 For example, in Cygwin, zlib is linked to the Cygwin runtime
Chris@43 358 CYGWIN1.DLL, and it is distributed under the name CYGZ.DLL.
Chris@43 359
Chris@43 360
Chris@43 361 15. May I include additional pieces of code that I find useful,
Chris@43 362 link them in ZLIB1.DLL, and export them?
Chris@43 363
Chris@43 364 - No. A legitimate build of ZLIB1.DLL must not include code
Chris@43 365 that does not originate from the official zlib source code.
Chris@43 366 But you can make your own private DLL build, under a different
Chris@43 367 file name, as suggested in the previous answer.
Chris@43 368
Chris@43 369 For example, zlib is a part of the VCL library, distributed
Chris@43 370 with Borland Delphi and C++ Builder. The DLL build of VCL
Chris@43 371 is a redistributable file, named VCLxx.DLL.
Chris@43 372
Chris@43 373
Chris@43 374 16. May I remove some functionality out of ZLIB1.DLL, by enabling
Chris@43 375 macros like NO_GZCOMPRESS or NO_GZIP at compile time?
Chris@43 376
Chris@43 377 - No. A legitimate build of ZLIB1.DLL must provide the complete
Chris@43 378 zlib functionality, as implemented in the official zlib source
Chris@43 379 code. But you can make your own private DLL build, under a
Chris@43 380 different file name, as suggested in the previous answer.
Chris@43 381
Chris@43 382
Chris@43 383 17. I made my own ZLIB1.DLL build. Can I test it for compliance?
Chris@43 384
Chris@43 385 - We prefer that you download the official DLL from the zlib
Chris@43 386 web site. If you need something peculiar from this DLL, you
Chris@43 387 can send your suggestion to the zlib mailing list.
Chris@43 388
Chris@43 389 However, in case you do rebuild the DLL yourself, you can run
Chris@43 390 it with the test programs found in the DLL distribution.
Chris@43 391 Running these test programs is not a guarantee of compliance,
Chris@43 392 but a failure can imply a detected problem.
Chris@43 393
Chris@43 394 **
Chris@43 395
Chris@43 396 This document is written and maintained by
Chris@43 397 Cosmin Truta <cosmint@cs.ubbcluj.ro>