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;