Doing some explorer/shell stuff on Win8/64bit with WindowsAPICodePack. Having some problems with the propertysystem causing an AccessViolationException when iterating over fileproperties with x64 platform target. Seems to be some problem in PropVariant.cs. Switching to x86 fixes the problems, but causes incomplete directory listings (f.e. "etc" missing in system32/drivers). Any ideas?
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);
}
}
I'm not really into pinvoke and c++ stuff, but I've recompiled the source with a little fix in PropVariant.cs :
//[FieldOffset(12)] original
[FieldOffset(16)]
IntPtr _ptr2;
and this fixed the issue