C # WindowsApiCodepack PropertySystem AccessViolationException

Running any explorer / shell material on Win8 / 64bit using WindowsAPICodePack. Having some problems with the propertysystem causing an AccessViolationException when iterating over file properties with an x64 target platform. There seems to be a problem in PropVariant.cs. Switching to x86 fixes the problems, but leads to incomplete catalog lists (fe ", 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);
        }
    }
+4
source share
1 answer

I am not in pinvoke and C ++, but I recompiled the source with a little fix in PropVariant.cs:

//[FieldOffset(12)] original
    [FieldOffset(16)]
    IntPtr _ptr2;

and this fixed the problem

+3
source

All Articles