Beispiel #1
0
        public IntPtr GetDisplayName(SIGDN sigdnName)
        {
            if (sigdnName == SIGDN.FILESYSPATH)
            {
                StringBuilder result = new StringBuilder(FileSystem.MAX_PATH);
                if (!ILShell32.SHGetPathFromIDList(_pidl, result))
                {
                    throw new ArgumentException();
                }
                return(Marshal.StringToHGlobalUni(result.ToString()));
            }
            else
            {
                //IShellFolder parentFolder = GetParent().GetIShellFolder();
                IntPtr        childPidl = ILShell32.ILFindLastID(_pidl);
                StringBuilder builder   = new StringBuilder(FileSystem.MAX_PATH);
                builder.Length = 0; // TODO
                //STRRET strret = new STRRET();

                //TODO
                //parentFolder.GetDisplayNameOf(childPidl,
                //    (SHGNO)((int)sigdnName & 0xffff), out strret);
                //ShlWapi.StrRetToBuf(ref strret, childPidl, builder,
                //    (uint)builder.Capacity);
                return(Marshal.StringToHGlobalUni(builder.ToString()));
            }
        }
Beispiel #2
0
        private string GetDisplayName(SIGDN purpose)
        {
            IntPtr hString = IntPtr.Zero;
            string name    = string.Empty;

            try
            {
                if (_shellItem?.GetDisplayName(purpose, out hString) == NativeMethods.S_OK)
                {
                    if (hString != IntPtr.Zero)
                    {
                        name = Marshal.PtrToStringAuto(hString);
                    }
                }
            }
            catch (Exception e)
            {
                ShellLogger.Error($"ShellItem: Unable to get {purpose} display name: {e.Message}");
            }
            finally
            {
                Marshal.FreeCoTaskMem(hString);
            }

            return(name);
        }
Beispiel #3
0
        public IntPtr GetDisplayName(SIGDN sigdnName)
        {
            if (sigdnName == SIGDN.FILESYSPATH)
            {
                StringBuilder result = new StringBuilder(512);
                if (!Shell32.SHGetPathFromIDList(m_Pidl, result))
                {
                    throw new ArgumentException();
                }
                return(Marshal.StringToHGlobalUni(result.ToString()));
            }
            else
            {
                IShellFolder  parentFolder = GetParent().GetIShellFolder();
                IntPtr        childPidl    = Shell32.ILFindLastID(m_Pidl);
                StringBuilder builder      = new StringBuilder(512);
                STRRET        strret       = new STRRET();

                parentFolder.GetDisplayNameOf(childPidl,
                                              (SHGNO)((int)sigdnName & 0xffff), out strret);
                ShlWapi.StrRetToBuf(ref strret, childPidl, builder,
                                    (uint)builder.Capacity);
                return(Marshal.StringToHGlobalUni(builder.ToString()));
            }
        }
Beispiel #4
0
    private static string GetDisplayName(IShellItem item, SIGDN sigdnName)
    {
        item.GetDisplayName(sigdnName, out var ptr);
        var name = Marshal.PtrToStringUni(ptr);

        Marshal.FreeCoTaskMem(ptr);
        return(name);
    }
Beispiel #5
0
        /// <summary>
        /// Returns the name of the item in the specified style.
        /// </summary>
        ///
        /// <param name="sigdn">
        /// The style of display name to return.
        /// </param>
        ///
        /// <returns>
        /// A string containing the display name of the item.
        /// </returns>
        public string GetDisplayName(SIGDN sigdn)
        {
            IntPtr resultPtr = m_ComInterface.GetDisplayName(sigdn);
            string result    = Marshal.PtrToStringUni(resultPtr);

            Marshal.FreeCoTaskMem(resultPtr);
            return(result);
        }
Beispiel #6
0
 /// <summary>
 /// Returns a <see cref="string"/> that represents this instance base according to the format provided by <paramref name="displayNameFormat"/>.
 /// </summary>
 /// <param name="displayNameFormat">The desired display name format.</param>
 /// <returns>A <see cref="string"/> that represents this instance.</returns>
 public string ToString(SIGDN displayNameFormat)
 {
     try
     {
         SHGetNameFromIDList(this, displayNameFormat, out var name).ThrowIfFailed();
         return(name);
     }
     catch (Exception ex) { Debug.WriteLine($"Error: PIDL:ToString = {ex}"); }
     return(null);
 }
Beispiel #7
0
 /// <summary>Returns a <see cref="System.String"/> that represents this instance base according to the format provided by <paramref name="displayNameFormat"/>.</summary>
 /// <param name="displayNameFormat">The desired display name format.</param>
 /// <returns>A <see cref="System.String"/> that represents this instance.</returns>
 public string ToString(SIGDN displayNameFormat)
 {
     try
     {
         SHGetNameFromIDList(this, displayNameFormat, out SafeCoTaskMemHandle name);
         return(name.ToString(-1));
     }
     catch (Exception ex) { Debug.WriteLine($"Error: PIDL:ToString = {ex}"); }
     return(null);
 }
Beispiel #8
0
        /// <summary>
        /// Get the name for a given Shell item ID.
        /// </summary>
        public static string GetNameFromId(ItemIdList id, SIGDN form = SIGDN.NORMALDISPLAY)
        {
            HRESULT hr = Imports.SHGetNameFromIDList(id, form, out string name);

            if (hr != HRESULT.S_OK)
            {
                throw Errors.GetIoExceptionForHResult(hr);
            }

            return(name);
        }
Beispiel #9
0
        public static string SHGetNameFromIDList(IdList pidl, SIGDN sigdnName)
        {
            string ret;
            int    hr = _SHGetNameFromIDList(pidl, sigdnName, out ret);

            if (hr != ShellConsts.S_OK)
            {
                Marshal.ThrowExceptionForHR(hr);
            }
            return(ret);
        }
Beispiel #10
0
 public string GetDisplayName(SIGDN type)
 {
     try {
         var comInterface = this.ComInterface;
         var resultPtr    = comInterface.GetDisplayName(type);
         var result       = Marshal.PtrToStringUni(resultPtr);
         Marshal.FreeCoTaskMem(resultPtr);
         Marshal.FinalReleaseComObject(comInterface);
         return(result);
     } catch {
         return("Search.search-ms");
     }
 }
 /// <summary>
 /// Returns the name of the item in the specified style.
 /// </summary>
 ///
 /// <param name="sigdn">
 /// The style of display name to return.
 /// </param>
 ///
 /// <returns>
 /// A string containing the display name of the item.
 /// </returns>
 public string GetDisplayName(SIGDN sigdn)
 {
     try
     {
         IntPtr resultPtr = m_ComInterface.GetDisplayName(sigdn);
         string result    = Marshal.PtrToStringUni(resultPtr);
         Marshal.FreeCoTaskMem(resultPtr);
         return(result);
     }
     catch (Exception)
     {
         return(String.Empty);
     }
 }
Beispiel #12
0
        /// <summary>
        /// Returns the name of the item in the specified style.
        /// </summary>
        ///
        /// <param name="sigdn">
        /// The style of display name to return.
        /// </param>
        ///
        /// <returns>
        /// A string containing the display name of the item.
        /// </returns>
        public string GetDisplayName(SIGDN sigdn)
        {
            try
            {
                IntPtr resultPtr = m_ComInterface.GetDisplayName(sigdn);
                string result    = Marshal.PtrToStringUni(resultPtr);
                Marshal.FreeCoTaskMem(resultPtr);
                return(result);
            }
            catch (Exception ex)
            {
                Console.Write("\nError ShellItem.cs\n" + ex.Message);

                return(string.Empty);
            }
        }
		public IntPtr GetDisplayName(SIGDN sigdnName) {
			if (sigdnName == SIGDN.FILESYSPATH) {
				var result = new StringBuilder(512);
				if (!Shell32.SHGetPathFromIDList(Pidl, result)) throw new ArgumentException();
				return Marshal.StringToHGlobalUni(result.ToString());
			}
			else {
				IShellFolder parentFolder = GetParent().GetIShellFolder();
				IntPtr childPidl = Shell32.ILFindLastID(Pidl);
				var builder = new StringBuilder(512);
				var strret = new STRRET();

				parentFolder.GetDisplayNameOf(childPidl, (SHGNO)((int)sigdnName & 0xffff), out strret);
				ShlWapi.StrRetToBuf(ref strret, childPidl, builder, (uint)builder.Capacity);
				return Marshal.StringToHGlobalUni(builder.ToString());
			}
		}
Beispiel #14
0
 /// <summary>
 /// Returns the name of the item in the specified style.
 /// </summary>
 ///
 /// <param name="sigdn">
 /// The style of display name to return.
 /// </param>
 ///
 /// <returns>
 /// A string containing the display name of the item.
 /// </returns>
 public string GetDisplayName(SIGDN sigdn)
 {
     try {
         IntPtr resultPtr = ComInterface.GetDisplayName(sigdn);
         string result    = Marshal.PtrToStringUni(resultPtr);
         Marshal.FreeCoTaskMem(resultPtr);
         return(result);
     } catch {
         try {
             var    shellobj  = new ShellItem(this.CachedParsingName.ToShellParsingName());
             IntPtr resultPtr = shellobj.ComInterface.GetDisplayName(sigdn);
             string result    = Marshal.PtrToStringUni(resultPtr);
             Marshal.FreeCoTaskMem(resultPtr);
             return(result);
         } catch {
             return("Search.search-ms");
         }
     }
 }
Beispiel #15
0
            public string GetDisplayName(SIGDN sigdnName)
            {
                if (sigdnName == SIGDN.SIGDN_FILESYSPATH)
                {
                    var result = new StringBuilder(512);
                    if (!SHGetPathFromIDList(PIDL, result))
                    {
                        throw new ArgumentException();
                    }
                    return(result.ToString());
                }

                var    parentFolder = InternalGetParent().GetIShellFolder();
                var    child        = PIDL.LastId;
                STRRET strret;

                parentFolder.GetDisplayNameOf(child, (SHGDN)((int)sigdnName & 0xffff), out strret);
                return(strret.ToString());
            }
Beispiel #16
0
        /// <summary>
        /// Gets the display name of the shell item or null if name is not available.
        /// </summary>
        /// <param name="flags"></param>
        /// <returns></returns>
        public string GetDisplayName(SIGDN flags)
        {
            IntPtr ppszName = default(IntPtr);
            string result   = null;

            try
            {
                if (this.Obj.GetDisplayName(flags, out ppszName) == HRESULT.S_OK)
                {
                    result = Marshal.PtrToStringUni(ppszName);
                }
            }
            finally
            {
                if (ppszName != default(IntPtr))
                {
                    Marshal.FreeCoTaskMem(ppszName);
                }
            }

            return(result);
        }
Beispiel #17
0
 public static extern uint SHGetNameFromIDList(IntPtr pidl, SIGDN sigdnName, out String ppszName);
Beispiel #18
0
 public static extern UInt32 SHGetNameFromIDList(IntPtr pidl, SIGDN sigdnName, out IntPtr ppszName);
Beispiel #19
0
 public static extern uint SHGetNameFromIDList(IntPtr pidl, SIGDN sigdnName, [Out] out String ppszName);
Beispiel #20
0
 public static extern string SHGetNameFromIDList(IntPtr pidl, SIGDN sigdnName);
Beispiel #21
0
 string GetDisplayName(SIGDN sigdnName);
Beispiel #22
0
 public static extern IntPtr SHGetNameFromIDList(IntPtr pidl, SIGDN sigdnName, [MarshalAs(UnmanagedType.LPWStr)] out string ppszName);
Beispiel #23
0
 public static extern HRESULT SHGetNameFromIDList(
     ItemIdList pidl,
     SIGDN sigdnName,
     out string ppszName);
 public string GetDisplayName(SIGDN type) => this._Item.GetDisplayName(type);
Beispiel #25
0
 private static extern int _SHGetNameFromIDList(
     [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(IdListMarshaler))]
     IdList pidl, SIGDN sigdnName,
     [MarshalAs(UnmanagedType.LPWStr)]
     out string name);
 public HRESULT GetDisplayName(SIGDN sigdnName, [NativeTypeName("LPWSTR *")] ushort **ppszName)
 {
     return(((delegate * unmanaged <IShellItem *, SIGDN, ushort **, int>)(lpVtbl[5]))((IShellItem *)Unsafe.AsPointer(ref this), sigdnName, ppszName));
 }
 public string GetDisplayName(SIGDN type) => this._Item.GetDisplayName(type);
 public static extern HRESULT SHGetNameFromIDList([NativeTypeName("LPCITEMIDLIST")] ITEMIDLIST *pidl, SIGDN sigdnName, [NativeTypeName("PWSTR *")] ushort **ppszName);
Beispiel #29
0
 /// <summary>Gets the display name of the IShellItem object.</summary>
 /// <param name="sigdnName">One of the SIGDN values that indicates how the name should look.</param>
 /// <returns>
 /// A value that, when this function returns successfully, receives the address of a pointer to the retrieved display name.
 /// </returns>
 SafeCoTaskMemString GetDisplayName(SIGDN sigdnName);
Beispiel #30
0
 private string GetDisplayName(SIGDN dn)
 {
     try { return(iShellItem?.GetDisplayName(dn)); } catch { }
     return(null);
 }