APL ZlibTool OCX Demo
for Windows

Zlib is a "free, general-purpose, legally unencumbered -- that is, not covered by any patents -- lossless data-compression library" available in various forms.

APL ZlibTool Demo demonstrates the use of Mark Nelson's ZlibTool OCX file-compression utility within APL+Win®.

APL ZlibTool Demo
05 Mar 2006 (1,106,952 bytes)
installs APL+Win 4 runtime system and Mark Nelson's ZLibOCX2.dll
for APLers:
APLZLIBTOOL.w3
(102,470 bytes)
requires APL+Win 4+ development system
and Mark Nelson's ZlibTool.ocx or ZlibOCX2.dll

Before you can use this demo, you must have the ZlibTool OCX installed and registered on your computer. The runtime package above optionally installs and registers ZlibOCX2.dll for you, or you can use the links above to get it yourself. I believe the two versions are functionally the same, and I have not encountered any of the problems mentioned in Mark Nelson's FAQ concerning use of the original ZlibTool.ocx, so my demo is coded to use either OCX version. After downloading, copy ZlibTool.ocx from the zip package (or ZlibOCX2.dll) to your Windows \System32 folder, then use Start | Run to register it:

regsvr32 ZlibTool.ocx
or
regsvr32 ZLibOCX2.dll

APL ZlibTool OCX Demo

To operate the demo, enter or browse for a file to compress in the Source File field. If you use the browse button to choose a file, the chosen name plus the ".zl" extension is placed in the Output File field. Choose a compression level from 0 (no compression) to 9 (maximum compression), then click the Compress button to compress the file. The progress bar displays Progress events from the OCX, and the compressed and uncompressed file sizes are displayed below the bar on completion. To decompress a file, enter a Zlib-compressed file name in the Source field and the desired output file name in the Output field, then click the Expand button. To minimize inadvertent errors, my demo forces the ".zl" extension for compressed files (to enable the Compress/Expand buttons), although Zlib does not require this.

Technical Notes

ZlibTool OCX is simple to use. It has a built-in GUI consisting solely of a progress bar, however it also can be operated as a program utility without any user interface. My demo includes a GUI for selecting input and output files and setting the compression level. I display my own progress bar, since the OCX's cannot be controlled independently, and manipulate the Progress event to update it. Also see the variable "utility" in the workspace for a step-by-step outline of how to use the OCX without a GUI.

APL developers should be warned that an application that uses this control must validate the InputFile path and filename and the OutputFile path before using the Compress or Decompress methods. If either of these properties is incorrect, an error will be generated that will crash APL+Win.

ZlibTool provides a handy method for creating custom archives in APL+Win applications. It achieves compression ratios nearly the same as PKZip. I tested compression of various native file formats, and Zlib matched PKZip with less than 2% difference in size (Zlib usually slightly larger) and with comparable speed. The Zlib format is compatible with GZIP but cannot be expanded by PKZip, WinZip, or ZipMagic.

Scripting ZlibTool OCX

ZlibTool OCX also can be used as an HTML object or in JScript or VBScript. However, to use in a script, you must install and register the ZlibOCX2.dll version.


To use ZlibTool OCX in an HTML document, you can do something like this:

  <form>
  Input File: <input type="text" name="input">
  <br />
  Output File: <input type="text" name="output">
  <br />
  <br />
  <input type="button" name="compress"
         value="Compress"
         onclick="zlibtool.InputFile=input.value;
                  zlibtool.OutputFile=output.value;
                  zlibtool.Compress();"
  >
  <input type="button" name="decompress"
         value="Decompress"
         onclick="zlibtool.InputFile=input.value;
                  zlibtool.OutputFile=output.value;
                  zlibtool.Decompress();"
  >
  </form>

  Progress: <object classid=
    "clsid:E88121A3-9FA9-11CF-9D9F-00AA003A3AA3"
    id="zlibtool"
    width="128"
    height="24"
  >
  <param name="InputFile" value="">
  <param name="OutputFile" value="">
  </object>

In actual use you would want to add a script function to validate the input- and output-file values before compress/decompress, and maybe reset the progress bar. But the above example works.


With the ZlibOCX2.dll version, you can operate the OCX from script:

  zlibtool = new ActiveXObject("zlibIF.zlibIF.1");
  zlibtool.InputFileName = "c:\\file.txt";
  zlibtool.OutputFileName = "c:\\file.zl";
  zlibtool.CompressionLevel=9;
  zlibtool.Compress();

Of course, in real use, you would want to assign the file names, compression level and method from external parameters, such as command-line arguments.

Thanks to Pradeep Kurra at the University of Memphis for initiating this discussion.

APL+Win® is a product of APL2000, Inc.
made with ParkeNet Editor
ParkeNet.com