当前位置: 代码迷 >> C# >> win7环境下使用Shell32获取系统文件夹,部署在xp环境中出错,怎么解决
  详细解决方案

win7环境下使用Shell32获取系统文件夹,部署在xp环境中出错,怎么解决

热度:62   发布时间:2016-05-05 04:28:06.0
win7环境下使用Shell32获取系统文件夹,部署在xp环境中出错,如何解决?
win7环境下使用Shell32遍历系统文件夹,如下例:
Shell32.Shell shell32 = new Shell32.ShellClass();
Shell32.Folder shell32Folder = shell32.NameSpace(Win32API.ShellFolder.MyComputer);
Shell32.Folder desktopFolder = shell32.NameSpace(Win32API.ShellFolder.DesktopDirectory);
Shell32.FolderItems folderItems = desktopFolder.ParentFolder.Items();
foreach(Shell32.FolderItem folderItem in folderItems)
 { 
   if(folderItem.Name == desktopFolder.Title)
   {
      _parentListViewItem = new FolderListViewItem(folderItem);
      break;
   }
 }
但是部署在winxp上报错:
System.InvalidCastException: 无法将类型为“Shell32.ShellClass”的 COM 对象强制转换为接口类型“Shell32.IShellDispatch5”。
此操作失败的原因是对 IID 为“{866738B9-6CF2-4DE8-8767-F794EBE74F4E}”的接口的 COM 组件调用 QueryInterface 因以下错误而失败: 不支持此接口...

====================================================
只有将程序在winxp上重新编译一下,才可以。请问能否不需要在xp重新编译的情况下,正常部署。
------解决思路----------------------
最快的办法...在XP下开发该软体代码测试即可
------解决思路----------------------
Win7 和 XP 的 Shell32.dll 文件不同吧
  相关解决方案