我需要将zLib1.dll与Visual Basic.NET一起使用
我正在研究一些古老的C代码,它使用zLib1.dll来解压缩一个缓和文件。我需要一个例子,说明如何使用Visual Basic.NET访问DLL中的“解压缩”函数 我知道可能会出现这种情况,所以以下是我研究过的一些事情:我需要将zLib1.dll与Visual Basic.NET一起使用,.net,zlib,.net,Zlib,我正在研究一些古老的C代码,它使用zLib1.dll来解压缩一个缓和文件。我需要一个例子,说明如何使用Visual Basic.NET访问DLL中的“解压缩”函数 我知道可能会出现这种情况,所以以下是我研究过的一些事情: 我知道zLib1.dll有一个.NET包装器。事实上,如果您下载源代码,它甚至会出现在zip文件中。问题是帮助文件(chm)无法为我打开,因此我无法阅读文档 这可能是一个解决方案。。。我见过有人提到使用内置压缩。。。但这和zLib完全一样吗?如果一个文件没有使用与zLib相同的
Public Function AltDecompress(data As Byte()) As Byte()
Dim output = New MemoryStream()
Dim tmp As Byte() = GetDataBlock(data, 2) ' using .NET we have to strip the zLib header
Using compressedStream = New MemoryStream(tmp)
Using zlibStream = New DeflateStream(compressedStream, CompressionMode.Decompress)
zlibStream.CopyTo(output)
zlibStream.Close()
output.Position = 0
Return output.ToArray
End Using
End Using
End Function
Public Function GetDataBlock(ByRef Data As Byte(), ByVal start As Integer, Optional ByVal len As Integer = 0) As Byte()
' Extract a datablock from another datablock
' if len is not specified it will copy the entire block from the starting point to the end
Dim BlockLen As Integer = Data.Length - start ' Calculate the length of the data block
' Check if len was specified
If len = 0 Then
' if not grab everything from start to end
BlockLen = Data.Length - start
Else
' Grab just the data asked for
BlockLen = len
End If
Dim tmpBlock(BlockLen) As Byte ' Create the target array
Array.ConstrainedCopy(Data, start, tmpBlock, 0, BlockLen) ' Copy the data
Return tmpBlock ' return the block
End Function
我有两个建议给你:试着用内置功能解压文件,看看它是否有效。如果失败,谷歌如何在你使用的系统上打开chm文件。-第三,如果我的第一个建议无效:在
古C
中编写一个可以解压专有文件的应用程序,然后(re)使用.NET内置支持的算法对其进行压缩。如果有人遇到此问题,我会找到我自己问题的答案(某种程度上)。\upublic Shared Function解压缩(ByRef dest As Byte()、ByVal destlen As ULong、ByRef src As Byte()、ByVal srclen As ULong)作为Integer End函数
唯一的问题是,当它访问函数并执行我告诉它的操作时…它不起作用。抛出访问冲突,因此返回到绘图板。。。。