Using 7Zip.dll in UNICODE [Resolved]

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Using 7Zip.dll in UNICODE [Resolved]

Post by Kwai chang caine »

Hello at all :D

Before i use a code for use 7Zip.dll with PB
Since PB passing in UNICODE this code not works anymore :|
I have try to translate variable in ASCII but nothing works
If someone know how use it in the new version of PB

Code: Select all

Procedure.s SevenZipDossier(PbIdForm, Path7Zip.s, FolderSource.s, PathDestination.s)
  
 Id7Zip = OpenLibrary(#PB_Any, Path7Zip)
  
 If Id7Zip
    
  If FileSize(FolderSource) = - 2 
       
   PathAddBackslash_(@PathDestination)
   PathAddBackslash_(@FolderSource)
   NameZipFile$ = StringField(FolderSource, CountString(FolderSource, "\"), "\") + ".zip"
   NameZipFile$ = PathDestination + NameZipFile$
   
   *bufFolderSource = AllocateMemory(Len(FolderSource))
   PokeS(*bufFolderSource, FolderSource, -1, #PB_Ascii)

   *bufNameZipFile = AllocateMemory(Len(NameZipFile$))
   PokeS(*bufNameZipFile, NameZipFile$, -1, #PB_Ascii)

   OutputAnsi.s = Space(255)
   CmdLine$ =  "a -tzip -mx7 -ir!" + #DQUOTE$ + PeekS(*bufFolderSource, Len(FolderSource), #PB_Ascii) + "*.*" + #DQUOTE$ + " " + #DQUOTE$ + PeekS(*bufNameZipFile, Len(NameZipFile$), #PB_Ascii) + #DQUOTE$
   CallFunction(Id7Zip, "SevenZip", WindowID(PbIdForm), @CmdLine$, @OutputAnsi, 255)
   
   AnsiLen = Len(OutputAnsi)
   UniLen = MultiByteToWideChar_(#CP_ACP, 0, OutputAnsi, AnsiLen, 0, 0)
   
   If UniLen
    *Unicode = SysAllocStringLen_(0, UniLen)
    MultiByteToWideChar_(#CP_ACP, 0, OutputAnsi, AnsiLen, *Unicode, UniLen)
   EndIf
   
   Output.s = PeekS(*Unicode)
   Debug Output
 
  EndIf
  
  CloseLibrary(Id7Zip)
  
 EndIf

EndProcedure

#Window = 0
OpenWindow(#Window, x, y, 100, 100, "7zip")

SevenZipDossier(#Window, "C:\Temp\7-zip32.dll", "C:\Temp\FolderToZip\", "C:\Temp\")
Have a good day
Last edited by Kwai chang caine on Fri Apr 07, 2017 10:25 am, edited 1 time in total.
ImageThe happiness is a road...
Not a destination
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: Using 7Zip.dll in UNICODE

Post by Marc56us »

Hi KCC,

Sorry, not a reply to your question, but PB support 7z format since 5.10 (uncompress) and 5.40 (compress)
No need 7z DLL
I have not tested with unicode, but it should normally work ?

UseLZMAPacker()

:wink:
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Using 7Zip.dll in UNICODE

Post by Kwai chang caine »

Hello Marc :D

Yes i know that :wink:
But using 7Zip is reall more simple
With the packer you must enumerate all the folder recursively, take name of each file, etc...
With this DLL only the name of the parent folder ....and "rollen my chicken" :mrgreen:

Finally..it was simple...before the arrival of UNICODE :|
But thanks when even for your answer 8)
ImageThe happiness is a road...
Not a destination
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: Using 7Zip.dll in UNICODE

Post by Marc56us »

Yes, that's a good reason :)

In some case, I use command line version of 7z
(I never figured out how to use the dll version :oops: )

Apart from 7zFM (File Manager), there are two other exe in package
  • 7z.exe: use with runprogram in an hidden windows
  • 7zG.exe same way, for long operation.
    7zG (graphic) work as 7z.exe but diplay a window info with button to stop, pause etc.
    User can seen progress bar, number of files, and can stop. Very usefull.
    7zG does not open console window.

Code: Select all

; Using 7zG.exe (7 zip command line GRAPHIC version)

; Check if exist in standard location
Compressor.s = GetUserDirectory(#PB_Directory_Programs) + "7-zip\7zG.exe"
If FileSize(Compressor) < 0 
     End
EndIf

; Choose a big folder to have time to see 7 zip graphic information window
Source_Dir.s        = PathRequester("Directory to Backup ?", GetTemporaryDirectory())
Destination_File.s  = OpenFileRequester("Destination FileName", GetTemporaryDirectory(), "*.7z", 1)

If Source_Dir <> "" And Destination_File <> ""
     RunProgram(Compressor, "a " + Destination_File + " " + Source_Dir, GetTemporaryDirectory())
EndIf
:wink:
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Using 7Zip.dll in UNICODE

Post by Kwai chang caine »

Thanks a lot, i try your tips in the case of nobody know how solve my problem 8)

It's really magical the numeric, in few seconds we teleport both from france to english land :shock: :lol: :lol:

Image

Have a very good day my friend 8)
ImageThe happiness is a road...
Not a destination
User avatar
blueb
Addict
Addict
Posts: 1116
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: Using 7Zip.dll in UNICODE

Post by blueb »

Maybe you could use the 'lib' files from JHPJHP...

http://www.purebasic.fr/english/viewtop ... 12&t=61534
- It was too lonely at the top.

System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
normeus
Enthusiast
Enthusiast
Posts: 472
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: Using 7Zip.dll in UNICODE

Post by normeus »

kcc,
I see that you are actually creating the command line request:

Code: Select all

a -tzip -mx7 -ir!"c:\7zip\FolderToZip\*.*" "c:\7zip\FolderToZip.zip"
at that point you should be able to call 7zip.exe instead of calling DLL

I don't know which version of 7zip you are using or your PB version to test but you are not sending ASCII to DLL
once you put together the command request in unicode:

Code: Select all

cmdline$ = "a -tzip -mx7 -ir!" + "c:\temp\ToZIP\*.* "+"c:\temp\out.zip"
then PokeS the command to send:

Code: Select all

   *bufCmdLine  = AllocateMemory(Len(CmdLine$ ))
   PokeS(*bufCmdLine, CmdLine$, -1, #PB_Ascii)
then Disco with *bufCmdLine

Code: Select all

CallFunction(Id7Zip, "SevenZip", WindowID(PbIdForm), *bufCmdLine, @OutputAnsi, 255)

Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
loulou2522
Enthusiast
Enthusiast
Posts: 550
Joined: Tue Oct 14, 2014 12:09 pm

Re: Using 7Zip.dll in UNICODE

Post by loulou2522 »

Why not using packer native in Purebasic, i use it and that works perfectly even with zip file ?

exe.

Code: Select all

 UseZipPacker()

  ; Créer le fichier compressé
  If CreatePack(0, "MesFichiersCompresses.zip") 
  
    ; Ajouter vos fichiers 
    AddPackFile(0, "Image1.bmp", "Image1.bmp")  
    AddPackFile(0, "Image2.bmp", "Image2.bmp") 
    AddPackFile(0, "mywave1.wav", "mywave1.wav") 
    AddPackFile(0, "mywave2.wav", "mywave2.wav") 
    ClosePack(0) 
  EndIf
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Using 7Zip.dll in UNICODE

Post by Kwai chang caine »

@BlueB
Interesting link (like all jhpjhp do obviously)
I take a look to it
Thanks 8)

@Normeus
What a donkey i am :oops:
You have totately right, i mix ascii and unicode.
And since one hour i have try all i know, so nearly nothing :mrgreen:, without see the nose in the middle of the face :oops:
One thousand of thanks Normeus for your precious help

@loulou2522
I have already answering to this question above :wink:
http://www.purebasic.fr/english/viewtop ... 43#p505543
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Using 7Zip.dll in UNICODE

Post by Kwai chang caine »

Waaaaoooouuuhhh !!!
You are too strong NORMEUS !!! :shock:


This morning i test your code and exactely what you have say (Because yesterday, i answer you on my smartphone, so no test possible :| )
And that's works perfectly 8)

I have also adding

Code: Select all

AnsiLen = Len(OutputAnsi) * 4
Because i suppose the buffer need to be more big in UNICODE rather ASCII :idea:

I love you 8)
And thanks a lot for your precious help

@All
Have the best very good day of the world 8)

And long life to this splendid tool 7Zip
One of the last tool no programming in OOP :? , so that can be again used with our amazing PB 8)
ImageThe happiness is a road...
Not a destination
User avatar
Bisonte
Addict
Addict
Posts: 1313
Joined: Tue Oct 09, 2007 2:15 am

Re: Using 7Zip.dll in UNICODE [Resolved]

Post by Bisonte »

By the way ...

Code: Select all

   *bufFolderSource = AllocateMemory(Len(FolderSource))
   PokeS(*bufFolderSource, FolderSource, -1, #PB_Ascii)
is since PB5.60 shorter with

Code: Select all

*bufFolderSource = Ascii(FolderSource)
and you forget to free the memory at the end of your procedure...
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Using 7Zip.dll in UNICODE [Resolved]

Post by Kwai chang caine »

Hello BISONTE :D

Incredible !!! i don't know this function :shock:

It's the kind FRED, who think to all his numerous PB childrens.
Like a hen, watching over her little chicks, for make his life much more easy 8)

Image

This FRED... is really a mother for us !!! :mrgreen:

Thanks a lot BISONTE for this precious tips 8)

PS : I like your dog or wolf, he is really nice :wink:
ImageThe happiness is a road...
Not a destination
Taz
User
User
Posts: 75
Joined: Sat Jan 20, 2018 5:28 pm
Location: Germany

Re: Using 7Zip.dll in UNICODE

Post by Taz »

loulou2522 wrote:Why not using packer native in Purebasic, i use it and that works perfectly even with zip file ?

exe.

Code: Select all

 UseZipPacker()

  ; Créer le fichier compressé
  If CreatePack(0, "MesFichiersCompresses.zip") 
  
    ; Ajouter vos fichiers 
    AddPackFile(0, "Image1.bmp", "Image1.bmp")  
    AddPackFile(0, "Image2.bmp", "Image2.bmp") 
    AddPackFile(0, "mywave1.wav", "mywave1.wav") 
    AddPackFile(0, "mywave2.wav", "mywave2.wav") 
    ClosePack(0) 
  EndIf
That's great, BUT how can I add a file to an existing archive in PureBasic?
User avatar
DeanH
Enthusiast
Enthusiast
Posts: 278
Joined: Wed May 07, 2008 4:57 am
Location: Adelaide, South Australia
Contact:

Re: Using 7Zip.dll in UNICODE [Resolved]

Post by DeanH »

Thanks to a bit of help from Kwai chang caine, I have been able to produce a small procedure that takes 7-zip command line instructions. Output is a string containing whatever comes from the dll. It is assumed the dll is in the same directory as the calling program.

Code: Select all

Procedure$ SevenZip(CmdLine$)
  Protected Id7Zip,wn,Output$
  Id7Zip=OpenLibrary(#PB_Any,"7-zip32.dll")
  If Id7Zip
    wn=OpenWindow(#PB_Any, 300, 200, 320, 200, "7zip",#PB_Window_ScreenCentered|#PB_Window_Invisible)
    If wn
      OutputAnsi$ = Space(32767)
      *CmdLine = Ascii(CmdLine$)
      CallFunction(Id7Zip, "SevenZip", WindowID(wn), *CmdLine, @OutputAnsi$, 32767)
      Output$=PeekS(@OutputAnsi$, 32767, #PB_Ascii)
      FreeMemory(*CmdLine)
      CloseLibrary(Id7Zip)
      CloseWindow(wn)
    EndIf
  Else
    Output$="7-zip32.dll not present
  EndIf
  ProcedureReturn Output$
EndProcedure

;The test zips bmd files in the current directory
Debug SevenZip("a Test.zip *.bmd")
Debug ""
;Test lists contents of the zip file
Debug SevenZip("l Test.zip")

The 7-zip32.dll documentation includes a function SevenZipSetUnicodeMode. I tried this but it did not seem to allow the CmdLine$ input without changing it to ascii.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Using 7Zip.dll in UNICODE [Resolved]

Post by Kwai chang caine »

:wink:
ImageThe happiness is a road...
Not a destination
Post Reply