DLL_FAQ.txt 18 KB

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