Simple decompression using 7z. dll

Source: Internet
Author: User

First go to The 7z official website to downloadCode7zSource codeOr lzma can be used, but the source code of 7z is recommended, and everything in it is comprehensive.

7z. dll works through the COM interface. However, it does not use the standard COM interface. If there is a com base, its code will be easier.

A simple example is/CPP/7zip/UI/client7z, which contains simple compression, decompression, and viewing of compressed package files. The source code of 7z. dll is in bundles/7 zformatf.

The codes of clinet7z and file manager seem to be easy to understand. You can follow them step by step. // Update later at night

7z. dll uses the COM interface, but it does not use the standard COM interface.

Decompression of files mainly relies on the following two callback classes

/Archive open callback class

// Class carchiveopencallback for opening compressed files:

Public iarchiveopencallback,

Public icryptogettextpassword,

Public cmyunknownimp

 

// Extract the callback class carchiveextractcallback:

Public iarchiveextractcallback,

Public icryptogettextpassword,

Public cmyunknownimp

Extracting the callback class

// Iprogress

Stdmethod (settotal) (uint64 size); // obtain the total number of bytes of the pressurized File

Stdmethod (setcompleted) (const uint64 * completevalue); // obtain the size of the currently decompressed file in bytes. You can use this callback function to calculate the current decompression progress.

// Iarchiveextractcallback

Stdmethod (getstream) (uint32 index, isequentialoutstream ** outstream, int32 askextractmode); // get the file stream,

Lresult myreleasesteam (); // when unzipping is canceled, the reason why the control of the released file stream is canceled and unzipped does not go to the setoperationresult () callback function, and the released file stream is in this function, therefore, you must release it yourself.

// Obtain interface functions

Createobjectfunc = (createobjectfunc) Lib. getproc ("Createobject ");

Cmycomptr <iinarchive> archive;

Errorcode = createobjectfunc (& clsid_cformat7z, & iid_iinarchive, (void **) & archive );

Cinfilestream * filespec = new cinfilestream;

Cmycomptr <iinstream> file = filespec;

Ustring archivename = getunicodestring (infile );

If (! Filespec-> open (archivename ))

{

// Cannot open the compressed file (this file cannot be found)

Return;

}

Carchiveopencallback * opencallbackspec = new carchiveopencallback;

Cmycomptr <iarchiveopencallback> opencallback (opencallbackspec );

Opencallbackspec-> passwordisdefined = false;

Errorcode = archive-> open (file, 0, opencallback );

If (errorcode! = S_ OK)

Return;

// Extract command

Carchiveextractcallback * extractcallbackspec = new carchiveextractcallback;

Cmycomptr <iarchiveextractcallback> extractcallback (extractcallbackspec );

Extractcallbackspec-> Init (archive, OUTFILE); // second parameter is Output Folder path

Extractcallbackspec-> passwordisdefined = false;

Extractcallbackspec-> setfileinfo (Info );

// Extractcallbackspec-> passwordisdefined = true;

// Extractcallbackspec-> Password = l "1 ";

Errorcode = archive-> extract (null, (uint32) (int32) (-1), false, extractcallback );

If (errorcode! = S_ OK)

Return;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.