Windows7下使用Shell32.dll出现没有实现接口的错误的解决办法

---恢复内容开始---

问题出现在Windows7系统上,在Windows10上运行没有问题。

问题描述:

1 客户给的lcscd3.xml文件,没有问题。压缩后再解压,也没问题。
2 将客户给的lcscd3.xml文件,压缩后上传到管理平台 xx.30,下载后上位机软件解压,出现错误:根目录数据无..
3 将客户给的lcscd3.xml文件,压缩后上传到管理平台 xx.30,下载后上用电脑自带解压工具,运行后出现,站点错误情况。

我考虑可能是因为压缩时用的WinRAR,解压时用的其他工具,可能是压缩时和解压时用到的算法不一致导致文件有差别。

解决办法:

用windows自带的解压工具在网上搜索到使用Shell32.dll库。

 public static Shell32.Folder GetShell32NameSpaceFolder(Object folder)
        {
            Type shellAppType = Type.GetTypeFromProgID("Shell.Application");

            Object shell = Activator.CreateInstance(shellAppType);
            return (Shell32.Folder)shellAppType.InvokeMember("NameSpace",
            System.Reflection.BindingFlags.InvokeMethod, null, shell, new object[] { folder });
        }

但是这种方式在Windows10上运行没有问题,在Windows7系统上却出现HRESULT:0x80004002 (E_NOINTERFACE),---- 我觉得是接口没能实现。

在国外网站上查看用反射解决该问题。

public static Shell32.Folder GetShell32NameSpaceFolder(Object folder)
{
  Type shellAppType = Type.GetTypeFromProgID("Shell.Application");
Object shell
= Activator.CreateInstance(shellAppType); return (Shell32.Folder)shellAppType.InvokeMember("NameSpace", System.Reflection.BindingFlags.InvokeMethod, null, shell, new object[] { folder }); } // Shell对象 //Shell32.Shell objShell = new Shell32.Shell(); // ZIP文件 Shell32.Folder sourceFile = GetShell32NameSpaceFolder(zipFile); // Shell32.Folder destinationFolder = GetShell32NameSpaceFolder(folderPath); // 遍历ZIP文件 foreach (var file in sourceFile.Items()) {   destinationFolder.CopyHere(file, 4 | 16); }

 

---恢复内容结束---

问题出现在Windows7系统上,在Windows10上运行没有问题。

问题描述:

1 客户给的lcscd3.xml文件,没有问题。压缩后再解压,也没问题。
2 将客户给的lcscd3.xml文件,压缩后上传到管理平台 xx.30,下载后上位机软件解压,出现错误:根目录数据无..
3 将客户给的lcscd3.xml文件,压缩后上传到管理平台 xx.30,下载后上用电脑自带解压工具,运行后出现,站点错误情况。

本人考虑可能是因为压缩时用的WinRAR,解压时用的其他工具,可能是压缩时和解压时用到的算法不一致导致文件有差别。

解决办法:

用windows自带的解压工具在网上搜索到使用Shell32.dll库。

 public static Shell32.Folder GetShell32NameSpaceFolder(Object folder)
        {
            Type shellAppType = Type.GetTypeFromProgID("Shell.Application");

            Object shell = Activator.CreateInstance(shellAppType);
            return (Shell32.Folder)shellAppType.InvokeMember("NameSpace",
            System.Reflection.BindingFlags.InvokeMethod, null, shell, new object[] { folder });
        }

但是这种方式在Windows10上运行没有问题,在Windows7系统上却出现HRESULT:0x80004002 (E_NOINTERFACE),---- 我觉得是接口没能实现。

在国外网站上查看用反射解决该问题。

public static Shell32.Folder GetShell32NameSpaceFolder(Object folder)
{
  Type shellAppType = Type.GetTypeFromProgID("Shell.Application");
Object shell
= Activator.CreateInstance(shellAppType); return (Shell32.Folder)shellAppType.InvokeMember("NameSpace", System.Reflection.BindingFlags.InvokeMethod, null, shell, new object[] { folder }); } // Shell对象 //Shell32.Shell objShell = new Shell32.Shell(); // ZIP文件 Shell32.Folder sourceFile = GetShell32NameSpaceFolder(zipFile); // Shell32.Folder destinationFolder = GetShell32NameSpaceFolder(folderPath); // 遍历ZIP文件 foreach (var file in sourceFile.Items()) {   destinationFolder.CopyHere(file, 4 | 16); }

 

posted on 2019-05-27 22:15  拾掇的往昔  阅读(379)  评论(0)    收藏  举报

导航