在win8/64位上用windowsapicodepack做一些explorer/shell的工作。在使用x64平台目标对文件属性进行迭代时,PropertySystem出现一些问题,导致AccessViolationException异常。在propvariant.cs中似乎有些问题。切换到x86可以修复这些问题,但会导致目录列表不完整(例如system32/drivers中缺少“etc”)。有什么想法吗?
using System;
using Microsoft.WindowsAPICodePack.Shell;
using Microsoft.WindowsAPICodePack.Shell.PropertySystem;
namespace ApiCodepackTest
{
class Program
{
const string path = @"c:\windows\system32\drivers";
static void Main(string[] args)
{
var shellObject = (ShellFolder)ShellObject.FromParsingName(path);
showProperties(shellObject);
showItems(shellObject);
Console.ReadLine();
}
static void showProperties(ShellFolder folder)
{
var sys = folder.Properties.System;
foreach (var prop in sys.GetType().GetProperties())
{
try
{
var shellProperty = prop.GetValue(sys) as IShellProperty;
if (shellProperty != null && shellProperty.ValueAsObject != null)
Console.WriteLine(shellProperty.CanonicalName + " " + shellProperty.ValueAsObject);
}
catch{} //you should not pass!
}
}
static void showItems(ShellFolder folder)
{
foreach (var i in folder)
Console.WriteLine(i.Name);
}
}
最佳答案
我不是很喜欢Pinvoke和C++的东西,但是我在propvariant.cs中重新编译了source:
//[FieldOffset(12)] original
[FieldOffset(16)]
IntPtr _ptr2;
这解决了问题
关于c# - C#WindowsApiCodepack PropertySystem AccessViolationException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28076941/