-1

我正在尝试使用 Shell32.dll 解压缩一个简单的压缩文件。我有一个对 Shell32.dll 的引用,它在我的开发 PC(Win7 64)上显示为 Interop.Shell.dll。我通过文件副本从中心位置推出 exe 更新,我想为 .dll 执行此操作出色地。

该程序在 XP 上使用与我的 PC 上安装的相同文件失败。我尝试使用重命名为 Interop.Shell.dll 的 XP \Windows\System 中的 Shell.dll,但我想这很简单 - 当我尝试调用 dll 时,它会出现无法加载的错误。

我也打开了另一种解压缩方式,它使用与平台无关的 dll。我通过 Process.Start() 使用了 7Zip,但我想避免在客户端上安装/更新程序。

是否有一个共同点 Shell32.dll 我可以使用它可以在 XP 上/之后的任何 Win OS 上运行?

或者,如果我使用 Shell32.dll,我是否必须为每个操作系统创建单独的构建?

谢谢!

Function Unzip(FilePathofZip As String, DestinationFolder As String) As Boolean
    Try
        Dim sFile As String = FilePathofZip
        ' requires referenc to windows.system.shell32.dll
        Dim sc As New Shell32.Shell()

        If IO.Directory.Exists(DestinationFolder) Then IO.Directory.Delete(DestinationFolder, True)
        Application.DoEvents()
        IO.Directory.CreateDirectory(DestinationFolder)
        'Declare the folder where the files will be extracted
        Dim output As Shell32.Folder = sc.NameSpace(DestinationFolder)

        If FilePathofZip.EndsWith(".kmz") Then
            sFile = FilePathofZip & ".zip"
            IO.File.Move(FilePathofZip, sFile)
            Application.DoEvents()
        End If

        'Declare your input zip file as folder 
        Dim input As Shell32.Folder = sc.NameSpace(sFile)
        'Extract the files from the zip file using the CopyHere command .
        output.CopyHere(input.Items, 4)
        Return True
    Catch ex As Exception
        MsgBox(ex.Message)
        Return False
    End Try
End Function
4

1 回答 1

0

我切换到 DotNetZip。将项目引用添加到 Ionic.Zip.Reduced.dll。导入 Ionic.Zip

此代码需要从 ESRI REST 服务下载的 .kmz 文件,但也应与 .zip 文件一起使用。

Function Unzip(FilePathofZip As String, DestinationFolder As String) As Boolean
    ' extract .kmz files downloaded from ESRI REST services
    Try
        Dim sFile As String = FilePathofZip

        If IO.Directory.Exists(DestinationFolder) Then IO.Directory.Delete(DestinationFolder, True)
        Application.DoEvents()
        IO.Directory.CreateDirectory(DestinationFolder)

        If FilePathofZip.EndsWith(".kmz") Then
            sFile = FilePathofZip & ".zip"
            IO.File.Move(FilePathofZip, sFile)
            Application.DoEvents()
        End If

        Try
            ' Using... required
            Using zip As ZipFile = ZipFile.Read(sFile)
                Dim e As ZipEntry
                For Each e In zip
                    e.Extract(DestinationFolder)
                Next
            End Using
        Catch ex1 As Exception
            MsgBox("Problem with compressed file - notify programmers" & vbCrLf & ex1.Message)
            Return False
        End Try

        Return True
    Catch ex As Exception
        MsgBox(ex.Message)
        Return False
    End Try
End Function
于 2013-08-19T21:16:59.430 回答