2015-01-21 9 views
4

WindowsAPICodePack을 사용하여 Win8/64bit에서 일부 탐색기/셸 작업 수행. x64 플랫폼 대상으로 파일 속성을 반복 할 때 AccessViolationException을 일으키는 propertysystem에 몇 가지 문제가 있습니다. PropVariant.cs에서 문제가있는 것 같습니다. x86으로 전환하면 문제는 해결되지만 디렉토리 목록이 불완전하게됩니다 (예 : system32/drivers에 "etc"가 누락되었습니다). 어떤 아이디어?C# WindowsApiCodepack PropertySystem AccessViolationException

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); 
     } 
    } 

답변

3

나는 PInvoke를 및 C++ 물건에 정말 모르겠지만, PropVariant.cs에 약간의 수정으로 source을 다시 컴파일했습니다

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

이이

+0

니스 문제를 해결 . 이것은 트릭을 수행합니다. 고마워! –