annotate src/zlib-1.2.7/win32/DLL_FAQ.txt @ 169:223a55898ab9 tip default

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