Menu

7zip dll c++ example

Help
vlad
2013-04-25
2024-02-13
1 2 > >> (Page 1 of 2)
  • vlad

    vlad - 2013-04-25

    Hello,

    I'm a developer trying to make a small archive program using 7zip dll, but I can't figure out how to use it. I don't know where the CLSID and IID are defined, what IID to use in order to be able to compress multimple files into an archive.
    My code looks something like this:

    typedef int (_CreateObject)(const GUID clsid, const GUID iid, void *outObject);
    HMODULE hMod = LoadLibrary("7zra.dll");
    _CreateObject pfnCreate = (_CreateObject)GetProcAddress(hMod, "CreateObject");
    GUID CLSID_CFormat7z = {0x23170F69, 0x40C1, 0x2790, {0x10, 0x00, 0x00, 0x01, 0x10, 0x07, 0x00, 0x00}};
    GUID IID_Coder = {0x23170F69, 0x40C1, 0x278A, {0x00, 0x00, 0x00, 0x04, 0x00, 0x05, 0x00, 0x00}};

    ICompressCoder2 pCoder = NULL;
    int i = pfnCreate(&CLSID_CFormat7z, &IID_Coder, (void
    *)&pCoder);

    I always get a NULL pointer. Can anyone help me with a simple example please?

     
  • Igor Pavlov

    Igor Pavlov - 2013-04-26

    Try CPP\7zip\UI\Client7z example.

     
  • vlad

    vlad - 2013-04-26

    Thank you very much Igor.

     
  • ali

    ali - 2017-05-28

    Dear Igor

    I am trying to use your powerful library in vs 2015, i have built it using nmake, and now testing 7zClient sample, as I prompted in CMD
    "Client7z.exe l test.7z"
    the execution failed with error ("can't create archive file")

    or by CMD "Client7z.exe a test.7z test1.txt"
    the execution failed with error ("Can not open file as archive")

    would you tell me what happened? or how to use 7Zip in vs 2015 c++?

    Yours Sincerely

     
    • Igor Pavlov

      Igor Pavlov - 2017-05-28

      probably some problem with CMD.
      try another commands:

      7z.exe
      Client7z.exe
      7z.exe l test.7z
      Client7z.exe l test.7z
      
       
  • ali

    ali - 2017-05-28

    or Update Error

     
  • ali

    ali - 2017-05-28

    CMD has no error
    if 7z.exe downloaded from sourceforge is used, compresed-file content are listed properly with no error!

    I want to build from source files then use them in vs2015.

     
  • Igor Pavlov

    Igor Pavlov - 2017-05-28

    Show the log:

    Client7z.exe > log1.txt
    Client7z.exe l test.7z > log2.txt
    
     
  • ali

    ali - 2017-06-01

    finally i could use clinet7.exe to list zip file contents, the example works fine for zip files with extension .7z. but for .rar extension files, the line
    archive->Open(file, &scanSize, openCallback) != S_OK
    retruns true and then
    PrintError("Can not open file as archive", archiveName);

    how i fix this to open *.rar files?
    and how i bulid your libraray as c++ static lib?

     
  • ali

    ali - 2017-06-03

    i found how to solve last problem,

     
  • John Tadiparthi

    John Tadiparthi - 2022-07-07

    Hi Ali,

    We are looking for the C++ DLL or static lib version of Cleint7z which we can reference and use it for compressing. Did you manage to build it? If YES, can you please guide/share bit more details of how you managed it?

    Regards
    John

     
  • IgorSmet

    IgorSmet - 2023-08-14

    Hi all!
    Please tell me how you can use the ready library 7z.dll? How is this, for example, done in third-party applications like: PeaZip or WindowsRar ... ? The fact is that I cannot run the project Cleint7z in debug mode under my Visual Studio MFC project .....

     
  • Igor Pavlov

    Igor Pavlov - 2023-08-14

    I cannot run the project Cleint7z in debug mode under my Visual Studio MFC project .....

    If you can't run it, try to find the reason.
    Simplify situation:
    - use release mode instead of debug mode.
    - compile Cleint7z without MFC.
    - write here what version of Visual Studio.

     
  • Igor Pavlov

    Igor Pavlov - 2023-08-14

    just open
    CPP\7zip\UI\Client7z\Client7z.dsp
    project and compile/run it.

     
  • IgorSmet

    IgorSmet - 2023-08-21

    Hi all!
    With the help of Client7z.cpp it was possible to successfully unpack all archives of the format 7z.
    However, formats other than 7z are not decompressed.
    Can you please tell me whether it is possible to unpack other archive formats using the components included in the source https://7-zip.org/sdk.html ?

     
  • Igor Pavlov

    Igor Pavlov - 2023-08-21

    lzma sdk supports only 7z format.
    You need full 7-zip source code instead for all format types.
    Then you must use full 7z.dll from 7-zip, and just change clsid in Client7z.cpp.

    enum
    {
      kId_Zip = 1,
      kId_BZip2 = 2,
      kId_7z = 7,
      kId_Xz = 0xC,
      kId_Tar = 0xEE,
      kId_GZip = 0xEF
    };
    
    // use another id, if you want to support other formats (zip, Xz, ...).
    // DEFINE_GUID_ARC (CLSID_Format, kId_Zip)
    // DEFINE_GUID_ARC (CLSID_Format, kId_BZip2)
    // DEFINE_GUID_ARC (CLSID_Format, kId_Xz)
    // DEFINE_GUID_ARC (CLSID_Format, kId_Tar)
    // DEFINE_GUID_ARC (CLSID_Format, kId_GZip)
    DEFINE_GUID_ARC (CLSID_Format, kId_7z)
    
     
  • IgorSmet

    IgorSmet - 2023-08-21

    Thank you. Tried...
    All zip files were successfully unpacked.
    But, .rar format is not all. Those that were created in WinRar with a higher compression ratio were not unpacked.
    Archives .rar created in WindowsRar were successfully unpacked.
    Can you please tell me what can be done about it?

     
  • Igor Pavlov

    Igor Pavlov - 2023-08-21

    Try to unpack same "bad" rar with 7-Zip program.

     
  • IgorSmet

    IgorSmet - 2023-08-21

    This bad" rar with 7-Zip program unpacks successfully

     
  • IgorSmet

    IgorSmet - 2023-08-21

    Archives .rar in my program I tried to unpack with the value DEFINE_GUID_ARC (CLSID_Format, kId_Zip).
    In the list of 6 values, I did not see a format similar to Rar.
    Maybe you need to set another value CLSID_Format that matches the rar format?

     
  • Igor Pavlov

    Igor Pavlov - 2023-08-22
    Handler GUIDs:
    
    {23170F69-40C1-278A-1000-000110xx0000}
    
      01 Zip
      02 BZip2
      03 Rar
      04 Arj
      05 Z
      06 Lzh
      07 7z
      08 Cab
      09 Nsis
      0A lzma
      0B lzma86
      0C xz
      0D ppmd
    
      C0 AVB
      C1 LP
      C2 Sparse
      C3 APFS
      C4 Vhdx
      C5 Base64
      C6 COFF
      C7 Ext
      C8 VMDK
      C9 VDI
      CA Qcow
      CB GPT
      CC Rar5
      CD IHex
      CE Hxs
      CF TE
      D0 UEFIc
      D1 UEFIs
      D2 SquashFS
      D3 CramFS
      D4 APM
      D5 Mslz
      D6 Flv
      D7 Swf
      D8 Swfc
      D9 Ntfs
      DA Fat
      DB Mbr
      DC Vhd
      DD Pe
      DE Elf
      DF Mach-O
      E0 Udf
      E1 Xar
      E2 Mub
      E3 Hfs
      E4 Dmg
      E5 Compound
      E6 Wim
      E7 Iso
      E8 
      E9 Chm
      EA Split
      EB Rpm
      EC Deb
      ED Cpio
      EE Tar
      EF GZip
    
     
  • IgorSmet

    IgorSmet - 2023-08-22

    Thank you. Tried.
    If the value is - CLSID_Format {23170F69-40C1-278A-1000-000110030000} it still doesn't open the archive.
    Failed function HRESULT hrzlt = archive->Open(file, &scanSize, openCallback); hrzlt == 1

    Other types of popular archives open successfully.
    What else can you advise?

     
  • IgorSmet

    IgorSmet - 2023-08-22

    Substituted the value Rar5(0xCC) and everything turned out. Thank you

     
  • IgorSmet

    IgorSmet - 2023-08-22

    In Client7z.cpp If the library function IInaArchive::Extract is busy extracting a very large archive, is it possible
    to get the number of bytes extracted at the same time ??
    For the purpose of obtaining percentages.

     
  • Igor Pavlov

    Igor Pavlov - 2023-08-22
    Z7_COM7F_IMF(CArchiveExtractCallback::SetTotal(UInt64 /* size */))
    {
      return S_OK;
    }
    
    Z7_COM7F_IMF(CArchiveExtractCallback::SetCompleted(const UInt64 * /* completeValue */))
    {
      return S_OK;
    }
    
     
1 2 > >> (Page 1 of 2)

Log in to post a comment.