Problem with 7z sdk and C++ (with password)

  • Alessio

    Alessio - 2012-03-27

    I would like to use 7z sdk in my c++ program.
    I see the Client7z.cpp in lzma920\CPP\7zip\UI\Client7z but I still have 2 problems:

    1/ I can execute: Client7z.exe a mine.7z text1.txt text2.txt text3.txt to create a 7z archive with the three .txt files.
    But I cannot compress a full directory. So I would like to execute: Client7z.exe a mine.7z mydirectory and receive a 7z file with all the files of mydirectory.

    2/ When I try to compress with a password. So i do that in the Client7z.exe :

    if (!PasswordIsDefined)
        // You can ask real password here from user
        Password = L"123456";
        PasswordIsDefined = true;    
      return StringToBstr(Password, password);

    And also:

    updateCallbackSpec->PasswordIsDefined = true;
        updateCallbackSpec->Password = L"123456";

    where it's needed.

    But the problem is that when I execute : Client7z.exe a mine.7z text1.txt text2.txt
    When I try to open the mine.7z, no password is asked… and after that when i try to open text1.txt the password is asked.
    But I want to ask the password when I open the mine.7z.

    Could you help me please?

    Thanks :-)

  • Igor Pavlov

    Igor Pavlov - 2012-03-27

    1) Client7z is simplified version of 7z.exe. You can add "add directory" code.
    2) You must specify Header encription (-mhe switch in 7z.exe):
          const wchar_t *names =

    and replace properties to something like that:
          const wchar_t *names =
          const int kNumProps = sizeof(names) / sizeof(names);
          NCOM::CPropVariant values =

  • Alessio

    Alessio - 2012-03-27

    Thanks for your answer.
    For the second problem it's now ok! Your solution works good ;)

    For the add directory function, could you give me a little help?
    I would like to execute : Client7z.exe a myarchive.7z mydirectory
    and receive myarchive.7z with all the files from mydirectory but without the mydirectory directory.

    Thanks a lot.

  • Igor Pavlov

    Igor Pavlov - 2012-03-27

    Look EnumDirItems.cpp file and CDirItems::EnumerateDirectory function.
    You can write something similar that function.

  • Alessio

    Alessio - 2012-03-27

    I try to do something like that but it's difficult for me…

    If someone has already done that, I would like to see the code.

    Thanks a lot for the help.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks