[solved] 7-zip dll in AHK

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Masonjar13
Posts: 1528
Joined: 20 Jul 2014, 10:16
GitHub: Masonjar13
Location: Не Россия

[solved] 7-zip dll in AHK

12 Jan 2015, 04:53

I'm less than decent with dlls, but I'm in need of a dll to replace 7za.exe (command-line 7-Zip). I'm currently trying to use SevenZipSharp.dll with the following test script, with both the test archive and dll in the same directory as the script.

Code: Select all

sevPrc:=dllCall("LoadLibrary","Str","SevenZipSharp.dll","Ptr")
dllCall("SevenZipSharp\SevenZipExtractor",str,"wast.7z",str,"1") ; class constr - SevenZipExtractor(string file,string password)
dllCall("SevenZipSharp.dll\BeginExtractArchive",str,a_scriptdir) ; func - void BeginExtractArchive(string dir)
dllCall("FreeLibrary","Ptr",sevPrc)
I figured this wouldn't work, and it didn't, as the function is a member of a class (SevenZipExtractor). I'm not sure how to instantiate a class and call it's member in ahk, though. Line 2 and 3 both give me ErrorLevel -4. The process is being loaded, as it's ErrorLevel returns 0 and Process Explorer can find it attached to the script while running. There also, unfortunately, isn't a return value; I need to be able to tell if it was successfully extracted or not (maybe Check()?). For convenience, I've attached the help file for the dll.
Attachments
SevenZipSharpHelp.7z
(404.14 KiB) Downloaded 216 times
Last edited by Masonjar13 on 12 Jan 2015, 20:28, edited 1 time in total.
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
User avatar
jigga
Posts: 93
Joined: 24 Jan 2014, 00:31
Facebook: joel.fazio
Google: +JoelFazio

Re: 7-zip dll in AHK

12 Jan 2015, 13:34

Maybe try ExtractArchive(String) instead of BeginExtractArchive? I think the function you are using is meant to be asynchronous.
User avatar
Masonjar13
Posts: 1528
Joined: 20 Jul 2014, 10:16
GitHub: Masonjar13
Location: Не Россия

Re: 7-zip dll in AHK

12 Jan 2015, 13:57

Well, one thing at a time. First, I need to create the object of the class to be able to access either of those two functions. I don't know how to do that from a dll though.
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
User avatar
jigga
Posts: 93
Joined: 24 Jan 2014, 00:31
Facebook: joel.fazio
Google: +JoelFazio

Re: 7-zip dll in AHK

12 Jan 2015, 14:36

errorlevel -4 means the function could not be found. If it was a permission/path issue it would return errorlevel -3 or N where N is a positive number. I'm not super familiar with DLL stuff though, so idk lol.
HotKeyIt
Posts: 2224
Joined: 29 Sep 2013, 18:35
Contact:

Re: 7-zip dll in AHK

12 Jan 2015, 16:57

I think you could use it with .NET Framework Interop.

There is also 7-zip32.dll, it's a different dll/project and it works via DllCall.
User avatar
LinearSpoon
Posts: 156
Joined: 29 Sep 2013, 22:55

Re: 7-zip dll in AHK

12 Jan 2015, 17:10

Assuming you got the dll from here: https://sevenzipsharp.codeplex.com/
I've looked at it and it doesn't seem to export any functions at all. At least, not in the way DllCall wants them.

I don't know how easy it would be to get it working; I can't find an example of how to use a C# dll that doesn't involve "add a reference to it in visual studio". The actual 7-zip dll has some functions available, but the example provided in the source is too long for me to figure out how to use it in a reasonable amount of time.

Other than continuing to use the command line version, HotKeyIt's post looks most promising (though it probably won't work on 64 bit AHK).
User avatar
Masonjar13
Posts: 1528
Joined: 20 Jul 2014, 10:16
GitHub: Masonjar13
Location: Не Россия

Re: 7-zip dll in AHK

12 Jan 2015, 19:45

I actually have 7-zip32.dll, but I couldn't find support for using a password. Is that what DWORD _dwMode is suppose to be for (presuming SevenZipOpenArchive is the function I should be looking at)?
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
User avatar
Masonjar13
Posts: 1528
Joined: 20 Jul 2014, 10:16
GitHub: Masonjar13
Location: Не Россия

Re: 7-zip dll in AHK

12 Jan 2015, 20:17

Got it (stole a function from shajul's library)

Code: Select all

sevPrc:=dllCall("LoadLibrary","Str","7-zip32.dll","Ptr")
file:="wast.7z",pass:=1
7Zip__SevenZip("e """ file """ -p" pass " -y")

dllCall("FreeLibrary","Ptr",sevProc)
exitapp

7Zip__SevenZip(sCommand) {
  nSize := 32768
  VarSetCapacity(tOutBuffer,nSize)
  aRet := DllCall("7-zip32\SevenZip", "Ptr", hWnd
          ,"AStr", sCommand
          ,"Ptr", &tOutBuffer
          ,"Int", nSize)
  If !ErrorLevel
    return StrGet(&tOutBuffer,nSize,"CP0"), ErrorLevel := aRet
  else
    return 0
}
Now, can I make this not show a visible window?
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
User avatar
Masonjar13
Posts: 1528
Joined: 20 Jul 2014, 10:16
GitHub: Masonjar13
Location: Не Россия

Re: 7-zip dll in AHK

12 Jan 2015, 20:27

HotKeyIt wrote:Use -hide option.
That was painfully obvious.. It makes my mouse twitch a bit, but it will do.

Much appreciation to all replies.
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
User avatar
Masonjar13
Posts: 1528
Joined: 20 Jul 2014, 10:16
GitHub: Masonjar13
Location: Не Россия

Re: [solved] 7-zip dll in AHK

13 Jan 2015, 15:39

Following the suggested methods in the help, I've loaded the library and then got the handle of the function to use directly. Besides that, how can I make it any faster?

Current environment demonstration:

Code: Select all

SetBatchLines -1
Process,Priority,,H
sevPrc:=dllCall("LoadLibrary","Str",tmp "\7-zip64.dll","Ptr")
global sevProc := dllCall("GetProcAddress","Ptr",sevPrc,"AStr","SevenZip","Ptr")
Currently averages at 69ms. If I can get it at atleast below 50ms, it should be okay, but I'd prefer much lower if possible. Any additional code isn't relative as the timings only covered the dll function call. Using Winmm\time[Begin/End]Period doesn't seem to make a difference.
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
HotKeyIt
Posts: 2224
Joined: 29 Sep 2013, 18:35
Contact:

Re: [solved] 7-zip dll in AHK

13 Jan 2015, 16:03

Can you post the code you used for timings?
User avatar
Masonjar13
Posts: 1528
Joined: 20 Jul 2014, 10:16
GitHub: Masonjar13
Location: Не Россия

Re: [solved] 7-zip dll in AHK

13 Jan 2015, 16:29

Sure. Just use any supported archive with a password that isn't numeric and this'll work just fine.

Code: Select all

#SingleInstance Force
#Persistent
SetBatchLines -1
Process,Priority,,H
sevPrc:=dllCall("LoadLibrary","Str","7-zip64.dll","Ptr")
global sevProc := dllCall("GetProcAddress","Ptr",sevPrc,"AStr","SevenZip","Ptr")
cnt:=100,file:="test.7z"
global dlltme

timing:=a_tickcount
Loop % cnt
    7ZipCLine("e """ file """ -p" a_index " -y -hide")
timing:=a_tickcount - timing
msgbox % "Timing: " timing " Average: " timing//cnt "`nDll timing: " dlltme " Average: " dlltme//cnt
dllCall("FreeLibrary","Ptr",sevPrc)
exitapp

7ZipCLine(sCommand) {
;    DllCall("Winmm\timeBeginPeriod", uint, 3)
    nSize := 32768
    VarSetCapacity(tOutBuffer,nSize)
    tme:=a_tickcount
    aRet := dllCall(sevProc, "Ptr", hWnd,"AStr", sCommand,"Ptr", &tOutBuffer,"Int", nSize)
    dlltme+=a_tickcount - tme
;    DllCall("Winmm\timeEndPeriod", UInt, 3)
    if(!ErrorLevel)
        return ErrorLevel := aRet
    return 0
}
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
User avatar
jigga
Posts: 93
Joined: 24 Jan 2014, 00:31
Facebook: joel.fazio
Google: +JoelFazio

Re: [solved] 7-zip dll in AHK

13 Jan 2015, 17:18

You could always buy a beastly mac pro and run windows on it. The programmer at my work bought the stock version and runs windows in VM. It out performs my new high end gaming PC by a large margin :\
HotKeyIt
Posts: 2224
Joined: 29 Sep 2013, 18:35
Contact:

Re: [solved] 7-zip dll in AHK

13 Jan 2015, 17:36

Try this:

Code: Select all

#SingleInstance Force
#Persistent
SetBatchLines -1
Process,Priority,,H
global sevProc:=dllCall("GetProcAddress","Ptr",dllCall("LoadLibrary","Str","7-zip64.dll","Ptr"),"AStr","SevenZip","Ptr")
cnt:=100,file:="test.7z",timing:=a_tickcount
Loop % cnt
    dllCall(sevProc, "Ptr", A_ScriptHwnd,"AStr"
        ; command line
        , "e """ file """ -p" a_index " -y -hide"
        ,"Ptr", 0,"Int", 0)
timing:=a_tickcount - timing
msgbox % "Timing: " timing " Average: " timing//cnt "`nDll timing: " dlltme " Average: " dlltme//cnt
exitapp
User avatar
Masonjar13
Posts: 1528
Joined: 20 Jul 2014, 10:16
GitHub: Masonjar13
Location: Не Россия

Re: [solved] 7-zip dll in AHK

13 Jan 2015, 17:47

jigga wrote:You could always buy a beastly mac pro and run windows on it. The programmer at my work bought the stock version and runs windows in VM. It out performs my new high end gaming PC by a large margin :\
Never. I have not and will not purchase an Apple product, under any circumstance.

I'm running an i7-4820k at 4.3GHz, with 16GB RAM at 2.4GHz. Those are both at safe, standard-usage clocks.
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
User avatar
Masonjar13
Posts: 1528
Joined: 20 Jul 2014, 10:16
GitHub: Masonjar13
Location: Не Россия

Re: [solved] 7-zip dll in AHK

13 Jan 2015, 18:13

HotKeyIt wrote:Try this
Little to no difference. Notes: running in real-time seems to make it slower (?), upon doubling the iterations, it becomes slightly slower (both versions).
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
User avatar
jigga
Posts: 93
Joined: 24 Jan 2014, 00:31
Facebook: joel.fazio
Google: +JoelFazio

Re: [solved] 7-zip dll in AHK

13 Jan 2015, 19:22

Masonjar13 wrote:
jigga wrote:You could always buy a beastly mac pro and run windows on it. The programmer at my work bought the stock version and runs windows in VM. It out performs my new high end gaming PC by a large margin :\
Never. I have not and will not purchase an Apple product, under any circumstance.

I'm running an i7-4820k at 4.3GHz, with 16GB RAM at 2.4GHz. Those are both at safe, standard-usage clocks.
I hate apple as well, but that machine is just a beast. Of course it costs the same as 4 of my cars :\
zotune
Posts: 83
Joined: 17 Nov 2014, 17:57

Re: [solved] 7-zip dll in AHK

18 Sep 2015, 09:24

HotKeyIt wrote:Try this:

Code: Select all

#SingleInstance Force
#Persistent
SetBatchLines -1
Process,Priority,,H
global sevProc:=dllCall("GetProcAddress","Ptr",dllCall("LoadLibrary","Str","7-zip64.dll","Ptr"),"AStr","SevenZip","Ptr")
cnt:=100,file:="test.7z",timing:=a_tickcount
Loop % cnt
    dllCall(sevProc, "Ptr", A_ScriptHwnd,"AStr"
        ; command line
        , "e """ file """ -p" a_index " -y -hide"
        ,"Ptr", 0,"Int", 0)
timing:=a_tickcount - timing
msgbox % "Timing: " timing " Average: " timing//cnt "`nDll timing: " dlltme " Average: " dlltme//cnt
exitapp
Does this work to extract a file? I can't seem to get it to work.
Also, do you by any chance have an example for compressing a file with ultra compression?

Return to “Ask For Help”

Who is online

Users browsing this forum: Bodhi, boiler, mikeyww, PuzzledGreatly, vanheartnet098, wineguy and 54 guests