Sample Applications|This sample can be found in:
samples\Visual C++ 6-7\MEMORYCOMPRESSION
The sample is an application that takes input from the keyboard and stores it (as a text file) in a zip file.
The sample uses the QueryMemoryFile and ZippingMemoryFile events to accomplish this, but even if you aren't interested in these events, the sample still demonstrates setting properties, running methods and handling events, so you can use the Compress and Uncompress methods as needed.
To use the this sample, you will need Microsoft Visual C++ 6.0. The sample demonstrates how to:
Import Xceed Zip's type library in a C++ project
How to implement an event sink using ATL
Perform memory compression with the Xceed Zip control
To use the sample, proceed as follows:
Open the "Memory Compression.dsw" file in the MSVC IDE.
The files XceedZip.dll and zipDispIds.h must be made available in the include path in order to compile the project. Current project settings include "\XceedZip" in the include path, so you can either copy the two required files to this folder, or modify the include path accordingly.
All the important calls are implemented in "Memory Compression.cpp".
The first thing that the sample demonstrates is how to import XceedZip's type library in a C++ project. The line "#import "XceedZip.dll" generates XceedZip.tlh, which is the header file containing the declarations for the enumerations, classes, and other things contained in the type library. It also generates XceedZip.tli, which is the implementation of the methods declared in XceedZip.tlh. Complete documentation on the #import directive can be found in the MSVC documentation.
Looking at the main function shows how the wrapper classes generated by the #import directive can be used.
Up to this point, we only used MSVC features (#import is a Microsoft C++ extension), with no MFC or ATL specific features.
The second thing that the sample demonstrate is how to implement an event sink using ATL.
We first need to include ATL's main header files. Look at stdafx.h, between the BEGIN/END ATL REQUIRED comments.
Then, we need to declare a class that will derive either from IDispEventImpl<> or IDispEventSimpleImpl<>. The major difference between these two class templates is that the former uses information from the type library to determine the event handlers' information (return and parameter types), while the latter gets this information from user-provided structures.
With Xceed Zip, we use IdispEventSimpleImple<> because we use enumeration types in many of the events, and IdispEventImpl<> does not handle that correctly.
The first thing to do to implement an event is to add a member function to the sink class. This function must use _stdcall calling convention, and must be declared exactly as the event is defined in the event interface. Tip: you can copy/paste the declaration from XceedZip.tlh.
Next, a _ATL_FUNC_INFO structure must be declared for each event handler. This structure specifies the return and parameter types for the handler.
Finally, a SINK_MAP must be declared in the sink class, using ATL macros. Each event handler in the sink class must be provided through a SINK_ENTRY_INFO() entry in the sink map.
To use the sink object, all that needs to be done is to call DispEventAdvise() with a pointer to the object from which the events need to be handled.