Giter Club home page Giter Club logo

Comments (4)

Kitsune2222 avatar Kitsune2222 commented on July 21, 2024

The solution was found. It's just that after each Attach() call, you need to call Detach(). I think this is obvious, but I didn't immediately guess.

from p7zip.

jinfeihan57 avatar jinfeihan57 commented on July 21, 2024

Can you post your code? I can't open the picture. @Kitsune2222

from p7zip.

Kitsune2222 avatar Kitsune2222 commented on July 21, 2024

In my project need call IInArchive methods from different places (I'm wan't write Kotlin JNI binding for this library, for android). Me need store IInArchive pointer for opened archive, and i'm get it by Detach(). When me need IInArchive i'm get it by this saved pointer.

It not real, short, stupid code which cause this problem. It archive2->Extract() function not working when (archive1 and archive2) are in different methods which called from JNI:

CMyComPtr<IInArchive> archive;
CCodecs *c = new CCodecs;
HRESULT res = c->Load();
HRESULT res2 = c->CreateInArchive(archiveFormat, archive);
UInt64 maxPos = 4 * 1024 * 1024;
archive->Open(iStream, &maxPos, nullptr);
size_t pointer = (size_t) (void *) archive.Detach();
 // Method 1 (Get number of items)
CMyComPtr<IInArchive> archive1;
archive1.Attach((IInArchive *) pointer);
UInt32 numItems;
archive1->GetNumberOfItems(&numItems);
 // Method 2 (Extract)
 CMyComPtr<IInArchive> archive2;
archive2.Attach((IInArchive *) pointer);
archive2->Extract((UInt32 *) 0, (UInt32) -1, false, nullptr);

It's weird but when they are in the same function, it works now (Checked now). Doesn't work in different methods which called by JNI.

It working always:

CMyComPtr<IInArchive> archive;
CCodecs *c = new CCodecs;
HRESULT res = c->Load();
HRESULT res2 = c->CreateInArchive(archiveFormat, archive);
UInt64 maxPos = 4 * 1024 * 1024;
archive->Open(iStream, &maxPos, nullptr);
size_t pointer = (size_t) (void *) archive.Detach();
 // Method 1 (Get number of items)
CMyComPtr<IInArchive> archive1;
archive1.Attach((IInArchive *) pointer);
UInt32 numItems;
archive1->GetNumberOfItems(&numItems);
archive1.Detach();
 // Method 2 (Extract)
 CMyComPtr<IInArchive> archive2;
archive2.Attach((IInArchive *) pointer);
archive2->Extract((UInt32 *) 0, (UInt32) -1, false, nullptr);
archive2.Detach();

I don't know how to do it right, but second variant works. What do you say about this?
P.s. nullptr in callbacks it's temporarily code, i'm know.

Upd.
Taking this opportunity, I want to ask how to set different compression methods and other settings here when creating an archive?

from p7zip.

jinfeihan57 avatar jinfeihan57 commented on July 21, 2024

Maybe this will give you the answer.
https://github.com/stonewell/lib7zip

from p7zip.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.