This code shows how to use the freeware InfoZip Zip32.DLL and Unzip32.DLL files from the
(continued)
Silverlight 2 SDK for Visual Studio 2008
This package is an add-on to the RTM release of Visual Studio 2008 to provide tooling for Microsoft Silverlight 2 Beta 1. It provides a Silverlight project system for developing Silverlight applications using C# or Visual Basic.
»
Article: What Does it Take to Build the Best RIA?
With the proliferation of Rich Interactive Application (RIA) platform choices out there, you no longer have to take a one-size-fits-all approach to developing your next RIA application. Knowing the strengths (and weaknesses) of each platform can help you to decide the best RIA for your next application.
»
Expression Blend 2.5 Preview
Use Expression Blend 2.5 to create and modify managed Silverlight 2-based applications. Expression Blend for Silverlight 2 includes all of the features in Expression Blend 2 but has not reached the quality level of Expression Blend 2 for WPF or Silverlight 1 development. »
The Hottest Mobile Platform Meets the Hottest RIA Platform
With the Symbian OS now supporting Microsoft Silverlight, mobile developers can bring new and exciting capabilities to handsets all over the globe. Find out why developers now need to make mobile devices a core part of their RIA development strategy.
»
Article: Leveraging Your Flash Development with Silverlight
You're not giving up Flash any time soon (and we don't blame you.) But if you could get your Flash application working in Silverlight, why wouldn't you? We show you the tools and techniques required to have your rockin' Flash application rolled for Silverlight.
»
The InfoZip DLL's are open-source DLL's that are available for programmers to utilise free of charge. They are standard C DLL's and were very tricky/impossible to interface with VB until VB5/6 offered the 'addressof' operator.
About this Code
I based this code on the Zip/Unzip examples that come with the downloadable DLL's and encapsulated that code into re-usable class modules that can either be used in an ActiveX DLL, or just placed into your project as required. The downloadable project contains the source-code for an ActiveX DLL called CGZipLibrary and a sample project which uses that DLL.
The example program simply takes everything in it's own directory and zip's it into a file.
You can then unzip this file straight into the TEMP directory. You can check the structure of the Zip file using WinZip (or similar) if you want to check that the Zip is intact (I've had no problems with it at all).
The Class Modules CGZipFiles and CGUnzipFiles have a lot of properties - it's worth reading through the code in these classes to learn how to get the best from them.
A sample piece of code using the Zip class could be as simple as :
Dim oZip as CGZipFiles
set oZip = new CGZipFiles
oZip.ZipFileName = "\MyZip.Zip"
oZip.AddFile "c:\mystuff\myfiles\*.*"
oZip.AddFile "c:\mystuff\mymedia\*.wav"
If oZip.MakeZipFile <> 0 then
MsgBox oZip.GetLastMessage
EndIf
set oZip = nothing
'
The code for Unzipping files is just as straight-forward :
Dim oUnZip as CGUnZipFiles
set oUnZip = new CGUnZipFiles
oUnZip.ZipFileName = "\MyZip.Zip"
oUnZip.ExtractDir = App.Path ' or whatever you like !
oUnZip.HonourDirectories = true ' keep dir structure
If oUnZip.UnZip <> 0 then
MsgBox oUnZip.GetLastMessage
EndIf
set oUnZip = nothing
'
Note : This code is provided as-is - I know that there are a few bugs in the interface to the Zip/Unzip DLL's (including a frustrating one that's got a real cludge work around - see if you can spot it). It's designed as a starting point to allow you to use Zip and Unzip functionality in your programs. You should really place the Zip32.DLL and Unzip32.DLL into your \windows\system directory (although you can just have them in the same directory as the ActiveX DLL)
I've been a version of this code for several weeks in a production application and it's just been superb.
Add www.codeguru.com to your favorites Add www.codeguru.com to your browser search box IE 7 | Firefox 2.0 | Firefox 1.5.xReceive news via our XML/RSS feed