Jump to content

DllStruct help needed


Recommended Posts

Hi,

I want to use a DLL for unzipping, but I have a problem to create a struct, which is neede by the DLL.

Please, would somebody help me Bugfixing ?

the C/C++ struct of tPackRec

packdefs.pas.txt

My trial

$tPackRec = DllStructCreate('byte  internal;' & _
                                'int   Time;' & _
                                'int   Size;' & _
                                'int   CompressSize;' & _
                                'long  headeroffset;' & _
                                'str   FileName;' & _
                                'dword PackMethod;' & _
                                'dword Attr;' & _
                                'dword Flags')oÝ÷ Øay-çâ®Ëbµé­è§µêçjV«­¬¨}¼­z+-êÞjÊ'¦È9e    ©e}¨¥°mæè¶Ú&Ëay׬r¸©¶*'jÛZrv÷öÜ(®¼¢·ll¢ x    ÝêÞɲr©ë^r^jëh×6Global Const $ZIP_OK = 0
Global Const $ZIP_FILEERROR = -1
Global Const $ZIP_INTERNALERROR = -2
Global Const $ZIP_NOMOREITEMS = 1

Global Const $UNZIP_OK = 0
Global Const $UNZIP_CRCERR = 1
Global Const $UNZIP_WRITEERROR = 2
Global Const $UNZIP_READERROR = 3
Global Const $UNZIP_ZIPFILEERROR = 4
Global Const $UNZIP_USERABORT = 5
Global Const $UNZIP_NOTSUPPORTED = 6
Global Const $UNZIP_ENCRYPTED = 7
Global Const $UNZIP_INUSE = 1
Global Const $UNZIP_DLLNOTFOUND = 2

Global $sTextRes = 'The Returnvalue of Function = '

$sFile = @DesktopDir & '\SciTE4AutoIt3.zip'
$sDest = @ScriptDir

$hDLL = DllOpen('unzipd32.dll')
If $hDLL = -1 Then
    MsgBox(4096, 'Error', 'zlib1.dll konnte nicht geöffnet werden!')
Else
    $struct = DllStructCreate('str;str;dword;long;hwnd;int')
    $tPackRec = DllStructCreate('byte  internal;' & _
                                'int   Time;' & _
                                'int   Size;' & _
                                'int   CompressSize;' & _
                                'long  headeroffset;' & _
                                'str   FileName;' & _
                                'dword PackMethod;' & _
                                'dword Attr;' & _
                                'dword Flags')
    If IsZip($sFile) Then        
        $iZip = GetFirstInZip($sFile, DllStructGetPtr($tPackRec)) ; this function fails!    
        If $iZip = $ZIP_OK Then MsgBox(4096, 'GetFirstInZip', $sTextRes & $iZip)
        While $iZip = $ZIP_OK
            $iUnZip = UnZipFile($sFile, $sDest, DllStructGetData($tPackRec, 'Attr'), DllStructGetData($tPackRec, 'headeroffset'))
            If $iUnZip = $UNZIP_OK Then
                $iZip = GetNextInZip(DllStructGetPtr($tPackRec))
            Else
                $iZip = $ZIP_INTERNALERROR
            EndIf
        WEnd
        CloseZipFile(DllStructGetPtr($tPackRec))        
    Else
        MsgBox(4112, 'IsZip', 'Dies ist keine ZIP-Datei!')
    EndIf
    ;;;
    DllClose($hDLL)
EndIf

;==============================================================================
;        Functions
;==============================================================================

Func UnZipFile($sZipFile, $sDestDir, $dwAttr, $lHeaderoffset, $hFileAction = 0, $iIndex = 0)
    
    $aResult = DllCall($hDLL, 'int', 'unzipfile', 'str',   $sZipFile, _
                                                  'str',   $sDestDir, _
                                                  'dword', $dwAttr, _
                                                  'long',  $lHeaderoffset, _
                                                  'hwnd',  $hFileAction, _
                                                  'int',   $iIndex)
    Return $aResult[0]
    
EndFunc

Func GetFirstInZip($sZipFile, $ptPackRec)
    
    $aResult = DllCall($hDLL, 'int', 'GetFirstInZip', 'str', $sZipFile, 'ptr', $ptPackRec)
    Return $aResult[0]
    
EndFunc

Func GetNextInZip($ptPackRec)
    
    $aResult = DllCall($hDLL, 'int', 'GetNextInZip', 'ptr', $ptPackRec)
    Return $aResult[0]
    
EndFunc

Func CloseZipFile($ptPackRec)
    
    $aResult = DllCall($hDLL, 'none', 'CloseZipFile', 'ptr', $ptPackRec)
    
EndFunc

Func IsZip($sZipFile)
    
    $aResult = DllCall($hDLL, 'int', 'isZip', 'str', $sZipFile)
    Return $aResult[0]
    
EndFunc

The description

INFO_UNZ.TXT

The files

http://userpage.fu-berlin.de/~alibaba/pc/g...lists/unzip.zip

(the unzipd32.dll is packed in the Unzdl206.zip)

Thanx for reading this post.

Greetz

Greenhorn

Link to comment
Share on other sites

try

'byte internal[12];' instead of 'byte internal;'

You miss the length (I assume 12 bytes and not 11)

You're right, I noticed it already, thank you very much ! :D

And also I forgot a type in the struct : long CRC;

Aaaaand, I think FileName must be defined as char FileName[256];

Now GetFirstInZip is working without errors, the whole script runs now without errors, but nothing is unpacked :D

#cs ============================================================================

 AutoIt Version: 3.2.10.0
 Author:         Greenhorn

 Script Function:
    Template AutoIt script.

#ce ============================================================================

Global Const $ZIP_OK = 0                ; Unpacked ok
Global Const $ZIP_FILEERROR = -1        ; Error reading zip file
Global Const $ZIP_INTERNALERROR = -2    ; Error in zip file format
Global Const $ZIP_NOMOREITEMS = 1        ; Everything read
;    Error codes, delivered by unarjfile
Global Const $UNZIP_OK = 0                ; Unpacked ok
Global Const $UNZIP_CRCERR = 1            ; CRC error
Global Const $UNZIP_WRITEERROR = 2        ; Error writing out file: maybe disk full
Global Const $UNZIP_READERROR = 3        ; Error reading zip file
Global Const $UNZIP_ZIPFILEERROR = 4    ; Error in zip structure
Global Const $UNZIP_USERABORT = 5        ; Aborted by user
Global Const $UNZIP_NOTSUPPORTED = 6    ; ZIP Method not supported!
Global Const $UNZIP_ENCRYPTED = 7        ; Zipfile encrypted
Global Const $UNZIP_INUSE = 1            ; DLL in use by other program!
Global Const $UNZIP_DLLNOTFOUND = 2        ; DLL not loaded!

Global $sTextRes = 'The Returnvalue of Function = '

$sFile = @DesktopDir & '\SciTE4AutoIt3.zip'
If Not FileExists(@ScriptDir & '\SciTE\') Then
    $sDest = DirCreate(@ScriptDir & '\SciTE')
Else
    $sDest = @ScriptDir & '\SciTE'
EndIf

$hDLL = DllOpen('unzipd32.dll')
If $hDLL = -1 Then
    MsgBox(4096, 'Error', 'unzipd32.dll konnte nicht geöffnet werden!')
Else
;~     $struct = DllStructCreate('char[256];char[256];dword;long;hwnd;int')
    $tPackRec = DllStructCreate('byte  internal[12];' & _    ; Used internally by the dll
                                'int   Time;' & _            ; file time
                                'int   Size;' & _            ; file size
                                'int   CompressSize;' & _    ; size in zipfile
                                'long  headeroffset;' & _    ; file offset in zip: needed in unzipfile
                                'long  CRC;' & _             ; CRC, sort of checksum
                                'char  FileName[256];' & _    ; file name
                                'dword PackMethod;' & _        ; pack method, see below
                                'dword Attr;' & _            ; file attribute
                                'dword Flags')                ; lo byte: arj_flags; hi byte: file_type
    If IsZip($sFile) Then        
        $iZip = GetFirstInZip($sFile, DllStructGetPtr($tPackRec))
;~         If $iZip = $ZIP_OK Then MsgBox(4096, 'GetFirstInZip', $sTextRes & $iZip)
        While $iZip = $ZIP_OK
            $iUnZip = UnZipFile($sFile, $sDest, DllStructGetData($tPackRec, 'Attr'), DllStructGetData($tPackRec, 'headeroffset'), 0, 27)
            If $iUnZip = $UNZIP_OK Then
;~                 MsgBox(4096, 'UnZipFile', $sTextRes & $iUnZip)
                $iZip = GetNextInZip(DllStructGetPtr($tPackRec))
            Else
                $iZip = $ZIP_INTERNALERROR
                MsgBox(4112, 'ZIP_INTERNALERROR', $sTextRes & $iZip)
            EndIf
        WEnd
        CloseZipFile(DllStructGetPtr($tPackRec))        
    Else
        MsgBox(4112, 'IsZip', 'Dies ist keine ZIP-Datei!')
    EndIf
    ;;;
    DllClose($hDLL)
EndIf

;==============================================================================
;        Functions
;==============================================================================

;==============================================================================
; Function UnZipFile($sZipFile, $sDestDir, $dwAttr, $lHeaderoffset, $hFileAction = 0, $iIndex = 0)
;
;      $sZipFile:       name of zip file with full path (i.e 'c:\test.zip')
;      $sDestDir:       desired name for unzipped file, existing files are overwritten
;      $dwAttr:         File attribute, returned in tPackRec.Attr. Important to detect directories
;       $lHeaderoffset:  header position of desired file in zipfile, found in 
;                      tZiprec.headeroffset
;        $hFileAction:    handle to dialog box showing advance of decompression (optional),
;                      or zero when only keyboard shall be checked
;        $iIndex:   - if hfileaction<>0 : notification code sent in a wm_command
;                  message to the dialog to update percent-bar
;                - if hfileaction=0  : virtual key code of key the user must press
;                  to interrupt unzipping, i.e. vk_escape
;                  
;  Return value: one of the unzip_xxx codes
;==============================================================================
Func UnZipFile($sZipFile, $sDestDir, $dwAttr, $lHeaderoffset, $hFileAction = 0, $iIndex = 0)
    
    $aResult = DllCall($hDLL, 'int', 'unzipfile', 'str',   $sZipFile, _
                                                  'str',   $sDestDir, _
                                                  'dword', $dwAttr, _
                                                  'long',  $lHeaderoffset, _
                                                  'hwnd',  $hFileAction, _
                                                  'int',   $iIndex)
    Return $aResult[0]
    
EndFunc

Func GetFirstInZip($sZipFile, $ptPackRec)
    
    $aResult = DllCall($hDLL, 'int', 'GetFirstInZip', 'str', $sZipFile, 'ptr', $ptPackRec)
    Return $aResult[0]
    
EndFunc

Func GetNextInZip($ptPackRec)
    
    $aResult = DllCall($hDLL, 'int', 'GetNextInZip', 'ptr', $ptPackRec)
    Return $aResult[0]
    
EndFunc

Func CloseZipFile($ptPackRec)
    
    $aResult = DllCall($hDLL, 'none', 'CloseZipFile', 'ptr', $ptPackRec)
    
EndFunc

Func IsZip($sZipFile)
    
    $aResult = DllCall($hDLL, 'int', 'isZip', 'str', $sZipFile)
    Return $aResult[0]
    
EndFunc

Hmmm ... :D

Maybe the filename ...

How does AutoIt3 is defining strings ?

In C-style with NULL character at the end, or uses AutoIt the C++ string library for strings in $string ???

Do I have to add a \0 character to the filename or not ... :)

Edited by Greenhorn
Link to comment
Share on other sites

I also tried to use the _ZipPlugin.au3, but it extracts only one item and exits ...

Please could somebody gimme a wink in this case ?

#331689

#include-once
#Include '_ZipPlugin.au3'

$hPluginDll = PluginOpen('Au3Zip.dll')

_ZipUnZip(@DesktopDir & '\SciTE4AutoIt3.zip', @DesktopDir & '\install\SciTE\')

PluginClose($hPluginDll)
Exit
Edited by Greenhorn
Link to comment
Share on other sites

It might be a bug with the plugin. The code you have is correct, it is actually trying to extract the whle archive, but it just so happens that the 2nd file it tries to unzip is '/api/au3.user.calltips.api' which is a 0 byte file. The plugin fails at this point. If you delete that file out of the archive, you'll see it works fine.

Edit: I.E. Check this code-

#include-once
#Include '_ZipPlugin.au3'
$hPluginDll = PluginOpen('Au3Zip.dll')
MsgBox(0,"",_ZipFormatMessage(_ZipUnZip("C:\SciTE4AutoIt3.zip", "C:\inzip")))
PluginClose($hPluginDll)
Edited by evilertoaster
Link to comment
Share on other sites

I tried _ZipDeleteFile, but it doesn't work, doesn't it ?

#include-once
#include <Array.au3>
#Include '_ZipPlugin.au3'

$szZipFile = @DesktopDir & '\SciTE4AutoIt3.zip'
$szDestDir = @DesktopDir & '\install\SciTE2\'

$hPluginDll = PluginOpen('Au3Zip.dll')
$aZipList = _ZipList2Array($szZipFile)
_ArrayDisplay($aZipList)
$vResult = _ZipDeleteFile($szZipFile,'api\au3.user.calltips.api')
ConsoleWrite(_ZipFormatMessage($ZR_RECENT) & @CRLF)
$aZipList = _ZipList2Array($szZipFile)
_ArrayDisplay($aZipList)
;~ $vResult = _ZipUnZip($szZipFile, $szDestDir)
;~ ConsoleWrite(_ZipFormatMessage($ZR_RECENT))

PluginClose($hPluginDll)
Exit

. . . :D

EDIT:

Maybe it's better to post this problem in a new thread ...

Edited by Greenhorn
Link to comment
Share on other sites

I tried _ZipDeleteFile, but it doesn't work, doesn't it ?

#include-once
#include <Array.au3>
#Include '_ZipPlugin.au3'

$szZipFile = @DesktopDir & '\SciTE4AutoIt3.zip'
$szDestDir = @DesktopDir & '\install\SciTE2\'

$hPluginDll = PluginOpen('Au3Zip.dll')
$aZipList = _ZipList2Array($szZipFile)
_ArrayDisplay($aZipList)
$vResult = _ZipDeleteFile($szZipFile,'api\au3.user.calltips.api')
ConsoleWrite(_ZipFormatMessage($ZR_RECENT) & @CRLF)
$aZipList = _ZipList2Array($szZipFile)
_ArrayDisplay($aZipList)
;~ $vResult = _ZipUnZip($szZipFile, $szDestDir)
;~ ConsoleWrite(_ZipFormatMessage($ZR_RECENT))

PluginClose($hPluginDll)
Exit

. . . :D

EDIT:

Maybe it's better to post this problem in a new thread ...

I have fixed the bug in the plugin and have updated the links.

I forgot to try deleting the offending file before I fixed the plugin but I think it would have worked if filename was right.

Try replacing the backslash with a forward slash as it is shown in ArrayDisplay.

vResult = _ZipDeleteFile($szZipFile,'api/au3.user.calltips.api')
Link to comment
Share on other sites

Thank you very much for fixing this precious plugin with light speed Posted Image ! ! !

This fast service will set a new world record, doesn't it ?

And also thank you very much for the plugin itself, elTorro !!!

Greetz

Greenhorn

Edited by Greenhorn
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...