public static COMInterfaces.IShellFolder GetShellFolder(IntPtr handle, string path, out IntPtr FolderID) { string tempPath = path; // Get the desktop folder COMInterfaces.IShellFolder returnedShellFolder = null; APIsShell.SHGetDesktopFolder(out returnedShellFolder); System.Guid IID_IShellFolder = new System.Guid("000214E6-0000-0000-C000-000000000046"); IntPtr Pidl = IntPtr.Zero; uint i, j = 0; // Connect to "My Computer" APIsShell.SHGetSpecialFolderLocation(handle, APIsEnums.ShellSpecialFolders.DRIVES, out Pidl); COMInterfaces.IShellFolder tempfolder; returnedShellFolder.BindToObject(Pidl, IntPtr.Zero, ref IID_IShellFolder, out tempfolder); Marshal.ReleaseComObject(returnedShellFolder); returnedShellFolder = tempfolder; int lastindexposition = 0; while (lastindexposition != -1) { lastindexposition = tempPath.IndexOf('\\'); if (lastindexposition == -1) { break; } string foldername = tempPath.Remove(lastindexposition, tempPath.Length - lastindexposition) + @"\"; returnedShellFolder.ParseDisplayName(handle, IntPtr.Zero, foldername, out i, out Pidl, ref j); returnedShellFolder.BindToObject(Pidl, IntPtr.Zero, ref IID_IShellFolder, out tempfolder); Marshal.ReleaseComObject(returnedShellFolder); returnedShellFolder = tempfolder; tempPath = tempPath.Substring(++lastindexposition); } FolderID = Pidl; return(returnedShellFolder); }
public static extern int SHGetDesktopFolder(out COMInterfaces.IShellFolder folder);
public static extern int SHBindToParent( IntPtr pidl, Guid iid, out COMInterfaces.IShellFolder folder, out IntPtr pidlRelative);
public static extern uint SHGetDataFromIDList( COMInterfaces.IShellFolder psf, IntPtr pidl, APIsEnums.ShellFolderGetaFromIDList nFormat, out APIsStructs.WIN32_FIND_DATA pv, int cb);