一个折磨了很久的7zip.dll回调函数问题
小弟最近在用VB调用7zip32.dll做一个解压7z文件的工具以下为模块代码:
Public Type tagEXTRACTINGINFO
dwFileSize As Long
dwWriteSize As Long
szSourceFileName As String * 513
dummy1 As String * 3
szDestFileName As String * 513
dummy As String * 3
End Type
Public Type tagEXTRACTINGINFOEX
exinfo As tagEXTRACTINGINFO
dwCompressedSize As Long
dwCRC As Long
uOSType As Long
wRatio As Long
wDate As Long
wTime As Long
szAttribute As String * 8
szMode As String * 8
End Type
Public Declare Function SevenZipSetOwnerWindowEx Lib "Files\7-zip32.dll" (ByVal hWnd As Long, ByVal lpArcProc As Long) As Long
Public Declare Function SafeArrayGetDim Lib "oleaut32.dll" (ByRef saArray() As Any) As Long
Public ExtractFiles() As String
Public strTemp As String
Public Function ArchiveProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal nState As Long, lpEis As tagEXTRACTINGINFOEX) As Boolean
'这个是回调函数。nstate=0时压缩或解压进行中。nstate=2时压缩或解压完毕。可回显lpEis下的参数。
If nState = 0 Then
问题:当在这里加如加入一些处理语句时,就解压不出任何东西,也没跳出任何错误信息!
Dim i As Long
If SafeArrayGetDim(ExtractFiles) = 0 Then
i = 0
Else
i = UBound(ExtractFiles) + 1
End If
ReDim Preserve ExtractFiles(i)
ExtractFiles(i) = lpEis.exinfo.szSourceFileName
如果把以上所有语句去掉,直接取得lpEis下的参数,(如:strTemp = lpEis.exinfo.szSourceFileName
,或者:Form1.Text1.Text= = lpEis.exinfo.szSourceFileName,则解压就顺利完成。
End If
ArchiveProc = True
End Function
SevenZipSetOwnerWindowEx Me.hWnd, AddressOf ArchiveProc‘回调
请问大神为何会出现次情况?是Dll文件本身的Bug吗? --------------------编程问答-------------------- 7z不是开源的吗 --------------------编程问答-------------------- 为什么不先sevenzipgetfilecount放个全局变量,然后在用变量作为下标定义数组?
感谢你的这个思路,让我的7zip解压有了进度条! --------------------编程问答-------------------- getfilecount要在回调之前,或者直接在回调之前就做个全局数组变量接收就好了。 --------------------编程问答-------------------- 就是说回调处理有速度要求,其实纯 VB 性能更好。
Public ExtractFiles() As String
Public FileCapacity As Long
Public FileCount As Long
Public Function ArchiveProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal nState As Long, lpEis As tagEXTRACTINGINFOEX) As Boolean
Dim sFileName As String
If nState = 0 Then
'第一时间取得数据'
sFileName = lpEis.exinfo.szSourceFileName
'空间成块增长'
If FileCount <= FileCapacity Then
FileCapacity = FileCapacity + 1024
ReDim Preserve ExtractFiles(FileCapacity - 1)
End If
'添加数据'
ExtractFiles(FileCount) = sFileName
FileCount = FileCount + 1
End If
ArchiveProc = True
End Function
补充:VB , API