Использование IFolderView :: GetSortColumns в C # для сортировки элементов в папке

В настоящее время я пытаюсь программно отсортировать папку из Windows Explorer в C #. Но как ни странно, я продолжаю нажимать «System.AccessViolationException».

Мой код следующий:

Program.cs:

WinAPI.SORTCOLUMN test = new WinAPI.SORTCOLUMN();
//At this point it is assumed that a shellView-Object of the correct windows explorer window is beeing casted to type folderView2 of type IFolderView2
folderView2.GetSortColumns(ref test, columnCount); //System.AccessViolationException hits. What to do?

WinAPI.cs:

[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("cde725b0-ccc9-4519-917e-325d72fab4ce")]
public interface IFolderView
{
[PreserveSig]
int GetCurrentViewMode(ref FOLDERVIEWMODE pViewMode);

[PreserveSig]
int SetCurrentViewMode(FOLDERVIEWMODE ViewMode);

[PreserveSig]
int GetFolder(ref Guid riid, out IPersistFolder2 ppv);

[PreserveSig]
int Item(int iItemIndex, out IntPtr ppidl);

[PreserveSig]
int ItemCount(uint uFlags, out int pcItems);

[PreserveSig]
int Items(uint uFlags, [In] ref Guid riid, out object ppv);

[PreserveSig]
int GetSelectionMarkedItem(out int piItem);

[PreserveSig]
int GetFocusedItem(out int piItem);

[PreserveSig]
int GetItemPosition(IntPtr pidl, out POINT ppt);

[PreserveSig]
int GetSpacing(ref POINT ppt);

[PreserveSig]
int GetDefaultSpacing(ref POINT ppt);

[PreserveSig]
int GetAutoArrange();

[PreserveSig]
int SelectItem(int iItem, int dwFlags);

[PreserveSig]
int SelectAndPositionItems(uint cidl, IntPtr apidl, IntPtr apt, int dwFlags);
}

//https://github.com/shellscape/Shellscape.Common/blob/aa5465929e842e4bcc88c29c1cc369122c307bc6/Microsoft/Windows%20API/Shell/Interop/ExplorerBrowser/ExplorerBrowserCOMInterfaces.cs
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("1af3a467-214f-4298-908e-06b03e0b39f9")]
public interface IFolderView2 : IFolderView
{
[PreserveSig]
void GetSortColumnCount(ref int pcColumns);
[PreserveSig]
void GetSortColumns(ref SORTCOLUMN rgSortColumns, int cColumns);
}

[StructLayout(LayoutKind.Sequential)]
public struct SORTCOLUMN
{
public PROPERTYKEY propkey;
public string direction;

public SORTCOLUMN(PROPERTYKEY propkey, string direction)
{
this.propkey = propkey;
this.direction = direction;
}
}

[StructLayout(LayoutKind.Sequential)]
public struct PROPERTYKEY
{
public Guid fmtid;
public string pid;

public PROPERTYKEY(Guid fmtid, string pid)
{
this.fmtid = fmtid;
this.pid = pid;
}
}

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]