Re: Using 7Zip.dll in UNICODE [Resolved]
Posted: Sun Nov 10, 2019 2:50 am
Code: Select all
;
; PB 5.71 LTS (x86)
; 7Zip.dll IN UNICODE [Resolved]
; https://www.purebasic.fr/english/viewtopic.php?f=13&t=68262
; Latest 7-zip32.dll: http://www.csdinc.co.jp/archiver/lib/7-zip32.html#download
; 7-zip32 api doc: http://www.csdinc.co.jp/archiver/lib/7-zip32api-en.zip
;
EnableExplicit
Prototype.i SevenZip(Window.i, *CmdLine, *OutputAnsi, OutputSize.i)
Prototype.i SevenZipSetUnicodeMode(setUnicode.i)
Procedure$ SevenZipCmdLine(CmdLine$)
Protected Id7Zip.i, wn, *CmdLine, Output$, OutputUTF8$
Protected SevenZipSetUnicodeMode.SevenZipSetUnicodeMode
Protected SevenZip.SevenZip
Id7Zip=OpenLibrary(#PB_Any,"7-zip32.dll")
If Id7Zip
;Debug "Library 7-zip32.dll opened"
;If ExamineLibraryFunctions(Id7Zip)
; While NextLibraryFunction()
; Debug LibraryFunctionName()
; Wend
;EndIf
SevenZipSetUnicodeMode=GetFunction(Id7Zip, "SevenZipSetUnicodeMode")
If Not SevenZipSetUnicodeMode : Output$="SevenZipSetUnicodeMode procedure not present in 7-zip32.dll" : Goto SevenZipCmdLineOut : EndIf
SevenZip=GetFunction(Id7Zip, "SevenZip")
If Not SevenZip : Output$="SevenZip procedure not present in 7-zip32.dll" : Goto SevenZipCmdLineOut : EndIf
wn=OpenWindow(#PB_Any, 300, 200, 320, 200, "7zip",#PB_Window_ScreenCentered|#PB_Window_Invisible)
If wn
OutputUTF8$ = Space(32767)
*CmdLine = UTF8(CmdLine$)
SevenZipSetUnicodeMode(#True) ; Return value always TRUE.
If Not SevenZip(WindowID(wn), *CmdLine, @ OutputUTF8$, 32767)
Output$=PeekS(@ OutputUTF8$, -1, #PB_UTF8)
Else
Output$="An error occurred."
EndIf
EndIf
Else
Output$="7-zip32.dll not present"
EndIf
SevenZipCmdLineOut:
If Id7Zip : CloseLibrary(Id7Zip) : EndIf
If *CmdLine : FreeMemory(*CmdLine) : EndIf
ProcedureReturn Output$
EndProcedure
;Add to archive all files in the current directory
MessageRequester("", SevenZipCmdLine("a Test.zip *.*"))
;Test lists contents of the zip file
;Debug SevenZipCmdLine("l Test.zip")
MessageRequester("", SevenZipCmdLine("l TEST.zip"))