public static IShellFolder GetIShellFolder(this ShellItem item) { var _pidl = item.PIDL; // Absolute PIDL IShellFolder desktop = DesktopFolder; IntPtr desktopPidl = IntPtr.Zero; Shell32.SHGetSpecialFolderLocation(IntPtr.Zero, CSIDL.CSIDL_DESKTOP, ref desktopPidl);; if (Shell32.ILIsEqual(_pidl, desktopPidl)) { return((IShellFolder)desktop); } else { IntPtr result; desktop.BindToObject(_pidl, IntPtr.Zero, ref Shell32.IID_IShellFolder, out result); var folder = (IShellFolder)Marshal.GetTypedObjectForIUnknown(result, typeof(IShellFolder)); return(folder); } }
IShellFolder GetIShellFolder() { IShellFolder desktop = null; Shell32.SHGetDesktopFolder(out desktop); IntPtr desktopPidl = IntPtr.Zero; Shell32.SHGetSpecialFolderLocation(IntPtr.Zero, CSIDL.CSIDL_DESKTOP, ref desktopPidl);; if (Shell32.ILIsEqual(_pidl, desktopPidl)) { return(desktop); } else { IntPtr result; desktop.BindToObject(_pidl, IntPtr.Zero, ref Shell32.IID_IShellFolder, out result); var folder = (IShellFolder)Marshal.GetTypedObjectForIUnknown(result, typeof(IShellFolder)); return(folder); } }
public override bool Equals(ResourceHandle other) { var handle = (ShellFileHandle)other; if (handle != null) { return(Shell32.ILIsEqual(pidl, handle.pidl)); } return(false); }
public static IShellFolder GetFolderImpl(this IntPtr pidl, ref PidlFolderData data, SBSP wFlags) { IShellFolder result = null; int hr = 0; IntPtr pidlTmp = IntPtr.Zero; var folderTmp = data.folderTmp; var currentAbsolutePidl = data.currentAbsolutePidl; var folderTmpPtr = data.folderTmpPtr; var currentFolder = data.currentFolder; IShellFolder desktopFolder = PidlFolderData.DesktopFolder; var desktopFolderPidl = PidlFolderData.DesktopFolderPidl; // Check to see if we have a desktop pidl, relative pidl or absolite pidl. if (Shell32.ILIsEqual(pidl, desktopFolderPidl)) { // The provided PIDL is the desktop folder. pidlTmp = Shell32.ILClone(desktopFolderPidl); folderTmp = desktopFolder; } else if ((wFlags & SBSP.SBSP_RELATIVE) != 0) { // SBSP_RELATIVE - pidl is relative from the current folder if ((hr = currentFolder.BindToObject(pidl, IntPtr.Zero, ref Shell32.IID_IShellFolder, out folderTmpPtr)) != WinError.S_OK) { return(result); // hr; } pidlTmp = Shell32.ILCombine(currentAbsolutePidl, pidl); folderTmp = (IShellFolder)Marshal.GetObjectForIUnknown(folderTmpPtr); } else { // SBSP_ABSOLUTE - pidl is an absolute pidl (relative from desktop) PidlClone pidlClone = PidlClone.Of(pidl); folderTmp = GetPidlCloneFolder(pidlClone); pidlTmp = pidlClone.Handle; } if (folderTmp == null) { Shell32.ILFree(pidlTmp); return(result); // WinError.E_FAIL; } result = folderTmp; return(result); }
public int Compare(IShellItem psi, SICHINT hint) { var other = (ShellItemImpl)psi; var myParent = GetParent(); var theirParent = other.GetParent(); if (Shell32.ILIsEqual(myParent.Pidl, theirParent.Pidl)) { return(myParent.GetIShellFolder().CompareIDs((SHCIDS)hint, Shell32.ILFindLastID(Pidl), Shell32.ILFindLastID(other.Pidl))); } return(1); }
public int Compare(IShellItem psi, SICHINT hint) { ShellItemImpl other = (ShellItemImpl)psi; ShellItemImpl myParent = GetParent(); ShellItemImpl theirParent = other.GetParent(); if (Shell32.ILIsEqual(myParent.m_Pidl, theirParent.m_Pidl)) { return(myParent.GetIShellFolder().CompareIDs((SHCIDS)hint, Shell32.ILFindLastID(m_Pidl), Shell32.ILFindLastID(other.m_Pidl))); } else { return(1); } }
private IShellFolder GetIShellFolder() { IShellFolder desktop = Shell32.SHGetDesktopFolder(); IntPtr desktopPidl; Shell32.SHGetSpecialFolderLocation(IntPtr.Zero, CSIDL.DESKTOP, out desktopPidl);; if (Shell32.ILIsEqual(Pidl, desktopPidl)) { return(desktop); } else { IntPtr result; desktop.BindToObject(Pidl, IntPtr.Zero, typeof(IShellFolder).GUID, out result); return((IShellFolder)Marshal.GetTypedObjectForIUnknown(result, typeof(IShellFolder))); } }
IShellFolder IFolder(IntPtr pidl, IShellFolder pShellFolderInterface, ref int result) { if (Shell32.ILIsEqual(pidl, Desktop.PIDL)) { result = WinError.S_OK; return((IShellFolder)Desktop.ShellFolderInterface); } IntPtr ppv = IntPtr.Zero; result = pShellFolderInterface.BindToObject(pidl, IntPtr.Zero, ref Shell32.IID_IShellFolder, out ppv); if (ppv == IntPtr.Zero) { // SBSP_ABSOLUTE - pidl is an absolute pidl (relative from desktop) var pidlTmp = Shell32.ILClone(pidl); IntPtr folderTmpPtr = IntPtr.Zero; IShellFolder desktopFolder = NativePidl.DesktopFolder; var hr = desktopFolder.BindToObject(pidlTmp, IntPtr.Zero, ref Shell32.IID_IShellFolder, out folderTmpPtr); if (hr != WinError.S_OK) { return(null); } var folderTmp = Marshal.GetObjectForIUnknown(folderTmpPtr) as IShellFolder; if (folderTmp == null) { Shell32.ILFree(pidlTmp); return(null);; // WinError.E_FAIL } return(folderTmp); } var shellFolderInterface = Marshal.GetObjectForIUnknown(ppv) as IShellFolder; return(shellFolderInterface); }
int IShellBrowser.BrowseObject(IntPtr pidl, SBSP wFlags) { if (this.InvokeRequired) { AutoResetEvent theEvent = new AutoResetEvent(false); int result = WinError.E_FAIL; this.Invoke((Action)(() => { result = ((IShellBrowser)this).BrowseObject(pidl, wFlags); theEvent.Set(); })); theEvent.WaitOne(); return(result); } int hr; IntPtr folderTmpPtr; IShellFolder folderTmp; IntPtr pidlTmp; // We'll need the shell folder GUID. var shellFolderGuid = typeof(IShellFolder).GUID; var shellViewGuid = typeof(IShellView).GUID; // Check to see if we have a desktop pidl, relative pidl or absolite pidl. if (Shell32.ILIsEqual(pidl, desktopFolderPidl)) { // The provided PIDL is the desktop folder. pidlTmp = Shell32.ILClone(desktopFolderPidl); folderTmp = desktopFolder; } else if ((wFlags & SBSP.SBSP_RELATIVE) != 0) { // SBSP_RELATIVE - pidl is relative from the current folder if ((hr = currentFolder.BindToObject(pidl, IntPtr.Zero, ref shellFolderGuid, out folderTmpPtr)) != WinError.S_OK) { return(hr); } pidlTmp = Shell32.ILCombine(currentAbsolutePidl, pidl); folderTmp = (IShellFolder)Marshal.GetObjectForIUnknown(folderTmpPtr); } else { // SBSP_ABSOLUTE - pidl is an absolute pidl (relative from desktop) pidlTmp = Shell32.ILClone(pidl); if ((hr = desktopFolder.BindToObject(pidlTmp, IntPtr.Zero, ref shellFolderGuid, out folderTmpPtr)) != WinError.S_OK) { return(hr); } folderTmp = (IShellFolder)Marshal.GetObjectForIUnknown(folderTmpPtr); } if (folderTmp == null) { Shell32.ILFree(pidlTmp); return(WinError.E_FAIL); } // Check that we have a new pidl if (Shell32.ILIsEqual(pidlTmp, currentAbsolutePidl)) { Shell32.ILFree(pidlTmp); return(WinError.S_OK); } currentFolder = folderTmp; FOLDERSETTINGS fs = new FOLDERSETTINGS(); IShellView lastIShellView = shellView; if (lastIShellView != null) { lastIShellView.GetCurrentInfo(ref fs); } // Copy the old folder settings else { fs = new FOLDERSETTINGS(); fs.fFlags = folderFlags; fs.ViewMode = folderViewMode; } // Create the IShellView IntPtr iShellViewPtr; hr = folderTmp.CreateViewObject(Handle, ref shellViewGuid, out iShellViewPtr); if (hr == WinError.S_OK) { shellView = (IShellView) Marshal.GetObjectForIUnknown(iShellViewPtr); hWndListView = IntPtr.Zero; RECT rc = new RECT(0, 0, ClientSize.Width, ClientSize.Height); int res; try { // Create the actual list view. res = shellView.CreateViewWindow(lastIShellView, ref fs, this, ref rc, ref hWndListView); } catch (COMException) { return(WinError.E_FAIL); } if (res < 0) { return(WinError.E_FAIL); } // Release the old IShellView if (lastIShellView != null) { lastIShellView.GetCurrentInfo(ref fs); lastIShellView.UIActivate(SVUIA_STATUS.SVUIA_DEACTIVATE); lastIShellView.DestroyViewWindow(); } // Set focus to the IShellView shellView.UIActivate(SVUIA_STATUS.SVUIA_ACTIVATE_FOCUS); currentAbsolutePidl = pidlTmp; } return(WinError.S_OK); }
public static int BrowseObject(this ShellDebuggerModel model, IntPtr pidl, SBSP wFlags) { int hr; IntPtr folderTmpPtr; IShellFolder folderTmp = null; IntPtr pidlTmp; // We'll need the shell folder GUID. var shellFolderGuid = typeof(IShellFolder).GUID; var desktopFolder = model.DesktopFolder; var currentFolder = model.currentFolder; var currentAbsolutePidl = model.currentAbsolutePidl; // Check to see if we have a desktop pidl, relative pidl or absolite pidl. if (Shell32.ILIsEqual(pidl, model.DesktopFolderPidl)) { // The provided PIDL is the desktop folder. pidlTmp = Shell32.ILClone(model.DesktopFolderPidl); folderTmp = model.DesktopFolder; } else if ((wFlags & SBSP.SBSP_RELATIVE) != 0) { // SBSP_RELATIVE - pidl is relative from the current folder if ((hr = currentFolder.BindToObject(pidl, IntPtr.Zero, shellFolderGuid, out folderTmpPtr)) != WinError.S_OK) { return(WinError.E_FAIL); } pidlTmp = Shell32.ILCombine(currentAbsolutePidl, pidl); folderTmp = (IShellFolder)Marshal.GetObjectForIUnknown(folderTmpPtr); } else { // SBSP_ABSOLUTE - pidl is an absolute pidl (relative from desktop) pidlTmp = Shell32.ILClone(pidl); if ((hr = desktopFolder.BindToObject(pidlTmp, IntPtr.Zero, shellFolderGuid, out folderTmpPtr)) != WinError.S_OK) { return(WinError.E_FAIL); } folderTmp = (IShellFolder)Marshal.GetObjectForIUnknown(folderTmpPtr); } if (folderTmp == null) { Shell32.ILFree(pidlTmp); return(WinError.E_FAIL); } // Check that we have a new pidl if (Shell32.ILIsEqual(pidlTmp, currentAbsolutePidl)) { Shell32.ILFree(pidlTmp); return(WinError.S_OK); } model.hWndListView = IntPtr.Zero; model.lastViewPidl = IntPtr.Zero; var ret = ChangeFolder(model, pidl, wFlags, folderTmp, pidlTmp); //var path = PidlManager.GetPidlDisplayName(pidlTmp); //if (path == "Control Panel" || model.lastViewPidl == IntPtr.Zero) //{ // IEnumIDList ppenumIDList = null; // var hr3 = folderTmp.EnumObjects(model.Form.Handle, // SHCONTF.SHCONTF_INCLUDEHIDDEN | SHCONTF.SHCONTF_INCLUDESUPERHIDDEN | SHCONTF.SHCONTF_NONFOLDERS, // | SHCONTF.SHCONTF_FOLDERS , // out ppenumIDList); // if (ppenumIDList == null) // if empty list // { // IntPtr iShellFolderPtr = IntPtr.Zero; // var guidFolder2 = typeof(IShellFolder2).GUID; // folderTmpPtr = IntPtr.Zero; // if ((hr = desktopFolder.BindToObject(pidlTmp, IntPtr.Zero, // ref guidFolder2, // shellFolderGuid, // out folderTmpPtr)) == WinError.S_OK) // { // folderTmp = (IShellFolder2)Marshal.GetObjectForIUnknown(folderTmpPtr); // var hr2 = ShellObject.CreateViewObject(folderTmp, model.Form.Handle, ref guidFolder2, out iShellFolderPtr); // } // if (iShellFolderPtr != IntPtr.Zero) // { // var ShellFolder = (IShellFolder2) // Marshal.GetObjectForIUnknown(iShellFolderPtr); // } // } //} return(ret == WinError.S_OK ? WinError.S_OK : WinError.E_FAIL); }