Получить выбранные элементы папки с WinAPI

Эй, ребята, я пытаюсь получить выбранные файлы из папки, которую использует пользователь. У меня есть следующий код, который уже запущен, но только для настольных файлов:

private string selectedFiles()
{
    // get the handle of the desktop listview
    IntPtr vHandle = WinApiWrapper.FindWindow("Progman", "Program Manager");
    vHandle = WinApiWrapper.FindWindowEx(vHandle, IntPtr.Zero, "SHELLDLL_DefView", null);
    vHandle = WinApiWrapper.FindWindowEx(vHandle, IntPtr.Zero, "SysListView32", "FolderView");

    //IntPtr vHandle = WinApiWrapper.GetForegroundWindow();

    //Get total count of the icons on the desktop
    int vItemCount = WinApiWrapper.SendMessage(vHandle, WinApiWrapper.LVM_GETITEMCOUNT, 0, 0);
    //MessageBox.Show(vItemCount.ToString());
    uint vProcessId;
    WinApiWrapper.GetWindowThreadProcessId(vHandle, out vProcessId);
    IntPtr vProcess = WinApiWrapper.OpenProcess(WinApiWrapper.PROCESS_VM_OPERATION | WinApiWrapper.PROCESS_VM_READ |
    WinApiWrapper.PROCESS_VM_WRITE, false, vProcessId);
    IntPtr vPointer = WinApiWrapper.VirtualAllocEx(vProcess, IntPtr.Zero, 4096,
    WinApiWrapper.MEM_RESERVE | WinApiWrapper.MEM_COMMIT, WinApiWrapper.PAGE_READWRITE);
    try
    {
        for (int j = 0; j < vItemCount; j++)
        {
            byte[] vBuffer = new byte[256];
            WinApiWrapper.LVITEM[] vItem = new WinApiWrapper.LVITEM[1];
            vItem[0].mask = WinApiWrapper.LVIF_TEXT;
            vItem[0].iItem = j;
            vItem[0].iSubItem = 0;
            vItem[0].cchTextMax = vBuffer.Length;
            vItem[0].pszText = (IntPtr)((int)vPointer + Marshal.SizeOf(typeof(WinApiWrapper.LVITEM)));
            uint vNumberOfBytesRead = 0;
            WinApiWrapper.WriteProcessMemory(vProcess, vPointer,
            Marshal.UnsafeAddrOfPinnedArrayElement(vItem, 0),
            Marshal.SizeOf(typeof(WinApiWrapper.LVITEM)), ref vNumberOfBytesRead);
            WinApiWrapper.SendMessage(vHandle, WinApiWrapper.LVM_GETITEMW, j, vPointer.ToInt32());
            WinApiWrapper.ReadProcessMemory(vProcess,
            (IntPtr)((int)vPointer + Marshal.SizeOf(typeof(WinApiWrapper.LVITEM))),
            Marshal.UnsafeAddrOfPinnedArrayElement(vBuffer, 0),
            vBuffer.Length, ref vNumberOfBytesRead);
            string vText = Encoding.Unicode.GetString(vBuffer, 0,
            (int)vNumberOfBytesRead);
            string IconName = vText;

            //Check if item is selected
            var result = WinApiWrapper.SendMessage(vHandle, WinApiWrapper.LVM_GETITEMSTATE, j, (int)WinApiWrapper.LVIS_SELECTED);
            if (result == WinApiWrapper.LVIS_SELECTED)
            {
                return vText;
            }
        }
    }
    finally
    {
        WinApiWrapper.VirtualFreeEx(vProcess, vPointer, 0, WinApiWrapper.MEM_RELEASE);
        WinApiWrapper.CloseHandle(vProcess);
  ,  }
    return String.Empty;
}

Я попытался получить дескриптор окна с помощью GetForegroundWindow (), а затем безуспешно вызвать SHELLDLL_DefView.

Итак, как я могу изменить первые 3 строки, чтобы получить указатель текущей используемой папки?

Ответы на вопрос(2)

Ваш ответ на вопрос