kusano 7d535a
kusano 7d535a
            Frequently Asked Questions about ZLIB1.DLL
kusano 7d535a
kusano 7d535a
kusano 7d535a
This document describes the design, the rationale, and the usage
kusano 7d535a
of the official DLL build of zlib, named ZLIB1.DLL.  If you have
kusano 7d535a
general questions about zlib, you should see the file "FAQ" found
kusano 7d535a
in the zlib distribution, or at the following location:
kusano 7d535a
  http://www.gzip.org/zlib/zlib_faq.html
kusano 7d535a
kusano 7d535a
kusano 7d535a
 1. What is ZLIB1.DLL, and how can I get it?
kusano 7d535a
kusano 7d535a
  - ZLIB1.DLL is the official build of zlib as a DLL.
kusano 7d535a
    (Please remark the character '1' in the name.)
kusano 7d535a
kusano 7d535a
    Pointers to a precompiled ZLIB1.DLL can be found in the zlib
kusano 7d535a
    web site at:
kusano 7d535a
      http://www.zlib.net/
kusano 7d535a
kusano 7d535a
    Applications that link to ZLIB1.DLL can rely on the following
kusano 7d535a
    specification:
kusano 7d535a
kusano 7d535a
    * The exported symbols are exclusively defined in the source
kusano 7d535a
      files "zlib.h" and "zlib.def", found in an official zlib
kusano 7d535a
      source distribution.
kusano 7d535a
    * The symbols are exported by name, not by ordinal.
kusano 7d535a
    * The exported names are undecorated.
kusano 7d535a
    * The calling convention of functions is "C" (CDECL).
kusano 7d535a
    * The ZLIB1.DLL binary is linked to MSVCRT.DLL.
kusano 7d535a
kusano 7d535a
    The archive in which ZLIB1.DLL is bundled contains compiled
kusano 7d535a
    test programs that must run with a valid build of ZLIB1.DLL.
kusano 7d535a
    It is recommended to download the prebuilt DLL from the zlib
kusano 7d535a
    web site, instead of building it yourself, to avoid potential
kusano 7d535a
    incompatibilities that could be introduced by your compiler
kusano 7d535a
    and build settings.  If you do build the DLL yourself, please
kusano 7d535a
    make sure that it complies with all the above requirements,
kusano 7d535a
    and it runs with the precompiled test programs, bundled with
kusano 7d535a
    the original ZLIB1.DLL distribution.
kusano 7d535a
kusano 7d535a
    If, for any reason, you need to build an incompatible DLL,
kusano 7d535a
    please use a different file name.
kusano 7d535a
kusano 7d535a
kusano 7d535a
 2. Why did you change the name of the DLL to ZLIB1.DLL?
kusano 7d535a
    What happened to the old ZLIB.DLL?
kusano 7d535a
kusano 7d535a
  - The old ZLIB.DLL, built from zlib-1.1.4 or earlier, required
kusano 7d535a
    compilation settings that were incompatible to those used by
kusano 7d535a
    a static build.  The DLL settings were supposed to be enabled
kusano 7d535a
    by defining the macro ZLIB_DLL, before including "zlib.h".
kusano 7d535a
    Incorrect handling of this macro was silently accepted at
kusano 7d535a
    build time, resulting in two major problems:
kusano 7d535a
kusano 7d535a
    * ZLIB_DLL was missing from the old makefile.  When building
kusano 7d535a
      the DLL, not all people added it to the build options.  In
kusano 7d535a
      consequence, incompatible incarnations of ZLIB.DLL started
kusano 7d535a
      to circulate around the net.
kusano 7d535a
kusano 7d535a
    * When switching from using the static library to using the
kusano 7d535a
      DLL, applications had to define the ZLIB_DLL macro and
kusano 7d535a
      to recompile all the sources that contained calls to zlib
kusano 7d535a
      functions.  Failure to do so resulted in creating binaries
kusano 7d535a
      that were unable to run with the official ZLIB.DLL build.
kusano 7d535a
kusano 7d535a
    The only possible solution that we could foresee was to make
kusano 7d535a
    a binary-incompatible change in the DLL interface, in order to
kusano 7d535a
    remove the dependency on the ZLIB_DLL macro, and to release
kusano 7d535a
    the new DLL under a different name.
kusano 7d535a
kusano 7d535a
    We chose the name ZLIB1.DLL, where '1' indicates the major
kusano 7d535a
    zlib version number.  We hope that we will not have to break
kusano 7d535a
    the binary compatibility again, at least not as long as the
kusano 7d535a
    zlib-1.x series will last.
kusano 7d535a
kusano 7d535a
    There is still a ZLIB_DLL macro, that can trigger a more
kusano 7d535a
    efficient build and use of the DLL, but compatibility no
kusano 7d535a
    longer dependents on it.
kusano 7d535a
kusano 7d535a
kusano 7d535a
 3. Can I build ZLIB.DLL from the new zlib sources, and replace
kusano 7d535a
    an old ZLIB.DLL, that was built from zlib-1.1.4 or earlier?
kusano 7d535a
kusano 7d535a
  - In principle, you can do it by assigning calling convention
kusano 7d535a
    keywords to the macros ZEXPORT and ZEXPORTVA.  In practice,
kusano 7d535a
    it depends on what you mean by "an old ZLIB.DLL", because the
kusano 7d535a
    old DLL exists in several mutually-incompatible versions.
kusano 7d535a
    You have to find out first what kind of calling convention is
kusano 7d535a
    being used in your particular ZLIB.DLL build, and to use the
kusano 7d535a
    same one in the new build.  If you don't know what this is all
kusano 7d535a
    about, you might be better off if you would just leave the old
kusano 7d535a
    DLL intact.
kusano 7d535a
kusano 7d535a
kusano 7d535a
 4. Can I compile my application using the new zlib interface, and
kusano 7d535a
    link it to an old ZLIB.DLL, that was built from zlib-1.1.4 or
kusano 7d535a
    earlier?
kusano 7d535a
kusano 7d535a
  - The official answer is "no"; the real answer depends again on
kusano 7d535a
    what kind of ZLIB.DLL you have.  Even if you are lucky, this
kusano 7d535a
    course of action is unreliable.
kusano 7d535a
kusano 7d535a
    If you rebuild your application and you intend to use a newer
kusano 7d535a
    version of zlib (post- 1.1.4), it is strongly recommended to
kusano 7d535a
    link it to the new ZLIB1.DLL.
kusano 7d535a
kusano 7d535a
kusano 7d535a
 5. Why are the zlib symbols exported by name, and not by ordinal?
kusano 7d535a
kusano 7d535a
  - Although exporting symbols by ordinal is a little faster, it
kusano 7d535a
    is risky.  Any single glitch in the maintenance or use of the
kusano 7d535a
    DEF file that contains the ordinals can result in incompatible
kusano 7d535a
    builds and frustrating crashes.  Simply put, the benefits of
kusano 7d535a
    exporting symbols by ordinal do not justify the risks.
kusano 7d535a
kusano 7d535a
    Technically, it should be possible to maintain ordinals in
kusano 7d535a
    the DEF file, and still export the symbols by name.  Ordinals
kusano 7d535a
    exist in every DLL, and even if the dynamic linking performed
kusano 7d535a
    at the DLL startup is searching for names, ordinals serve as
kusano 7d535a
    hints, for a faster name lookup.  However, if the DEF file
kusano 7d535a
    contains ordinals, the Microsoft linker automatically builds
kusano 7d535a
    an implib that will cause the executables linked to it to use
kusano 7d535a
    those ordinals, and not the names.  It is interesting to
kusano 7d535a
    notice that the GNU linker for Win32 does not suffer from this
kusano 7d535a
    problem.
kusano 7d535a
kusano 7d535a
    It is possible to avoid the DEF file if the exported symbols
kusano 7d535a
    are accompanied by a "__declspec(dllexport)" attribute in the
kusano 7d535a
    source files.  You can do this in zlib by predefining the
kusano 7d535a
    ZLIB_DLL macro.
kusano 7d535a
kusano 7d535a
kusano 7d535a
 6. I see that the ZLIB1.DLL functions use the "C" (CDECL) calling
kusano 7d535a
    convention.  Why not use the STDCALL convention?
kusano 7d535a
    STDCALL is the standard convention in Win32, and I need it in
kusano 7d535a
    my Visual Basic project!
kusano 7d535a
kusano 7d535a
    (For readability, we use CDECL to refer to the convention
kusano 7d535a
     triggered by the "__cdecl" keyword, STDCALL to refer to
kusano 7d535a
     the convention triggered by "__stdcall", and FASTCALL to
kusano 7d535a
     refer to the convention triggered by "__fastcall".)
kusano 7d535a
kusano 7d535a
  - Most of the native Windows API functions (without varargs) use
kusano 7d535a
    indeed the WINAPI convention (which translates to STDCALL in
kusano 7d535a
    Win32), but the standard C functions use CDECL.  If a user
kusano 7d535a
    application is intrinsically tied to the Windows API (e.g.
kusano 7d535a
    it calls native Windows API functions such as CreateFile()),
kusano 7d535a
    sometimes it makes sense to decorate its own functions with
kusano 7d535a
    WINAPI.  But if ANSI C or POSIX portability is a goal (e.g.
kusano 7d535a
    it calls standard C functions such as fopen()), it is not a
kusano 7d535a
    sound decision to request the inclusion of <windows.h>, or to</windows.h>
kusano 7d535a
    use non-ANSI constructs, for the sole purpose to make the user
kusano 7d535a
    functions STDCALL-able.
kusano 7d535a
kusano 7d535a
    The functionality offered by zlib is not in the category of
kusano 7d535a
    "Windows functionality", but is more like "C functionality".
kusano 7d535a
kusano 7d535a
    Technically, STDCALL is not bad; in fact, it is slightly
kusano 7d535a
    faster than CDECL, and it works with variable-argument
kusano 7d535a
    functions, just like CDECL.  It is unfortunate that, in spite
kusano 7d535a
    of using STDCALL in the Windows API, it is not the default
kusano 7d535a
    convention used by the C compilers that run under Windows.
kusano 7d535a
    The roots of the problem reside deep inside the unsafety of
kusano 7d535a
    the K&R-style function prototypes, where the argument types
kusano 7d535a
    are not specified; but that is another story for another day.
kusano 7d535a
kusano 7d535a
    The remaining fact is that CDECL is the default convention.
kusano 7d535a
    Even if an explicit convention is hard-coded into the function
kusano 7d535a
    prototypes inside C headers, problems may appear.  The
kusano 7d535a
    necessity to expose the convention in users' callbacks is one
kusano 7d535a
    of these problems.
kusano 7d535a
kusano 7d535a
    The calling convention issues are also important when using
kusano 7d535a
    zlib in other programming languages.  Some of them, like Ada
kusano 7d535a
    (GNAT) and Fortran (GNU G77), have C bindings implemented
kusano 7d535a
    initially on Unix, and relying on the C calling convention.
kusano 7d535a
    On the other hand, the pre- .NET versions of Microsoft Visual
kusano 7d535a
    Basic require STDCALL, while Borland Delphi prefers, although
kusano 7d535a
    it does not require, FASTCALL.
kusano 7d535a
kusano 7d535a
    In fairness to all possible uses of zlib outside the C
kusano 7d535a
    programming language, we choose the default "C" convention.
kusano 7d535a
    Anyone interested in different bindings or conventions is
kusano 7d535a
    encouraged to maintain specialized projects.  The "contrib/"
kusano 7d535a
    directory from the zlib distribution already holds a couple
kusano 7d535a
    of foreign bindings, such as Ada, C++, and Delphi.
kusano 7d535a
kusano 7d535a
kusano 7d535a
 7. I need a DLL for my Visual Basic project.  What can I do?
kusano 7d535a
kusano 7d535a
  - Define the ZLIB_WINAPI macro before including "zlib.h", when
kusano 7d535a
    building both the DLL and the user application (except that
kusano 7d535a
    you don't need to define anything when using the DLL in Visual
kusano 7d535a
    Basic).  The ZLIB_WINAPI macro will switch on the WINAPI
kusano 7d535a
    (STDCALL) convention.  The name of this DLL must be different
kusano 7d535a
    than the official ZLIB1.DLL.
kusano 7d535a
kusano 7d535a
    Gilles Vollant has contributed a build named ZLIBWAPI.DLL,
kusano 7d535a
    with the ZLIB_WINAPI macro turned on, and with the minizip
kusano 7d535a
    functionality built in.  For more information, please read
kusano 7d535a
    the notes inside "contrib/vstudio/readme.txt", found in the
kusano 7d535a
    zlib distribution.
kusano 7d535a
kusano 7d535a
kusano 7d535a
 8. I need to use zlib in my Microsoft .NET project.  What can I
kusano 7d535a
    do?
kusano 7d535a
kusano 7d535a
  - Henrik Ravn has contributed a .NET wrapper around zlib.  Look
kusano 7d535a
    into contrib/dotzlib/, inside the zlib distribution.
kusano 7d535a
kusano 7d535a
kusano 7d535a
 9. If my application uses ZLIB1.DLL, should I link it to
kusano 7d535a
    MSVCRT.DLL?  Why?
kusano 7d535a
kusano 7d535a
  - It is not required, but it is recommended to link your
kusano 7d535a
    application to MSVCRT.DLL, if it uses ZLIB1.DLL.
kusano 7d535a
kusano 7d535a
    The executables (.EXE, .DLL, etc.) that are involved in the
kusano 7d535a
    same process and are using the C run-time library (i.e. they
kusano 7d535a
    are calling standard C functions), must link to the same
kusano 7d535a
    library.  There are several libraries in the Win32 system:
kusano 7d535a
    CRTDLL.DLL, MSVCRT.DLL, the static C libraries, etc.
kusano 7d535a
    Since ZLIB1.DLL is linked to MSVCRT.DLL, the executables that
kusano 7d535a
    depend on it should also be linked to MSVCRT.DLL.
kusano 7d535a
kusano 7d535a
kusano 7d535a
10. Why are you saying that ZLIB1.DLL and my application should
kusano 7d535a
    be linked to the same C run-time (CRT) library?  I linked my
kusano 7d535a
    application and my DLLs to different C libraries (e.g. my
kusano 7d535a
    application to a static library, and my DLLs to MSVCRT.DLL),
kusano 7d535a
    and everything works fine.
kusano 7d535a
kusano 7d535a
  - If a user library invokes only pure Win32 API (accessible via
kusano 7d535a
    <windows.h> and the related headers), its DLL build will work</windows.h>
kusano 7d535a
    in any context.  But if this library invokes standard C API,
kusano 7d535a
    things get more complicated.
kusano 7d535a
kusano 7d535a
    There is a single Win32 library in a Win32 system.  Every
kusano 7d535a
    function in this library resides in a single DLL module, that
kusano 7d535a
    is safe to call from anywhere.  On the other hand, there are
kusano 7d535a
    multiple versions of the C library, and each of them has its
kusano 7d535a
    own separate internal state.  Standalone executables and user
kusano 7d535a
    DLLs that call standard C functions must link to a C run-time
kusano 7d535a
    (CRT) library, be it static or shared (DLL).  Intermixing
kusano 7d535a
    occurs when an executable (not necessarily standalone) and a
kusano 7d535a
    DLL are linked to different CRTs, and both are running in the
kusano 7d535a
    same process.
kusano 7d535a
kusano 7d535a
    Intermixing multiple CRTs is possible, as long as their
kusano 7d535a
    internal states are kept intact.  The Microsoft Knowledge Base
kusano 7d535a
    articles KB94248 "HOWTO: Use the C Run-Time" and KB140584
kusano 7d535a
    "HOWTO: Link with the Correct C Run-Time (CRT) Library"
kusano 7d535a
    mention the potential problems raised by intermixing.
kusano 7d535a
kusano 7d535a
    If intermixing works for you, it's because your application
kusano 7d535a
    and DLLs are avoiding the corruption of each of the CRTs'
kusano 7d535a
    internal states, maybe by careful design, or maybe by fortune.
kusano 7d535a
kusano 7d535a
    Also note that linking ZLIB1.DLL to non-Microsoft CRTs, such
kusano 7d535a
    as those provided by Borland, raises similar problems.
kusano 7d535a
kusano 7d535a
kusano 7d535a
11. Why are you linking ZLIB1.DLL to MSVCRT.DLL?
kusano 7d535a
kusano 7d535a
  - MSVCRT.DLL exists on every Windows 95 with a new service pack
kusano 7d535a
    installed, or with Microsoft Internet Explorer 4 or later, and
kusano 7d535a
    on all other Windows 4.x or later (Windows 98, Windows NT 4,
kusano 7d535a
    or later).  It is freely distributable; if not present in the
kusano 7d535a
    system, it can be downloaded from Microsoft or from other
kusano 7d535a
    software provider for free.
kusano 7d535a
kusano 7d535a
    The fact that MSVCRT.DLL does not exist on a virgin Windows 95
kusano 7d535a
    is not so problematic.  Windows 95 is scarcely found nowadays,
kusano 7d535a
    Microsoft ended its support a long time ago, and many recent
kusano 7d535a
    applications from various vendors, including Microsoft, do not
kusano 7d535a
    even run on it.  Furthermore, no serious user should run
kusano 7d535a
    Windows 95 without a proper update installed.
kusano 7d535a
kusano 7d535a
kusano 7d535a
12. Why are you not linking ZLIB1.DLL to
kusano 7d535a
    <<my c="" favorite="" library="" run-time="">> ?</my>
kusano 7d535a
kusano 7d535a
  - We considered and abandoned the following alternatives:
kusano 7d535a
kusano 7d535a
    * Linking ZLIB1.DLL to a static C library (LIBC.LIB, or
kusano 7d535a
      LIBCMT.LIB) is not a good option.  People are using the DLL
kusano 7d535a
      mainly to save disk space.  If you are linking your program
kusano 7d535a
      to a static C library, you may as well consider linking zlib
kusano 7d535a
      in statically, too.
kusano 7d535a
kusano 7d535a
    * Linking ZLIB1.DLL to CRTDLL.DLL looks appealing, because
kusano 7d535a
      CRTDLL.DLL is present on every Win32 installation.
kusano 7d535a
      Unfortunately, it has a series of problems: it does not
kusano 7d535a
      work properly with Microsoft's C++ libraries, it does not
kusano 7d535a
      provide support for 64-bit file offsets, (and so on...),
kusano 7d535a
      and Microsoft discontinued its support a long time ago.
kusano 7d535a
kusano 7d535a
    * Linking ZLIB1.DLL to MSVCR70.DLL or MSVCR71.DLL, supplied
kusano 7d535a
      with the Microsoft .NET platform, and Visual C++ 7.0/7.1,
kusano 7d535a
      raises problems related to the status of ZLIB1.DLL as a
kusano 7d535a
      system component.  According to the Microsoft Knowledge Base
kusano 7d535a
      article KB326922 "INFO: Redistribution of the Shared C
kusano 7d535a
      Runtime Component in Visual C++ .NET", MSVCR70.DLL and
kusano 7d535a
      MSVCR71.DLL are not supposed to function as system DLLs,
kusano 7d535a
      because they may clash with MSVCRT.DLL.  Instead, the
kusano 7d535a
      application's installer is supposed to put these DLLs
kusano 7d535a
      (if needed) in the application's private directory.
kusano 7d535a
      If ZLIB1.DLL depends on a non-system runtime, it cannot
kusano 7d535a
      function as a redistributable system component.
kusano 7d535a
kusano 7d535a
    * Linking ZLIB1.DLL to non-Microsoft runtimes, such as
kusano 7d535a
      Borland's, or Cygwin's, raises problems related to the
kusano 7d535a
      reliable presence of these runtimes on Win32 systems.
kusano 7d535a
      It's easier to let the DLL build of zlib up to the people
kusano 7d535a
      who distribute these runtimes, and who may proceed as
kusano 7d535a
      explained in the answer to Question 14.
kusano 7d535a
kusano 7d535a
kusano 7d535a
13. If ZLIB1.DLL cannot be linked to MSVCR70.DLL or MSVCR71.DLL,
kusano 7d535a
    how can I build/use ZLIB1.DLL in Microsoft Visual C++ 7.0
kusano 7d535a
    (Visual Studio .NET) or newer?
kusano 7d535a
kusano 7d535a
  - Due to the problems explained in the Microsoft Knowledge Base
kusano 7d535a
    article KB326922 (see the previous answer), the C runtime that
kusano 7d535a
    comes with the VC7 environment is no longer considered a
kusano 7d535a
    system component.  That is, it should not be assumed that this
kusano 7d535a
    runtime exists, or may be installed in a system directory.
kusano 7d535a
    Since ZLIB1.DLL is supposed to be a system component, it may
kusano 7d535a
    not depend on a non-system component.
kusano 7d535a
kusano 7d535a
    In order to link ZLIB1.DLL and your application to MSVCRT.DLL
kusano 7d535a
    in VC7, you need the library of Visual C++ 6.0 or older.  If
kusano 7d535a
    you don't have this library at hand, it's probably best not to
kusano 7d535a
    use ZLIB1.DLL.
kusano 7d535a
kusano 7d535a
    We are hoping that, in the future, Microsoft will provide a
kusano 7d535a
    way to build applications linked to a proper system runtime,
kusano 7d535a
    from the Visual C++ environment.  Until then, you have a
kusano 7d535a
    couple of alternatives, such as linking zlib in statically.
kusano 7d535a
    If your application requires dynamic linking, you may proceed
kusano 7d535a
    as explained in the answer to Question 14.
kusano 7d535a
kusano 7d535a
kusano 7d535a
14. I need to link my own DLL build to a CRT different than
kusano 7d535a
    MSVCRT.DLL.  What can I do?
kusano 7d535a
kusano 7d535a
  - Feel free to rebuild the DLL from the zlib sources, and link
kusano 7d535a
    it the way you want.  You should, however, clearly state that
kusano 7d535a
    your build is unofficial.  You should give it a different file
kusano 7d535a
    name, and/or install it in a private directory that can be
kusano 7d535a
    accessed by your application only, and is not visible to the
kusano 7d535a
    others (i.e. it's neither in the PATH, nor in the SYSTEM or
kusano 7d535a
    SYSTEM32 directories).  Otherwise, your build may clash with
kusano 7d535a
    applications that link to the official build.
kusano 7d535a
kusano 7d535a
    For example, in Cygwin, zlib is linked to the Cygwin runtime
kusano 7d535a
    CYGWIN1.DLL, and it is distributed under the name CYGZ.DLL.
kusano 7d535a
kusano 7d535a
kusano 7d535a
15. May I include additional pieces of code that I find useful,
kusano 7d535a
    link them in ZLIB1.DLL, and export them?
kusano 7d535a
kusano 7d535a
  - No.  A legitimate build of ZLIB1.DLL must not include code
kusano 7d535a
    that does not originate from the official zlib source code.
kusano 7d535a
    But you can make your own private DLL build, under a different
kusano 7d535a
    file name, as suggested in the previous answer.
kusano 7d535a
kusano 7d535a
    For example, zlib is a part of the VCL library, distributed
kusano 7d535a
    with Borland Delphi and C++ Builder.  The DLL build of VCL
kusano 7d535a
    is a redistributable file, named VCLxx.DLL.
kusano 7d535a
kusano 7d535a
kusano 7d535a
16. May I remove some functionality out of ZLIB1.DLL, by enabling
kusano 7d535a
    macros like NO_GZCOMPRESS or NO_GZIP at compile time?
kusano 7d535a
kusano 7d535a
  - No.  A legitimate build of ZLIB1.DLL must provide the complete
kusano 7d535a
    zlib functionality, as implemented in the official zlib source
kusano 7d535a
    code.  But you can make your own private DLL build, under a
kusano 7d535a
    different file name, as suggested in the previous answer.
kusano 7d535a
kusano 7d535a
kusano 7d535a
17. I made my own ZLIB1.DLL build.  Can I test it for compliance?
kusano 7d535a
kusano 7d535a
  - We prefer that you download the official DLL from the zlib
kusano 7d535a
    web site.  If you need something peculiar from this DLL, you
kusano 7d535a
    can send your suggestion to the zlib mailing list.
kusano 7d535a
kusano 7d535a
    However, in case you do rebuild the DLL yourself, you can run
kusano 7d535a
    it with the test programs found in the DLL distribution.
kusano 7d535a
    Running these test programs is not a guarantee of compliance,
kusano 7d535a
    but a failure can imply a detected problem.
kusano 7d535a
kusano 7d535a
**
kusano 7d535a
kusano 7d535a
This document is written and maintained by
kusano 7d535a
Cosmin Truta <cosmint@cs.ubbcluj.ro></cosmint@cs.ubbcluj.ro>