<a href="http://www.micropoll.com/akira/mpview/585320-168921">Click Here for Poll</a><a href="http://www.questionpro.com" title="online surveys">Online Survey</a><BR> | <a href="http://www.micropoll.com" title="Website Polls">Website Polls</a><BR> | <BR><a href="http://www.micropoll.com/akira/MicroPoll?mode=html&id=168921">View MicroPoll</A></div>

Visual Studio 2010!

Read now >

Windows Mobile Development Thoughts

Read now >

View Now
DevSource RSS FEEDS
XML Want an easy way to keep up with breaking tech news? And the Get DevSource headlines delivered to your desktop with RSS.
ADVERTISEMENT
ADVERTISEMENT

 

DevSource.com: Your Source for Visual Studio on Facebook
ADVERTISEMENT
Creating an Object-Oriented Interface to CAB Files
By Jim Mischel

Rate This Article: Add This Article To:

Creating an Object-Oriented Interface to CAB Files - ' The CabCompresor Class '
( Page 2 of 3 )

CabCompressor Class

The CabCompressor class provides an interface to the File Compression interface functionality in CABINET.DLL. It handles a lot of the bookkeeping tasks required for file compression, such as maintaining the FciCurrentCab structure, creating and destroying the FCI context, and supplying GCHandles for managed objects that are passed to FCI functions. It also provides an event interface for the NextCabinet, FilePlaced, and Progress FCI callbacks. Client programs can subscribe to these events to handle the callbacks.

All of the FCI callbacks are implemented as protected virtual functions that inheritors can override in order to change the default functionality. The memory allocation and file I/O callbacks call the common routines that are implemented in the CabIO class.

The public interface to CabCompressor consists primarily of the following methods:

  • CabCompressor constructor.
  • A Dispose method. Since CabCompressor allocates unmanaged resources, it implements the IDisposable interface so that it can release those resources when the garbage collector cleans up.
  • AddFile adds a file to a cabinet. This corresponds to the FciAddFile function.
  • FlushFolder corresponds to FciFlushFolder.
  • FlushCabinet corresponds to FciFlushCabinet.

CabCompressor uses a standard .NET event interface. The five events it implements are NextCabinet, FilePlaced, FileAdded, FolderComplete, and CabinetComplete. The event handler delegates use the recommended naming convention (NextCabinetEventHandler, FilePlacedEventHandler, ProgressEventHandler), as do the event arguments. Note that FileAdded, FolderComplete, and CabinetComplete all are of type ProgressEvent and use the ProgressEventArgs event arguments class.

Most of the code in CabCompressor is pretty mundane, concerned with handling the file I/O callbacks and converting the other callback function calls to events and passing them to the client program. Beyond that, there is some slightly complex code to maintain the user data pointer, and a bit of code that allocates and manages the FCI context so that the client program doesn't have to fool with it.



 
 
>>> More Using Microsoft Visual Studio Articles          >>> More By Jim Mischel