使用WindowsAPICodePack在Win8 / 64bit上执行一些资源管理器/ shell。在使用x64平台目标迭代fileproperties时,propertiesysystem遇到一些问题导致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);
}
}
答案 0 :(得分:3)
我并没有真正使用pinvoke和c ++的东西,但是我已经在PropVariant.cs中重新编译了source:
//[FieldOffset(12)] original
[FieldOffset(16)]
IntPtr _ptr2;
这解决了问题