1,486
社区成员
发帖
与我相关
我的任务
分享
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
Private Declare Function InitCompression Lib "gzip.dll" () As Long
Private Declare Function CreateCompression Lib "gzip.dll" (ByRef context As Long, ByVal flags As Long) As Long
Private Declare Function DestroyCompression Lib "gzip.dll" (ByRef context As Long) As Long
Private Declare Function Compress Lib "gzip.dll" (ByVal context As Long, ByVal inBytes As Any, ByVal input_size As Long, ByVal outBytes As Long, ByVal output_size As Long, ByRef input_used As Long, ByRef output_used As Long, ByVal compressionLevel As Long) As Long
Private Const GZIP_LVL As Integer = 1
Public Function GZipCompress(ByteArray() As Byte) As Boolean
Dim hContext As Long '正文句柄
Dim output_used As Long '压缩后尺寸
Dim input_used As Long '未压缩尺寸
Dim buffer() As Byte
context = 0
output_used = 0
input_used = 0
InitCompression ' // 初始化压缩
CreateCompression hContext, GZIP_LVL
ReDim buffer(UBound(In_bytes))
If (Compress(hContext, ByteArray, UBound(ByteArray), buffer, UBound(buttfer), input_used, output_used, GZIP_LVL) <> 0) Then
GZipCompress=false
exit function
End If
GZipCompress=true
end function
Shell "c:\progra~1\winrar\rar a -r d:\mydir\myrar.rar d:\mydata\*.*",vbHide
Private Declare Function InitCompression Lib "gzip.dll" () As Long
Private Declare Function CreateCompression Lib "gzip.dll" (ByRef context As Long, ByVal flags As Long) As Long
Private Declare Function DestroyCompression Lib "gzip.dll" (ByRef context As Long) As Long
Private Declare Function Compress Lib "gzip.dll" (ByVal context As Long, ByRef inBytes As Any, ByVal input_size As Long, ByRef outBytes As Any, ByVal output_size As Long, ByRef input_used As Long, ByRef output_used As Long, ByVal compressionLevel As Long) As Long
Private Const GZIP_LVL As Integer = 1
Public Function GZipCompress(ByteArray() As Byte) As Boolean
Dim hContext As Long '正文句柄
Dim output_used As Long '压缩后尺寸
Dim input_used As Long '未压缩尺寸
Dim buffer() As Byte
Dim iReturn As long
context = 0
output_used = 0
input_used = 0
InitCompression ' // 初始化压缩
CreateCompression hContext, GZIP_LVL
ReDim buffer(UBound(ByteArray) + 255)
lReturn = Compress(ByVal hContext, ByteArray(0), UBound(ByteArray) + 1, buffer(0), UBound(buffer), input_used, output_used, GZIP_LVL)
End Function
已经不报错了,但是数据没有被压缩。 IReturn 值是 -2147024809
我怀疑还是 Compress 函数中的参数没写好。