Beispiel #1
0
        internal static IPropertyStore CreateDefaultPropertyStore(ShellObject shellObj)
        {
            IPropertyStore nativePropertyStore = null;

            Guid guid = new Guid(ShellIIDGuid.IPropertyStore);
            int  hr   = shellObj.NativeShellItem2.GetPropertyStore(
                ShellNativeMethods.GetPropertyStoreOptions.BestEffort,
                ref guid,
                out nativePropertyStore);

            // throw on failure
            if (nativePropertyStore == null || !CoreErrorHelper.Succeeded(hr))
            {
                throw new Exception(hr.ToString());
            }

            return(nativePropertyStore);
        }
        /// <summary>
        ///     Gets the localized display string that describes the current sort order.
        /// </summary>
        /// <param name="descending">
        ///     Indicates the sort order should
        ///     reference the string "Z on top"; otherwise, the sort order should reference the string "A on top".
        /// </param>
        /// <returns>The sort description for this property.</returns>
        /// <remarks>
        ///     The string retrieved by this method is determined by flags set in the
        ///     <c>sortDescription</c> attribute of the <c>labelInfo</c> element in the property's .propdesc file.
        /// </remarks>
        public string GetSortDescriptionLabel(bool descending)
        {
            IntPtr ptr   = IntPtr.Zero;
            string label = string.Empty;

            if (NativePropertyDescription != null)
            {
                HResult hr = NativePropertyDescription.GetSortDescriptionLabel(descending, out ptr);

                if (CoreErrorHelper.Succeeded(hr) && ptr != IntPtr.Zero)
                {
                    label = Marshal.PtrToStringUni(ptr);
                    // Free the string
                    Marshal.FreeCoTaskMem(ptr);
                }
            }

            return(label);
        }