/// <summary> /// Gets parse and display name items for a ShellFolder2 object. /// /// Tpically using either values for /// <see cref="SHGDNF.SHGDN_FORPARSING"/> /// <see cref="SHGDNF.SHGDN_NORMAL"/> <paramref name="uFlags"/> /// </summary> /// <param name="ptr"></param> /// <param name="uFlags"></param> /// <returns></returns> public string GetShellFolderName(IntPtr ptr, SHGDNF uFlags) { if (Obj == null) { return(null); } IntPtr ptrStr = Marshal.AllocCoTaskMem(NativeMethods.MAX_PATH * 2 + 4); Marshal.WriteInt32(ptrStr, 0, 0); StringBuilder buf = new StringBuilder(NativeMethods.MAX_PATH); try { if (Obj.GetDisplayNameOf(ptr, uFlags, ptrStr) == HRESULT.S_OK) { NativeMethods.StrRetToBuf(ptrStr, ptr, buf, NativeMethods.MAX_PATH); } } finally { if (ptrStr != IntPtr.Zero) { Marshal.FreeCoTaskMem(ptrStr); } ptrStr = IntPtr.Zero; } return(buf.ToString()); }
public static string GetDisplayNameOf(this IShellFolder folder, IdList pidl, SHGDNF uFlags) { //StrRet value; StrRetNative value; int hr = folder._GetDisplayNameOf(pidl, uFlags, out value); if (hr != ShellConsts.S_OK) { Marshal.ThrowExceptionForHR(hr); } return(new StrRet(value).GetValue(pidl)); }
/// <summary> /// Retrieves the display name for the specified file object or subfolder. /// Return value: error code, if any /// </summary> /// <param name="pidl">Address of an ITEMIDLIST structure (PIDL) that uniquely identifies the file object or subfolder relative to the parent folder.</param> /// <param name="uFlags">Flags used to request the type of display name to return. For a list of possible values.</param> /// <param name="pName">Address of a STRRET structure in which to return the display name.</param> /// <returns> /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// </returns> int IShellFolder.GetDisplayNameOf(IntPtr pidl, SHGDNF uFlags, out STRRET pName) { // If we have an invalid PIDL, we must fail. if (pidl == IntPtr.Zero) { pName = new STRRET(); return(WinError.E_INVALIDARG); } // Create an idlist from the pidl. var idlist = PidlManager.PidlToIdlist(pidl); // Get the shell item. // TODO; handle errors var shellItem = GetChildItem(idlist); // If the flags are normal only, we're asking for the display name only. if (uFlags == SHGDNF.SHGDN_NORMAL) { // We only need the display name. pName = STRRET.CreateUnicode(shellItem.GetDisplayName(DisplayNameContext.OutOfFolder)); return(WinError.S_OK); } // If the flags are in folder, we're asking for the standard display name. if (uFlags == SHGDNF.SHGDN_INFOLDER || uFlags == SHGDNF.SHGDN_FORADDRESSBAR) { pName = STRRET.CreateUnicode(shellItem.GetDisplayName(DisplayNameContext.Normal)); return(WinError.S_OK); } // If the flags indicate parsing mode, we need to construct a name // that'll let us bounce from PIDL <-> name. We do this, rather than // the implementor. if (uFlags.HasFlag(SHGDNF.SHGDN_FORPARSING)) { // It's either relative (INFOLDER) or fully qualified. var str = uFlags.HasFlag(SHGDNF.SHGDN_INFOLDER) ? idlist.ToParsingString() : /* TODO start with my id list */ idlist.ToParsingString(); pName = STRRET.CreateUnicode(str); return(WinError.S_OK); } pName = STRRET.CreateUnicode(string.Empty); return(WinError.S_OK); }
/// <summary> /// Converts a given FULL <see cref="IdList"/> based PIDL into a name /// (display name or parse name etc). /// /// A Pidl is considered FULL if it can be resolved /// underneath the desktop root item. That is, a relativeChild PIDL /// from another parent (eg.: C: drive) cannot be resolved here and /// results in null being returned. /// </summary> /// <param name="idListPidl"></param> /// <param name="parseOption"></param> /// <returns>Returns the requested string or null if <paramref name="idListPidl"/> /// cannot be resolved underneath the Desktop root item.</returns> public static string IdListFullToName(IdList idListPidl, SHGDNF parseOption) { using (var desktopShellFolder = new ShellFolderDesktop()) { IntPtr pidl = default(IntPtr); try { pidl = PidlManager.IdListToPidl(idListPidl); if (pidl != default(IntPtr)) { string parseName = desktopShellFolder.GetShellFolderName(pidl, parseOption); return(parseName); } } finally { Marshal.FreeCoTaskMem(pidl); } } return(null); }
int IShellFolder2.SetNameOf(IntPtr hwnd, IntPtr pidl, string pszName, SHGDNF uFlags, out IntPtr ppidlOut) { return(((IShellFolder)this).SetNameOf(hwnd, pidl, pszName, uFlags, out ppidlOut)); }
int IShellFolder2.GetDisplayNameOf(IntPtr pidl, SHGDNF uFlags, out STRRET pName) { return(((IShellFolder)this).GetDisplayNameOf(pidl, uFlags, out pName)); }
/// <summary> /// Sets the display name of a file object or subchanging the item /// identifier in the process. /// Return value: error code, if any /// </summary> /// <param name="hwnd">Handle to the owner window of any dialog or message boxes that the client displays.</param> /// <param name="pidl">Pointer to an ITEMIDLIST structure that uniquely identifies the file object or subfolder relative to the parent folder.</param> /// <param name="pszName">Pointer to a null-terminated string that specifies the new display name.</param> /// <param name="uFlags">Flags indicating the type of name specified by the lpszName parameter. For a list of possible values, see the description of the SHGNO enum.</param> /// <param name="ppidlOut"></param> /// <returns> /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// </returns> /// <exception cref="System.NotImplementedException"></exception> int IShellFolder.SetNameOf(IntPtr hwnd, IntPtr pidl, string pszName, SHGDNF uFlags, out IntPtr ppidlOut) { // TODO this needs to be implemented. ppidlOut = IntPtr.Zero; return(WinError.E_NOTIMPL); }
int IShellFolder2.SetNameOf(IntPtr hwnd, IntPtr pidl, string pszName, SHGDNF uFlags, out IntPtr ppidlOut) { return ((IShellFolder2)shellFolderImpl).SetNameOf(hwnd, pidl, pszName, uFlags, out ppidlOut); }
int IShellFolder2.GetDisplayNameOf(IntPtr pidl, SHGDNF uFlags, out STRRET pName) { return ((IShellFolder2)shellFolderImpl).GetDisplayNameOf(pidl, uFlags, out pName); }
/// <summary> /// Sets the display name of a file object or subfolder, changing the item /// identifier in the process. /// Return value: error code, if any /// </summary> /// <param name="hwnd">Handle to the owner window of any dialog or message boxes that the client displays.</param> /// <param name="pidl">Pointer to an ITEMIDLIST structure that uniquely identifies the file object or subfolder relative to the parent folder.</param> /// <param name="pszName">Pointer to a null-terminated string that specifies the new display name.</param> /// <param name="uFlags">Flags indicating the type of name specified by the lpszName parameter. For a list of possible values, see the description of the SHGNO enum.</param> /// <param name="ppidlOut"></param> /// <returns> /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// </returns> /// <exception cref="System.NotImplementedException"></exception> int IShellFolder.SetNameOf(IntPtr hwnd, IntPtr pidl, string pszName, SHGDNF uFlags, out IntPtr ppidlOut) { // Use the ShellFolderImpl to handle the details. return(((IShellFolder)shellFolderImpl).SetNameOf(hwnd, pidl, pszName, uFlags, out ppidlOut)); }
/// <summary> /// Retrieves the display name for the specified file object or subfolder. /// Return value: error code, if any /// </summary> /// <param name="pidl">Address of an ITEMIDLIST structure (PIDL) that uniquely identifies the file object or subfolder relative to the parent folder.</param> /// <param name="uFlags">Flags used to request the type of display name to return. For a list of possible values.</param> /// <param name="pName">Address of a STRRET structure in which to return the display name.</param> /// <returns> /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// </returns> int IShellFolder.GetDisplayNameOf(IntPtr pidl, SHGDNF uFlags, out STRRET pName) { // Use the ShellFolderImpl to handle the details. return ((IShellFolder)shellFolderImpl).GetDisplayNameOf(pidl, uFlags, out pName); }
public static string GetDisplayNameOf(this IShellFolder folder, IdList pidl, SHGDNF uFlags) { //StrRet value; StrRetNative value; int hr = folder._GetDisplayNameOf(pidl, uFlags, out value); if (hr != ShellConsts.S_OK) Marshal.ThrowExceptionForHR(hr); return new StrRet(value).GetValue(pidl); }
public static string GetDisplayNameOf(this IShellFolder shellFolder, IntPtr pidl, SHGDNF uFlags) { shellFolder.GetDisplayNameOf(pidl, SHGDNF.FORPARSING, out var str); NativeMethods.StrRetToBSTR(ref str, pidl, out var buffer); return(buffer); }
/// <summary> /// Sets the display name of a file object or subchanging the item /// identifier in the process. /// Return value: error code, if any /// </summary> /// <param name="hwnd">Handle to the owner window of any dialog or message boxes that the client displays.</param> /// <param name="pidl">Pointer to an ITEMIDLIST structure that uniquely identifies the file object or subfolder relative to the parent folder.</param> /// <param name="pszName">Pointer to a null-terminated string that specifies the new display name.</param> /// <param name="uFlags">Flags indicating the type of name specified by the lpszName parameter. For a list of possible values, see the description of the SHGNO enum.</param> /// <param name="ppidlOut"></param> /// <returns> /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// </returns> /// <exception cref="System.NotImplementedException"></exception> int IShellFolder.SetNameOf(IntPtr hwnd, IntPtr pidl, string pszName, SHGDNF uFlags, out IntPtr ppidlOut) { // TODO this needs to be implemented. ppidlOut = IntPtr.Zero; return WinError.E_NOTIMPL; }
/// <summary> /// Retrieves the display name for the specified file object or subfolder. /// Return value: error code, if any /// </summary> /// <param name="pidl">Address of an ITEMIDLIST structure (PIDL) that uniquely identifies the file object or subfolder relative to the parent folder.</param> /// <param name="uFlags">Flags used to request the type of display name to return. For a list of possible values.</param> /// <param name="pName">Address of a STRRET structure in which to return the display name.</param> /// <returns> /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// </returns> int IShellFolder.GetDisplayNameOf(IntPtr pidl, SHGDNF uFlags, out STRRET pName) { // If we have an invalid PIDL, we must fail. if (pidl == IntPtr.Zero) { pName = new STRRET(); return WinError.E_INVALIDARG; } // Create an idlist from the pidl. var idlist = PidlManager.PidlToIdlist(pidl); // Get the shell item. // TODO; handle errors var shellItem = GetChildItem(idlist); // If the flags are normal only, we're asking for the display name only. if (uFlags == SHGDNF.SHGDN_NORMAL) { // We only need the display name. pName = STRRET.CreateUnicode(shellItem.GetDisplayName(DisplayNameContext.OutOfFolder)); return WinError.S_OK; } // If the flags are in folder, we're asking for the standard display name. if (uFlags == SHGDNF.SHGDN_INFOLDER || uFlags == SHGDNF.SHGDN_FORADDRESSBAR) { pName = STRRET.CreateUnicode(shellItem.GetDisplayName(DisplayNameContext.Normal)); return WinError.S_OK; } // If the flags indicate parsing mode, we need to construct a name // that'll let us bounce from PIDL <-> name. We do this, rather than // the implementor. if (uFlags.HasFlag(SHGDNF.SHGDN_FORPARSING)) { // It's either relative (INFOLDER) or fully qualified. var str = uFlags.HasFlag(SHGDNF.SHGDN_INFOLDER) ? idlist.ToParsingString() : /* TODO start with my id list */ idlist.ToParsingString(); pName = STRRET.CreateUnicode(str); return WinError.S_OK; } pName = STRRET.CreateUnicode(string.Empty); return WinError.S_OK; }
/// <summary> /// Sets the display name of a file object or subfolder, changing the item /// identifier in the process. /// Return value: error code, if any /// </summary> /// <param name="hwnd">Handle to the owner window of any dialog or message boxes that the client displays.</param> /// <param name="pidl">Pointer to an ITEMIDLIST structure that uniquely identifies the file object or subfolder relative to the parent folder.</param> /// <param name="pszName">Pointer to a null-terminated string that specifies the new display name.</param> /// <param name="uFlags">Flags indicating the type of name specified by the lpszName parameter. For a list of possible values, see the description of the SHGNO enum.</param> /// <param name="ppidlOut"></param> /// <returns> /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// </returns> /// <exception cref="System.NotImplementedException"></exception> int IShellFolder.SetNameOf(IntPtr hwnd, IntPtr pidl, string pszName, SHGDNF uFlags, out IntPtr ppidlOut) { // Use the ShellFolderImpl to handle the details. return ((IShellFolder)shellFolderImpl).SetNameOf(hwnd, pidl, pszName, uFlags, out ppidlOut); }
/// <summary> /// Retrieves the display name for the specified file object or subfolder. /// Return value: error code, if any /// </summary> /// <param name="pidl">Address of an ITEMIDLIST structure (PIDL) that uniquely identifies the file object or subfolder relative to the parent folder.</param> /// <param name="uFlags">Flags used to request the type of display name to return. For a list of possible values.</param> /// <param name="pName">Address of a STRRET structure in which to return the display name.</param> /// <returns> /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// </returns> int IShellFolder.GetDisplayNameOf(IntPtr pidl, SHGDNF uFlags, out STRRET pName) { // Use the ShellFolderImpl to handle the details. return(((IShellFolder)shellFolderImpl).GetDisplayNameOf(pidl, uFlags, out pName)); }