home *** CD-ROM | disk | FTP | other *** search
- unit DllAPI;
- {------------------------------------------------------------------------------}
- { Xceed Zip 4 Dll API Sample for Delphi 2, 3, 4 and 5. }
- { Copyright (c) 1998-1999 Xceed Software Inc. }
- {------------------------------------------------------------------------------}
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, ComCtrls;
-
- const
- { This is the message sent to the associated window when an event occurs. }
- WM_USER_XCEEDZIPEVENT = WM_USER + 1555;
-
- { These are some of the possible values for wParam when an event occurs. }
- XM_SKIPPINGFILE = 6;
- XM_FILESTATUS = 9;
- XM_GLOBALSTATUS = 10;
- XM_WARNING = 17;
-
- { If you have a registered version, paste your license number below. You
- will find this string in the LICENSE.TXT file. }
- cLicenseString = '';
-
- { These constants represent the type of value you want to retrieve a
- description for, using the XzGetErrorDescription API. }
- xvtError = 0;
- xvtWarning = 1;
- xvtSkippingReason = 2;
-
- { Number of chars in filename fields. }
- MAX_PATH = 260;
-
- type
- { The following structures were translated from the XceedZipAPI.h file. }
- PXcdSkippingFileParamsA = ^TXcdSkippingFileParamsA;
- TXcdSkippingFileParamsA = record
- wStructSize : SmallInt;
- hZip : LongInt;
- szFilename : array[ 1..MAX_PATH ] of Char;
- szComment : array[ 1..1024 ] of Char;
- szFilenameOnDisk : array[ 1..MAX_PATH ] of Char;
- lSize : LongInt;
- lCompressedSize : LongInt;
- xAttributes : LongInt;
- lCRC : LongInt;
- stModified : TSystemTime;
- stAccessed : TSystemTime;
- stCreated : TSystemTime;
- xMethod : LongInt;
- bEncrypted : LongInt;
- xReason : LongInt;
- end;
-
- PXcdFileStatusParamsA = ^TXcdFileStatusParamsA;
- TXcdFileStatusParamsA = record
- wStructSize : SmallInt;
- hZip : LongInt;
- szFilename : array[ 1..MAX_PATH ] of Char;
- lSize : LongInt;
- lCompressedSize : LongInt;
- lBytesProcessed : LongInt;
- nBytesPercent : SmallInt;
- nCompressionRatio : SmallInt;
- bFileCompleted : LongInt;
- end;
-
- PXcdGlobalStatusParams = ^TXcdGlobalStatusParams;
- TXcdGlobalStatusParams = record
- wStructSize : SmallInt;
- hZip : LongInt;
- lFilesTotal : LongInt;
- lFilesProcessed : LongInt;
- lFilesSkipped : LongInt;
- nFilesPercent : SmallInt;
- lBytesTotal : LongInt;
- lBytesProcessed : LongInt;
- lBytesSkipped : LongInt;
- nBytesPercent : SmallInt;
- lBytesOutput : LongInt;
- nCompressionRatio : SmallInt;
- end;
-
- PXcdWarningParamsA = ^TXcdWarningParamsA;
- TXcdWarningParamsA = record
- wStructSize : SmallInt;
- hZip : LongInt;
- szFilename : array[ 1..MAX_PATH ] of Char;
- xWarning : LongInt;
- end;
-
- TfrmDllAPI = class(TForm)
- cmdZip: TButton;
- cmdUnzip: TButton;
- cmdAbort: TButton;
- txtZipFile: TEdit;
- txtFiles: TEdit;
- txtExtract: TEdit;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- txtPassword: TEdit;
- Label4: TLabel;
- barProgress: TProgressBar;
- lstResults: TListBox;
- Label5: TLabel;
- chkSubfolders: TCheckBox;
- procedure cmdZipClick(Sender: TObject);
- procedure cmdUnzipClick(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure cmdAbortClick(Sender: TObject);
- private
- { This is a handle to your instance of the Xceed Zip object. }
- hZip : LongInt;
- { This method will be called each time the associated Xceed Zip object
- triggers an event, after setting the Window handle to notify. }
- procedure XceedZipMessage( var xMsg : TMessage ); message WM_USER_XCEEDZIPEVENT;
- public
- end;
-
- { These prototypes were translated from the XceedZipAPI.h file.
- Make sure to use stdcall naming for "C" style prototypes! }
- function XceedZipInitDLL : LongInt; stdcall; external 'XceedZip.DLL';
- function XceedZipShutdownDLL : LongInt; stdcall; external 'XceedZip.DLL';
-
- function XzCreateXceedZipA( pszLicense : PChar) : LongInt; stdcall; external 'XceedZip.DLL';
- procedure XzDestroyXceedZip( hZip : LongInt ); stdcall; external 'XceedZip.DLL';
- procedure XzSetXceedZipWindow( hZip : LongInt; hWnd : LongInt ); stdcall; external 'XceedZip.DLL';
-
- procedure XzSetZipFilenameA( hZip : LongInt; pszValue : PChar); stdcall; external 'XceedZip.DLL';
- procedure XzSetFilesToProcessA( hZip : LongInt; pszValue : PChar ); stdcall; external 'XceedZip.DLL';
- procedure XzSetUnzipToFolderA( hZip : LongInt; pszValue : PChar); stdcall; external 'XceedZip.DLL';
- procedure XzSetEncryptionPasswordA ( hZip : LongInt; pszValue : PChar ); stdcall; external 'XceedZip.DLL';
- procedure XzSetProcessSubfolders( hZip : LongInt; bValue : LongInt ); stdcall; external 'XceedZip.DLL';
- procedure XzSetAbort( hZip : LongInt; bValue : LongInt ); stdcall; external 'XceedZip.DLL';
-
- function XzZip( hZip : LongInt ) : LongInt; stdcall; external 'XceedZip.DLL';
- function XzUnzip( hZip : LongInt ) : LongInt; stdcall; external 'XceedZip.DLL';
- function XzGetErrorDescriptionA( hZip : LongInt; xType : LongInt; xCode : LongInt; pszBuffer : PChar; uMaxLength : LongInt ) : LongInt; stdcall; external 'XceedZip.DLL';
-
- var
- frmDllAPI: TfrmDllAPI;
-
- implementation
-
- {$R *.DFM}
-
- procedure TfrmDllAPI.FormCreate(Sender: TObject);
- begin
- { Initialize library. }
- XceedZipInitDLL;
-
- { Create one instance for this form. }
- hZip := XzCreateXceedZipA( cLicenseString );
-
- { Associate this instance with this window. }
- XzSetXceedZipWindow( hZip, Self.Handle );
- end;
-
- procedure TfrmDllAPI.FormDestroy(Sender: TObject);
- begin
- { Free instance and shutdown library. }
- XzDestroyXceedZip( hZip );
- XceedZipShutdownDll;
- end;
-
- procedure TfrmDllAPI.cmdZipClick(Sender: TObject);
- var
- xResult : LongInt;
- szMessage : array[ 0..200 ] of Char;
- begin
- { Set the zip file you wish to create or update. }
- XzSetZipFilenameA( hZip, PChar( txtZipFile.text ) );
-
- { The "FilesToProcess" property is a string representing a list of CR/LF
- delimited filenames or file masks. You can also use the AddFilesToProcess
- method to add multiple entries. }
- XzSetFilesToProcessA( hZip, PChar( txtFiles.text ) );
-
- { You can set other properties as you wish. }
- XzSetEncryptionPasswordA( hZip, PChar( txtPassword.Text ) );
-
- if chkSubfolders.Checked then
- XzSetProcessSubfolders( hZip, 1 )
- else
- XzSetProcessSubfolders( hZip, 0 );
-
- { Reset window contents. }
- barProgress.Position := 0;
- lstResults.Clear;
-
- { To start zipping, just call the Zip method. }
- xResult := XzZip( hZip );
-
- { The GetErrorDescription function is very useful for displaying a default
- message for any error code, skipping reason or warning. }
- XzGetErrorDescriptionA( hZip, xvtError, xResult, szMessage, 200 );
- ShowMessage( string( szMessage ) );
- end;
-
- procedure TfrmDllAPI.cmdUnzipClick(Sender: TObject);
- var
- xResult : LongInt;
- szMessage : array[ 0..200 ] of Char;
- begin
- { Set the zip filename you want to unzip from. }
- XzSetZipFilenameA( hZip, PChar( txtZipFile.Text ) );
-
- { Set the files you wish to unzip. Again, this is a list of CR/LF delimited
- filenames or file masks. You can also use the AddFilesToProcess method to
- add multiple entries. }
- XzSetFilesToProcessA( hZip, PChar( txtFiles.Text ) );
-
- { You can set other properties too. }
- XzSetUnzipToFolderA( hzip, PChar( txtExtract.text ) );
- XzSetEncryptionPasswordA( hZip, PChar( txtPassword.Text ) );
-
- if chkSubfolders.Checked then
- XzSetProcessSubfolders( hZip, 1 )
- else
- XzSetProcessSubfolders( hZip, 0 );
-
- { Reset window contents. }
- barProgress.Position := 0;
- lstResults.Clear;
-
- { To unzip, just call the Unzip method. }
- xResult := XzUnzip( hZip );
-
- XzGetErrorDescriptionA( hZip, xvtError, xResult, szMessage, 200 );
- ShowMessage( string( szMessage ) );
- end;
-
- procedure TfrmDllAPI.cmdAbortClick(Sender: TObject);
- begin
- { To abort the current operation, set the Abort property to TRUE }
- XzSetAbort( hZip, 1 );
- end;
-
- { When using the Dll API in conjunction with the "XzSetXceedZipWindow"
- function, the specified window will receive the special WM_USER_XCEEDZIPEVENT
- message. You just need to implement a handler for this message. }
- procedure TfrmDllAPI.XceedZipMessage( var xMsg : TMessage );
- var
- pSkipping : PXcdSkippingFileParamsA;
- pFile : PXcdFileStatusParamsA;
- pGlobal : PXcdGlobalStatusParams;
- pWarning : PXcdWarningParamsA;
- szMessage : array[ 0..200 ] of Char;
- begin
- { wParam contains the ID of the triggered event. lParam contains a pointer to
- the proper parameter structure (see XceedZipAPI.h). }
- case xMsg.WParam of
- XM_SKIPPINGFILE: { A file is being skipped. }
- begin
- pSkipping := PXcdSkippingFileParamsA( xMsg.LParam );
- XzGetErrorDescriptionA( hZip, xvtSkippingReason, pSkipping^.xReason,
- szMessage, 200 );
- lstResults.Items.Add( 'Skipping file '
- + string( pSkipping^.szFilename )
- + ' [' + string( szMessage ) + ']' );
- end;
-
- XM_FILESTATUS: { A file is being processed further. }
- begin
- pFile := PXcdFileStatusParamsA( xMsg.LParam );
- if pFile^.lBytesProcessed = 0 then
- lstResults.Items.Add( 'Processing file '
- + string( pFile^.szFilename ) );
- end;
-
- XM_GLOBALSTATUS: { The Zip file is being processed further. }
- begin
- pGlobal := PXcdGlobalStatusParams( xMsg.LParam );
- barProgress.Position := pGlobal^.nBytesPercent;
- end;
-
- XM_WARNING: { A warning occured. }
- begin
- pWarning := PXcdWarningParamsA( xMsg.LParam );
- XzGetErrorDescriptionA( hZip, xvtWarning, pWarning^.xWarning,
- szMessage, 200 );
- lstResults.Items.Add( 'Warning '
- + IntToStr( pWarning^.xWarning )
- + ' on file '
- + string( pWarning^.szFilename )
- + ' [' + string( szMessage ) + ']' );
- end;
- end;
- end;
-
- end.
-
-