Example #1
0
 /// <summary>
 /// Creates a unicode <see cref="STRRET"/> from a string.
 /// </summary>
 /// <param name="str">The string.</param>
 /// <returns>A unicode <see cref="STRRET"/> allocated on the shell allocator.</returns>
 public static STRRET CreateUnicode(string str)
 {
     //  Create a unicode string by using the SHStrDup shell function to make
     //  a copy of the source string.
     var strret = new STRRET { uType = STRRETTYPE.STRRET_WSTR };
     Shell32.SHStrDup(str, out strret.data);
     return strret;
 }
Example #2
0
        /// <summary>
        /// Creates a unicode <see cref="STRRET"/> from a string.
        /// </summary>
        /// <param name="str">The string.</param>
        /// <returns>A unicode <see cref="STRRET"/> allocated on the shell allocator.</returns>
        public static STRRET CreateUnicode(string str)
        {
            //  Create a unicode string by using the SHStrDup shell function to make
            //  a copy of the source string.
            var strret = new STRRET {
                uType = STRRETTYPE.STRRET_WSTR
            };

            Shell32.SHStrDup(str, out strret.data);
            return(strret);
        }
 int IShellFolder2.GetDisplayNameOf(IntPtr pidl, SHGDNF uFlags, out STRRET pName)
 {
     return ((IShellFolder2)shellFolderImpl).GetDisplayNameOf(pidl, uFlags, out pName);
 }
 /// <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);
 }
Example #5
0
        /// <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;
        }