求教用unzip32.dll解压缩.zip格式的文件的用法……

yxz32 2008-02-02 11:52:26
以下代码可以解压缩.rar格式的文件,但是不知道该如何解压.zip格式的。
请哪位知道的告诉我以下,万分感谢。
因为目前采用调用winzip的方式,但总觉得不太好,不如用dll来的安心。
所以请大家帮忙啊!
下面的是目前可以解压.rar格式文件的代码!

Const ERAR_END_ARCHIVE = 10
Const ERAR_NO_MEMORY = 11
Const ERAR_BAD_DATA = 12
Const ERAR_BAD_ARCHIVE = 13
Const ERAR_UNKNOWN_FORMAT = 14
Const ERAR_EOPEN = 15
Const ERAR_ECREATE = 16
Const ERAR_ECLOSE = 17
Const ERAR_EREAD = 18
Const ERAR_EWRITE = 19
Const ERAR_SMALL_BUF = 20

Const RAR_OM_LIST = 0
Const RAR_OM_EXTRACT = 1

Const RAR_SKIP = 0
Const RAR_TEST = 1
Const RAR_EXTRACT = 2

Const RAR_VOL_ASK = 0
Const RAR_VOL_NOTIFY = 1

Enum RarOperations
OP_EXTRACT = 0
OP_TEST = 1
OP_LIST = 2
End Enum

Private Type RARHeaderData
ArcName As String * 260
FileName As String * 260
Flags As Long
PackSize As Long
UnpSize As Long
HostOS As Long
FileCRC As Long
FileTime As Long
UnpVer As Long
Method As Long
FileAttr As Long
CmtBuf As String
CmtBufSize As Long
CmtSize As Long
CmtState As Long
End Type

Private Type RAROpenArchiveData
ArcName As String
OpenMode As Long
OpenResult As Long
CmtBuf As String
CmtBufSize As Long
CmtSize As Long
CmtState As Long
End Type

Private Declare Function RAROpenArchive Lib "unrar.dll" (ByRef ArchiveData As RAROpenArchiveData) As Long
Private Declare Function RARCloseArchive Lib "unrar.dll" (ByVal hArcData As Long) As Long
Private Declare Function RARReadHeader Lib "unrar.dll" (ByVal hArcData As Long, ByRef HeaderData As RARHeaderData) As Long
Private Declare Function RARProcessFile Lib "unrar.dll" (ByVal hArcData As Long, ByVal Operation As Long, ByVal DestPath As String, ByVal DestName As String) As Long
Private Declare Sub RARSetChangeVolProc Lib "unrar.dll" (ByVal hArcData As Long, ByVal Mode As Long)
Private Declare Sub RARSetPassword Lib "unrar.dll" (ByVal hArcData As Long, ByVal Password As String)

Private Sub Command5_Click()
End
End Sub

Private Sub RARExecute(Mode As RarOperations, RarFile As String, Optional Password As String)
' Description:-
' Extract file(s) from RAR archive.
' Parameters:-
' Mode = Operation to perform on RAR Archive
' RARFile = RAR Archive filename
' sPassword = Password (Optional)
Dim lHandle As Long
Dim iStatus As Integer
Dim uRAR As RAROpenArchiveData
Dim uHeader As RARHeaderData
Dim sStat As String, Ret As Long

uRAR.ArcName = RarFile
uRAR.CmtBuf = Space(16384)
uRAR.CmtBufSize = 16384

If Mode = OP_LIST Then
uRAR.OpenMode = RAR_OM_LIST
Else
uRAR.OpenMode = RAR_OM_EXTRACT
End If

lHandle = RAROpenArchive(uRAR)
If uRAR.OpenResult <> 0 Then OpenError uRAR.OpenResult, RarFile

If Password <> "" Then RARSetPassword lHandle, Password

If (uRAR.CmtState = 1) Then MsgBox uRAR.CmtBuf, vbApplicationModal + vbInformation, "Comment"

iStatus = RARReadHeader(lHandle, uHeader)
Show
Do Until iStatus <> 0
sStat = Left(uHeader.FileName, InStr(1, uHeader.FileName, vbNullChar) - 1)
Select Case Mode
Case RarOperations.OP_EXTRACT
List1.AddItem "Extracting " & sStat
Ret = RARProcessFile(lHandle, RAR_EXTRACT, "", uHeader.FileName)
Case RarOperations.OP_TEST
List1.AddItem "Testing " & sStat
Ret = RARProcessFile(lHandle, RAR_TEST, "", uHeader.FileName)
Case RarOperations.OP_LIST
List1.AddItem "File: " & sStat & vbTab & vbTab & vbTab & "Size: " & uHeader.UnpSize
Ret = RARProcessFile(lHandle, RAR_SKIP, "", "")
End Select

If Ret = 0 Then
List1.List(List1.ListCount - 1) = List1.List(List1.ListCount - 1) & vbTab & vbTab & "OK"
Else
ProcessError Ret
End If

iStatus = RARReadHeader(lHandle, uHeader)
Refresh
Loop

If iStatus = ERAR_BAD_DATA Then Erro ("File header broken")

RARCloseArchive lHandle
End Sub

Private Sub Form_Load()
Dim Vals() As String, Msg As String
Dim Command As String
Command = "x " & "D:\downloads\fscompr.zip" & " 0" '在这里用Commondilog 来确定你的文件路径。“X”,“0” 应该保留哦
If Command = "" Then
Msg = "VBUNRAR.EXE. This is a simple example of UNRAR.DLL usage" & vbCrLf & vbCrLf
Msg = Msg & "Syntax:" & vbCrLf
Msg = Msg & "VBUNRAR X <Archive> <Password> extract archive contents" & vbCrLf
Msg = Msg & "VBUNRAR T <Archive> <Password> test archive contents" & vbCrLf
Msg = Msg & "VBUNRAR L <Archive> <Password> view archive contents"
MsgBox Msg, vbApplicationModal + vbInformation, "VBUnRAR"
End
End If
Vals = Split(Command, " ")

ReDim Preserve Vals(2)
If Vals(0) = "" Or Vals(1) = "" Then Erro ("Missing arguments!")
Select Case UCase(Vals(0))
Case "X"
RARExecute OP_EXTRACT, Vals(1), Vals(2)
Case "T"
RARExecute OP_TEST, Vals(1), Vals(2)
Case "L"
RARExecute OP_LIST, Vals(1), Vals(2)
Case Else
Erro "Invalid Arguments!"
End Select
Command5.Enabled = True
End Sub

Private Sub OpenError(ErroNum As Long, ArcName As String)
Select Case ErroNum
Case ERAR_NO_MEMORY
Erro "Not enough memory"
Case ERAR_EOPEN:
Erro "Cannot open " & ArcName
Case ERAR_BAD_ARCHIVE:
Erro ArcName & " is not RAR archive"
Case ERAR_BAD_DATA:
Erro ArcName & ": archive header broken"
End Select
End Sub

Private Sub ProcessError(ErroNum As Long)
Select Case ErroNum
Case ERAR_UNKNOWN_FORMAT
Erro "Unknown archive format"
Case ERAR_BAD_ARCHIVE:
Erro "Bad volume"
Case ERAR_ECREATE:
Erro "File create error"
Case ERAR_EOPEN:
Erro "Volume open error"
Case ERAR_ECLOSE:
Erro "File close error"
Case ERAR_EREAD:
Erro "Read error"
Case ERAR_EWRITE:
Erro "Write error"
Case ERAR_BAD_DATA:
Erro "CRC error"
End Select
End Sub

Private Sub Erro(Msg As String)
MsgBox Msg, vbApplicationModal + vbExclamation, "Error"
End
End Sub
...全文
1282 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
szlili2013 2008-02-03
  • 打赏
  • 举报
回复
Function Wiz_SingleEntryUnzip Lib "unzip32.dll"
yxz32 2008-02-03
  • 打赏
  • 举报
回复
没有人知道吗?
不是吧。
请大家帮忙啊!
yxz32 2008-02-03
  • 打赏
  • 举报
回复
能否具体些呢?
这一函数没有参数吗?
该如何使用?
没用过。
yxz32 2008-02-02
  • 打赏
  • 举报
回复
其中这一行Command = "x " & "D:\downloads\fscompr.zip" & " 0" ,是我测试的.zip文件的地址,运行就提示该文件不是.rar文件,如果将这一行的原压缩文件换为"xxxx.rar"就可以正常解压。所以不知道该在哪里修改一下,可以解压.zip的文件呢。

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧