用VB访问RAR或者ZIP包中的数据,如何做到
注:分只给解决问题的人

解决方案 »

  1.   

    rar只能用shell调用rar.exe吧,在winrar安装目录下面有这个文件和一个文本的语法帮助,非常详尽。
    zip的话有一些dll可以下载,我个人觉得aunzip.dll好一些,这里有用法和下载:http://foxpro.diy.myrice.com/article/wjys.htm
      

  2.   

    Attribute VB_Name = "mRarSupport"Option ExplicitPrivate Type RAROPENARCHIVEDATA
        szArcName As Long               ' INPUT: Should point to a zero terminated string containing the archive name
        OpenMode As Long                ' INPUT: RAR_OM_LIST - Open archive for reading file headers only
                                        '        RAR_OM_EXTRACT - Open archive for testing and extracting files
        OpenResult As Long              ' OUTPUT: 0                 - Success
                                        '         ERAR_NO_MEMORY    - Not enough memory to initialize data structures
                                        '         ERAR_BAD_DATA     - Archive header broken
                                        '         ERAR_BAD_ARCHIVE  - File is not a valid RAR archive
                                        '         ERAR_EOPEN        - File open error
        szCmtBuf As Long                ' INPUT: Should point to a buffer for archive comments.
                                        '        Maximum comment size is limited to 64 KB. Comment text is zero termintad.
                                        '        If the comment text is larger than the buffer size, the comment text
                                        '        will be trunctated. If szCmtBuf is set to NULL, comments will not be read.
        CmtBufSize As Long              ' INPUT: Should contain size of buffer for archive comments
        CmtSize As Long                 ' OUTPUT: Containing size of comments actually read into the buffer.
                                        '         Cannot exceed CmtBufSize.
        CmtState As Long                ' State:
                                        ' 0                 - absent comments
                                        ' 1                 - Comments read completely
                                        ' ERAR_NO_MEMORY    - Not enough memory to extract comment
                                        ' ERAR_BAD_DATA     - Broken comment
                                        ' ERAR_UNKNOWN_FORMAT - Unknown comment format
                                        ' ERAR_SMALL_BUF    - Buffer too small, comments not completely read
    End TypePublic Type RARHEADERDATA
        Arcname As String * MAX_PATH         ' Contains the zero terminated string of the current archive name.
                                        ' Maybe used to determine the current volume name
        FileName As String * MAX_PATH        ' Contains the zero terminated string of the file name
        Flags As Long                   ' Flags
                                        ' bits 7 6 5 4 3 2 1 0
                                        '      0 0 0 0 0 0 0 1  &H1&    - file continued from previous volume
                                        '      0 0 0 0 0 0 1 0  &H2&    - file continues on next volume
                                        '      0 0 0 0 0 1 0 0  &H4&    - file encrypted with password
                                        '      0 0 0 0 1 0 0 0  &H8&    - file comment present
                                        '      0 0 0 1 0 0 0 0  &H10&   - compression of previous files is used
                                        '                                 (solid flag)
                                        '      0 0 0 0 0 0 0 0  &H00&   - dictionary size    64 KB
                                        '      0 0 1 0 0 0 0 0  &H20&   - dictionary size   128 KB
                                        '      0 1 0 0 0 0 0 0  &H40&   - dictionary size   256 KB
                                        '      0 1 1 0 0 0 0 0  &H60&   - dictionary size   512 KB
                                        '      1 0 0 0 0 0 0 0  &H80&   - dictionary size  1024 KB
                                        '      1 0 1 0 0 0 0 0  &HA0&   - reserved
                                        '      1 1 0 0 0 0 0 0  &HC0&   - reserved
                                        '      1 1 1 0 0 0 0 0  &HE0&   - file is directory
      

  3.   

    PackSize As Long                ' Packed file size or size of the file part if file was split between volumes
        UnpSize As Long                 ' UnPacked file size
        HostOS As Long                  ' Operating system used for archiving
                                        ' 0 - MS DOS
                                        ' 1 - OS/2
                                        ' 2 - Win32
                                        ' 3 - Unix
        FileCRC As Long                 ' unpacked CRC of file. '
                                        ' It should not be used for file parts which were split between volumes.
        'was  FILETIME As Long                ' Date & Time in standardMS-DOS format
        FileTime As Integer
        FileDate As Integer
                                        ' First 16 bits contain date
                                        '   Bits 0 - 4  : day (1-31)
                                        '   Bits 5 - 8  : month (1=January,12=December)
                                        '   Bits 9 - 15 : year (0=1980)
                                        ' Second 16 bits contain time
                                        '   Bits 0 - 4  : number of seconds divided by two
                                        '   Bits 5 - 10 : number of minutes (0-59)
                                        '   Bits 11 - 15: numer of hours (0-23)
        UnpVer As Long                  ' RAR version required to extract the file
                                        ' It is encoded as 10 * Major version + minor version
        Method As Long                  ' Packing method
        FileAttr As Long                ' File attributes
        CmtBuf As Long                  ' INPUT: Should point to a buffer for file comments.
                                        '        Maximum comment size is limited to 64 KB. Comment text is zero termintad.
                                        '        If the comment text is larger than the buffer size, the comment text
                                        '        will be trunctated. If szCmtBuf is set to NULL, comments will not be read.
        CmtBufSize As Long              ' INPUT: Should contain size of buffer for file comments
        CmtSize As Long                 ' OUTPUT: Containing size of comments actually read into the buffer.
                                        '         Should not exceed CmtBufSize.
        CmtState As Long                ' State:
                                        ' 0                 - absent comments
                                        ' 1                 - Comments read completely
                                        ' ERAR_NO_MEMORY    - Not enough memory to extract comment
                                        ' ERAR_BAD_DATA     - Broken comment
                                        ' ERAR_UNKNOWN_FORMAT - Unknown comment format
                                        ' ERAR_SMALL_BUF    - Buffer too small, comments not completely read
    End Type' Error constants
    'Private Const ERAR_END_ARCHIVE = 10&    ' end of archive
    'Private Const ERAR_NO_MEMORY = 11&      ' not enough memory to initialize data structures
    'Private Const ERAR_BAD_DATA = 12&       ' Archive header broken
    'Private Const ERAR_BAD_ARCHIVE = 13&    ' File is not valid RAR archive
    'Private Const ERAR_UNKNOWN_FORMAT = 14& ' Unknown comment format
    'Private Const ERAR_EOPEN = 15&          ' File open error
    'Private Const ERAR_ECREATE = 16&        ' File create error
    'Private Const ERAR_ECLOSE = 17&         ' file close error
    Private Const ERAR_EREAD = 18&          ' Read error
    Private Const ERAR_EWRITE = 19&         ' Write error
    ' Private Const ERAR_SMALL_BUF = 20&      ' Buffer too small, comment weren't read completely' OpenMode values
    Public Const RAR_OM_LIST = 0&           ' Open archive for reading file headers only
    Private Const RAR_OM_EXTRACT = 1        ' Open archive for testing and extracting files' Operation values
    Public Const RAR_SKIP = 0&              ' Move to the next file in archive
                                            ' Warning: If the archive is solid and
                                            ' RAR_OM_EXTRACT mode was set when the archive
                                            ' was opened, the current file will be processed and
                                            ' the operation will be performed slower than a simple seek
    'Private Const RAR_TEST = 1&             ' Test the current file and move to the next file in
                                            ' the archive. If the archive was opened with the
                                            ' RAR_OM_LIST mode, the operation is equal to RAR_SKIP
    Private Const RAR_EXTRACT = 2&          ' Extract the current file and move to the next file.
                                            ' If the archive was opened with the RAR_OM_LIST mode,
                                            ' the operation is equal to RAR_SKIP' ChangeVolProc-Mode-parameter-values
    'Private Const RAR_VOL_ASK = 0&          ' Required volume is absent. The function should
                                            ' prompt the user and return non-zero value to retry the
                                            ' operation. The function may also specify a new
                                            ' volume name, placing it to ArcName parameter
    'Private Const RAR_VOL_NOTIFY = 1&       ' Required volume is successfully opened. This is a
                                            ' notification call and ArcName modification is NOT
                                            ' allowed. The function should return non-zero value
                                            ' to continue or a zero value to terminate operation' Open RAR archive and allocate memory structures (about 1MB)
    ' parameters:   ArchiveData     - points to RAROpenArchiveData structure
    ' returns:  Archive handle or NULL in case of error