Using 7zip dll

Accessing

New member
Local time
Today, 04:04
Joined
Jul 28, 2016
Messages
5
So I'm trying to use the 7-zip32.dll to perform operations on files from Access rather than through the command line. But I can't get it to work, no matter what I try. The error is always the same:
Code:
Run-time error '453':
Can't find DLL entry point SevenZipOpenArchive in 7-zip32.dll
This is the code I tried:
Code:
Option Compare Database

Private Type tagINDIVIDUALINFO
    dwOriginalSize As Long
    dwCompressedSize As Long
    dwCRC As Long
    uFlag As Long
    uOSType As Long
    wRatio As Integer
    wDate As Integer
    wTime As Integer
    szFilename As String * 513
    dummy1 As String * 3
    szAttribute As String * 8
    szMode As String * 8
End Type
Private Declare Function SevenZipOpenArchive Lib "7-zip32.dll" (ByVal hwnd As Long, ByVal szFilename As String, ByVal dwMode As Long) As Long
Private Declare Function SevenZipCloseArchive Lib "7-zip32.dll" (ByVal harc As Long) As Long
Private Declare Function SevenZipFindFirst Lib "7-zip32.dll" (ByVal harc As Long, ByVal szWildName As String, lpSubInfo As tagINDIVIDUALINFO) As Long
Private Declare Function SevenZipFindNext Lib "7-zip32.dll" (ByVal harc As Long, lpSubInfo As tagINDIVIDUALINFO) As Long

Private Sub Command0_Click()
    Dim harc As Long
    
    harc = SevenZipOpenArchive(Me.hwnd, "C:\Program Files\7-Zip\readme.zip", 0)
End Sub
It does nothing so far, of course, but I'm trying to get that first step done and then keep going step by step, but I can't even do that. I'm keeping it simple, it's a form with only the one command button, then if I can at least finish that sub's run without errors I'll build upon that.
Of course, the dll file is registered (with regsvr32). I tried with "7-zip32" in the Lib variable, with the whole path ("C:\Program Files\7-Zip\7-zip32.dll"), nothing works, same error always.
Does any of you know how I should proceed? Thanks a lot!
 
You might want to state what you want your code to do.

Looking at those declarations there's nothing there that looks like it adds a file to an archive or extracts a file from an archive. Just Open, Close and Find functions. ?
 
I'm sorry, I didn't state what I wanted to do because I didn't think it mattered much. The fact was, I couldn't do anything, since I couldn't get the dll to work at all.
I found out that the dll that people used wasn't the one distributed with 7-zip, but a custom dll that you can download in a Japanese website. Once I pointed the Lib in my function to the path where I saved THAT dll it worked. I'm not an expert, I didn't know that there were some dll files compatible with Access and some that weren't until now (and still not even sure if that's the case or if something else happened). What I'm trying to do is getting the CRC of all the files in a folder, and if it's compressed, then get the CRC of the files inside it. Right now my function gets the CRC of the files INSIDE the compressed file, but not the CRC of the compressed file itself; it also doesn't work on rar files (unlike the 7zip's exe), but there seems to be libraries for rars as well, so I'll keep digging.
In any case, I guess it's not an Access Issue anymore. In regards to this thread, even though I'm still bumping into another problems, I finally got the dll to work. Should I mark it as solved or anything? If anyone cares about this in any case, I'll attach my code as it is right now. As I said, it won't return the CRC of the compressed file. It returns "-1" (error), which then will be converted to hex as FFFFFFFF. As it is right now, I'm simply printing the info in the debug info, while I'm figuring everything out. The ultimate goal is to find duplicates by CRC, not only inside a folder but also inside compressed files. But since I'm doing it in my free time, it's all baby steps until I have something done.

The output:
Code:
readme.zip - FFFFFFFF
readme.zip\readme.txt - BA9B7C66

The code:
Code:
Public Type tagINDIVIDUALINFO
    dwOriginalSize As Long
    dwCompressedSize As Long
    dwCRC As Long
    uFlag As Long
    uOSType As Long
    wRatio As Integer
    wDate As Integer
    wTime As Integer
    szFilename As String * 513
    dummy1 As String * 3
    szAttribute As String * 8
    szMode As String * 8
End Type
Public Declare Function SevenZipCheckArchive Lib "C:\Program Files\7-Zip\ForAccess\7-zip32.dll" (ByVal szFilename As String, ByVal imode As Long) As Long
Public Declare Function SevenZipOpenArchive Lib "C:\Program Files\7-Zip\ForAccess\7-zip32.dll" (ByVal hWnd As Long, ByVal szFilename As String, ByVal dwsize As Long) As Long
Public Declare Function SevenZipCloseArchive Lib "C:\Program Files\7-Zip\ForAccess\7-zip32.dll" (ByVal hArc As Long) As Long
Public Declare Function SevenZipFindFirst Lib "C:\Program Files\7-Zip\ForAccess\7-zip32.dll" (ByVal hArc As Long, ByVal szWildName As String, lpSubInfo As tagINDIVIDUALINFO) As Long
Public Declare Function SevenZipFindNext Lib "C:\Program Files\7-Zip\ForAccess\7-zip32.dll" (ByVal hArc As Long, lpSubInfo As tagINDIVIDUALINFO) As Long
Public Declare Function SevenZipGetCRC Lib "C:\Program Files\7-Zip\ForAccess\7-zip32.dll" (ByVal hArc As Long) As Long
Private udt7ZINDIVIDUALINFO As tagINDIVIDUALINFO
Private Declare Function apiGetActiveWindow Lib "user32" Alias "GetActiveWindow" () As Long
Private Declare Function apiGetParent Lib "user32" Alias "GetParent" (ByVal hWnd As Long) As Long

Public Sub sPrintInfoInDebug()
    Dim strFiles() As String
    Dim strFileName As String
    Dim intCounter As Integer
    
    strFiles = fListCompressedFilesAndCRC("C:\Program Files\7-Zip\readme.zip")
    If UBound(strFiles, 2) > 0 Then
        For intCounter = 1 To UBound(strFiles, 2)
            Debug.Print strFiles(1, intCounter) & " - " & strFiles(2, intCounter)
        Next
    End If
End Sub

Public Function fListCompressedFilesAndCRC(ByVal strPath As String) As String()
    Dim intCounter As Integer
    Dim lngResult As Long
    Dim strResult() As String
    Dim strFileName As String
    Dim strPathBuffer As String * 513
    
    ReDim strResult(1 To 2, 0)
    If SevenZipGetRunning = 0 Then
        strPathBuffer = strPath
        lngArcHandle = SevenZipOpenArchive(GetAccesshWnd, strPath, 0)
        If lngArcHandle <> 0 Then
            strFileName = Mid(strPath, InStrRev(strPath, "\") + 1) & "\"
            ReDim strResult(1 To 2, 1 To 1)
            strResult(1, 1) = Mid(strPath, InStrRev(strPath, "\") + 1)
            strResult(2, 1) = Hex(SevenZipGetCRC(lngArcHandle))
            If SevenZipCheckArchive(strPath, 1) > 0 Then
                If SevenZipFindFirst(lngArcHandle, "*", udt7ZINDIVIDUALINFO) = 0 Then
                    intCounter = 1
                    Do
                        intCounter = intCounter + 1
                        ReDim Preserve strResult(1 To 2, 1 To intCounter)
                        strResult(1, intCounter) = strFileName & Replace(udt7ZINDIVIDUALINFO.szFilename, Chr(0), "")
                        strResult(2, intCounter) = Hex(udt7ZINDIVIDUALINFO.dwCRC)
                    Loop While SevenZipFindNext(lngArcHandle, udt7ZINDIVIDUALINFO) = 0
                End If
            End If
            SevenZipCloseArchive (lngArcHandle)
        End If
    End If
    fListCompressedFilesAndCRC = strResult
End Function

Function GetAccesshWnd()
    Dim hWnd As Long
    Dim hWndAccess As Long

    ' Get the handle to the currently active window.
    hWnd = apiGetActiveWindow()
    hWndAccess = hWnd

    ' Find the top window (which has no parent window).
    While hWnd <> 0
        hWndAccess = hWnd
        hWnd = apiGetParent(hWnd)
    Wend

    GetAccesshWnd = hWndAccess

End Function
 
CRC, Cyclic redundancy check?

I don't really have an idea what that's all about, but I guess if you ever get it sorted somebody here might find it useful in the future.

Good luck.
 

Users who are viewing this thread

Back
Top Bottom