Jump to content

7zip dll is not loading


Recommended Posts

I'm writing a script to automatically extract the contents out of a 7-zip file the user selects (contents are always another win-zip file with pdfs inside that 7-zip) and then merge the pdfs together inserting a blank page when needed.

Everything was going fine and all the examples and testing had no issues. When I started putting in the zip extraction into the main program, the 7zip dll stopped loading, even after reboot.

The examples won't even work. I've put message boxes in the udf to see how far along the script was getting and it is finding the dll and attempting to load the correct 32bit or 64bit version, but just simply fails to load.

this line here is returning -1

$hDLL_7ZIP = DllOpen($sNoCompiledPath & $sZip64Dll) ; Open x64 dll from no compiled path

I checked the variables and they are pointing right to the dll. So what would cause my computer to no longer load the dll? Windows7 64 bit with autoit v. 3.3.8.1

zip udf

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

  • Moderators

Well, I'm going to take a wild guess here since I've no idea what the variable values are:

$hDLL_7ZIP = DllOpen($sNoCompiledPath & "" & $sZip64Dll) ; Open x64 dll from no compiled path

?

Edit:

One way to check the issue:

If Not FileExists($sNoCompiledPath & $sZip64Dll) Then
   MsgBox(16 + 262144, "Error", $sNoCompiledPath & $sZip64Dll & " does not exist!")
EndIf

 

Edit2:

Another shot in the dark, might you have inadvertently corrupted the DLL if the above all works?

Have you tried with a fresh copy of the dll in that location?

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Sorry, yes the "" is there.

Global $sZip32Dll = "7-zip32.dll"    ;|If you intend to modify the original name of used dll, don't forget
Global $sZip64Dll = "7-zip64.dll"    ;|to modify _7ZipStartup() function in FileInstall section.
Global $sNoCompiledPath = @ScriptDir & "" ;The directory where dll files are for non compiled use
Global $sCompiledPath = @TempDir & ""  ;The directory where fileinstall dll files for compiled use
Global Const $FNAME_MAX32 = 512
Global $hArchiveProc
Global $hDLL_7ZIP = 0

It was working fine while I was initially setting up the script and running tests and checking out the examples, but when I was confident I had the code I needed the dll just stopped working. (the example scripts no longer worked as well as my script)

the example script:

#include <7Zip.au3>
#include <Array.au3>

$sArcName = 'ZipExample.zip'
$aFlist = _7ZipGetFilesList(0, $sArcName)
_ArrayDisplay($aFlist)

my script:

#include <Math.au3>
#include <File.au3>
#include <Array.au3>
#include <7Zip.au3>
Dim $filelist[1]
$blank = "H:\Client\BRVO\Daily\Print\Letters with Insert 27_LAP\Use this Insert Sheet\Bravo_LetterheadmailCotinine__FINAL11_24.pdf"
$blank1 = "H:\Client\BRVO\Daily\Print\TESTING FOLDER\Blank.pdf"

;If not FileExists(@ScriptDir & "\7-zip32.dll") Then
;   FileInstall("C:\Program Files (x86)\AutoIt3\Include\7-zip32.dll",@ScriptDir & "\7-zip32.dll")
;EndIf

;If not FileExists(@ScriptDir & "\7-zip64.dll") Then
;   FileInstall("C:\Program Files (x86)\AutoIt3\Include\7-zip64.dll",@ScriptDir & "\7-zip64dll")
;EndIf

If Not FileExists(@ScriptDir & "\PDFmerge.ini") Then
    IniWrite(@ScriptDir & "\PDFmerge.ini","LastFolder","1","")
    IniWrite(@ScriptDir & "\PDFmerge.ini","LastFolder","2","")
EndIf
;MsgBox(0,"",@error)
$zippath = IniRead(@ScriptDir & "\PDFmerge.ini","LastFolder","2","")
If $zippath = "" Then
    $zippath = "C:\"
EndIf
;MsgBox(0,"",$zippath)
$zip = FileOpenDialog("Select Zip",$zippath,"(*.zip)",3)
;MsgBox(0,"",@error)
if @error Then
    Exit
EndIf
;MsgBox(0,"",$zip)
$zippath = ""
$zipsplit = StringSplit($zip,"\")
$a = $zipsplit[0]
$zipname = StringTrimRight($zipsplit[$a],4)
For $i = 1 To UBound($zipsplit) -1
    If $i <> $zipsplit[0] Then
        $zippath = $zippath & "\" & $zipsplit[$i]
    EndIf
Next
$zippath = StringTrimLeft($zippath,1)
MsgBox(0,"",$zip)
IniWrite(@ScriptDir & "\PDFmerge.ini","LastFolder","2",$zippath)
$ziplist = _7ZipGetFilesList(0, "" & $zip & "")
$zipinzip = "n"
MsgBox(0,"",@error)
_ArrayDisplay($ziplist)
For $i = 1 To UBound($ziplist) - 1
    If StringRight($ziplist[$i],3) = ".7z" Then
        $7zipname = $ziplist[$i]
        $zipinzip = "y"
    EndIf
Next

If $zipinzip = "y" Then
    _7ZIPExtract(0, $zipname)
Else
    _7ZIPExtract(0, $zipname, StringTrimRight($zip,4))
EndIf

If $zipinzip = "y" Then
    _7ZIPExtract(0, $zipname, $zippath & "\" & StringTrimRight($7zipname,3))
Else
    $7zipname = $zipname
EndIf

;$sourcepath = IniRead(@ScriptDir & "\PDFmerge.ini","LastFolder","1","")
$var = $zippath & "\" & StringTrimRight($7zipname,3) & "\"

Then it goes on to the merging process.

I've tried re-extracting from the udf zip (the udf, examples and dlls) in case something got corrupt or something but it's still not loading the dll.

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

  • Moderators

Unfortunately I cannot download from the zip url's provided.  They seem to be offline or 404'd.

I don't see mention of x64 there, so my only other guess is that the dll structures within that isn't setup to run x64 dll.

Edit:

Nevermind, I have the link.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I'm thinking this may not be an Autoit problem but a pc problem since it was working but suddenly stopped.

Unfortunately I've not found anything on Google yet as to why a dll fails to load or how to fix it. (I've seen a lot of guessing and suggestions of reinstalling software and some mentions of windows security problem or something, but no answers yet)

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

  • Moderators

All the same, that udf isn't really setup for x64.  And @OSArch is the wrong method there.  You could be using x64 dll with 32bit exe just because OS is 64bit

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

It is trying to load the 64 bit dll, but I changed the udf so that both dll variables pointed to the 32 bit then set both to point at 64 bit and neither one would load :(

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

  • Moderators

And I'm sure you've tried restarting your pc?

The paths point to the script directory, I'm sure you have the dll available there as well? (even thought I see the fileinstall).

With and without the changes I made, I have them working (of course, I ran a 32bit exe and the 64bit dll was loaded as I thought without).  If you're running AV software, try adding an exception or turning them off for 15 minutes or so while you test.

Edit:

None of the changes I make to account for x64 dll are working properly... so the only change to make this run x64 vs x32  properly that should be made is:

This:

Func _7ZipStartup()
    If Not @Compiled Then ; If not compiled, test and open the right dll
        If Not FileExists($sNoCompiledPath & $sZip32Dll) And _
           Not FileExists($sNoCompiledPath & $sZip64Dll) Then Return SetError(2, 0, 0)
        If @OSArch = "X86" Then
            $hDLL_7ZIP = DllOpen($sNoCompiledPath & $sZip32Dll) ; Open x32 dll from no compiled path
        Else
            $hDLL_7ZIP = DllOpen($sNoCompiledPath & $sZip64Dll) ; Open x64 dll from no compiled path
        EndIf
    Else ; If compiled, test and open the right dll (that must be in ScriptDir for compiling)
        If @OSArch = "X86" Then
            If Not FileInstall("7-zip32.dll", $sCompiledPath & $sZip32Dll, 1) Then Return SetError(3, 0, 0)
            $hDLL_7ZIP = DllOpen($sCompiledPath & $sZip32Dll) ; Open x32 dll from FileInstall path
        Else
            If Not FileInstall("7-zip64.dll", $sCompiledPath & $sZip64Dll, 1) Then Return SetError(3, 0, 0)
            $hDLL_7ZIP = DllOpen($sCompiledPath & $sZip64Dll) ; Open x64 dll from FileInstall path
        EndIf
    EndIf
    If $hDLL_7ZIP = -1 Then Return SetError(1, 0, 0) ; If no dll handle, return error
    Return 1
EndFunc   ;==>_7ZipStartup

Should be:

Func _7ZipStartup()
    If Not @Compiled Then ; If not compiled, test and open the right dll
        If Not FileExists($sNoCompiledPath & $sZip32Dll) And _
           Not FileExists($sNoCompiledPath & $sZip64Dll) Then Return SetError(2, 0, 0)
        If Not @AutoItX64 Then
            $hDLL_7ZIP = DllOpen($sNoCompiledPath & $sZip32Dll) ; Open x32 dll from no compiled path
        Else
            $hDLL_7ZIP = DllOpen($sNoCompiledPath & $sZip64Dll) ; Open x64 dll from no compiled path
        EndIf
    Else ; If compiled, test and open the right dll (that must be in ScriptDir for compiling)
        If Not @AutoItX64 Then
            If Not FileInstall("7-zip32.dll", $sCompiledPath & $sZip32Dll, 1) Then Return SetError(3, 0, 0)
            $hDLL_7ZIP = DllOpen($sCompiledPath & $sZip32Dll) ; Open x32 dll from FileInstall path
        Else
            If Not FileInstall("7-zip64.dll", $sCompiledPath & $sZip64Dll, 1) Then Return SetError(3, 0, 0)
            $hDLL_7ZIP = DllOpen($sCompiledPath & $sZip64Dll) ; Open x64 dll from FileInstall path
        EndIf
    EndIf
    If $hDLL_7ZIP = -1 Then Return SetError(1, 0, 0) ; If no dll handle, return error
    Return 1
EndFunc   ;==>_7ZipStartup

But I do not believe that will fix your problem.  I can't replicate it (your issue) no matter how many times I run it.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Yeah, the first thing I tried was a reboot thinking maybe it just got stuck in ram or something but it's still happening. I've also got copies of the dll in every location I've been trying to use it.

*edit*

Still the same with the updated function. I can't figure it out either as it was working fine for days, then just suddenly wouldn't load anymore. I wish I knew more about dlls and how they work

Edited by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

Somehow got it working again. I went to he 7zip site and downloaded the newly released dll from the source files and changed the udf to use that one instead and after some fumbling around with code, I set it back to use the old ones and they are now loading fine again.

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

  • 1 year later...

I copied SmOke_N modified _7ZipStartup() to properly select dll and copied all the dlls from my 7Zip instal folder to scriptdir.

Problem solved, Thank you.  Actually I had a hard time finding the dlls, but it's working now b/c of your example.

Edited by Xandy
Link to comment
Share on other sites

  • 1 year later...

It seems quite an older topic, however just because i wandered against this issue today as well and to add the two cents of clearance that i definitely think are lacking in the answers above:
What i think is happening here is that the original author set up a generic source environment that allows you to use 64-bit or 32-bit plugin.

However, in order to call a 64-bit DLL plugin, you need to compile your executable as 64-bit as well, in that regard, the original author either misinterpreted the idea that you are capable of loading a 64-bit or 32-bit plugin directed by the OSARCH variable or simply expects you to understand this basic and alter the file manually. The hint behind the global zip-dll variable strings are indicating towards mandatory manual intervention.

If you want your application to be multiplatform supporting, your best bet is compiling it 32-bit and embedding the 32-bit dll using the FileInstall option.
To get the 7zip-au3 operating properly, you need to alter two lines in the code to enforce 7zip.au3 to load the 32-bit DLL file.
In that situation, you can later return it back to normal.

 

 

; #VARIABLES# ===================================================================================================================
Global $sZip32Dll = "7-zip32.dll"           ;|If you intend to modify the original name of used dll, don't forget
Global $sZip64Dll = "7-zip32.dll"           ;|to modify _7ZipStartup() function in FileInstall section.

Func _7ZipStartup()
.....
....
        If @OSArch = "X86" Then
            If Not FileInstall("7-zip32.dll", $sCompiledPath & $sZip32Dll, 1) Then Return SetError(3, 0, 0)
            $hDLL_7ZIP = DllOpen($sCompiledPath & $sZip32Dll) ; Open x32 dll from FileInstall path
        Else
            If Not FileInstall("7-zip32.dll", $sCompiledPath & $sZip64Dll, 1) Then Return SetError(3, 0, 0)
            $hDLL_7ZIP = DllOpen($sCompiledPath & $sZip64Dll) ; Open x64 dll from FileInstall path
        EndIf
....
....
EndFunc   ;==>_7ZipStartup

 

 

Better would be to simply copy the 7zip.au3 into two copies: 7zip32.au3 and 7zip64.au3, respectively renaming the functionnames by adding the 32 or 64 (_7zipStartup32()/_7zipStartup64()) extension and adding a warning in the 7zip64.au3 when running uncompiled that  user must compile his source into a 64-bit executable in order to make his executable work. However so far i have not been capable to run the 64-bit plugin in my development environment simply because the Scite that i use executes the 32 bit version of autoit hence testing your interpreted source edition from within SCITE might not work.

Regards,

LBSL

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...