C# WindowsApiCodepack PropertySystem AccessViolationException
C# WindowsApiCodepack PropertySystem AccessViolationException
使用 WindowsAPICodePack 在 Win8/64bit 上做一些 explorer/shell 的事情。在使用 x64 平台目标迭代文件属性时,属性系统存在一些问题导致 AccessViolationException。似乎是 PropVariant.cs 中的一些问题。切换到 x86 可以解决这些问题,但会导致目录列表不完整(f.e。"etc" 在 system32/drivers 中缺失。有什么想法吗?
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++ 的东西,但我已经重新编译了 source 并在 PropVariant.cs 中做了一点修复:
//[FieldOffset(12)] original
[FieldOffset(16)]
IntPtr _ptr2;
这解决了问题
使用 WindowsAPICodePack 在 Win8/64bit 上做一些 explorer/shell 的事情。在使用 x64 平台目标迭代文件属性时,属性系统存在一些问题导致 AccessViolationException。似乎是 PropVariant.cs 中的一些问题。切换到 x86 可以解决这些问题,但会导致目录列表不完整(f.e。"etc" 在 system32/drivers 中缺失。有什么想法吗?
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++ 的东西,但我已经重新编译了 source 并在 PropVariant.cs 中做了一点修复:
//[FieldOffset(12)] original
[FieldOffset(16)]
IntPtr _ptr2;
这解决了问题