/// <summary>
        /// Constructs a new Shell object from IDList pointer
        /// </summary>
        /// <param name="idListPtr"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        internal static ShellObject Create(IntPtr idListPtr, ShellContainer parent)
        {
            IShellItem nativeShellItem;

            int retCode = ShellNativeMethods.SHCreateShellItem(
                IntPtr.Zero,
                parent.NativeShellFolder,
                idListPtr, out nativeShellItem);

            if (!CoreErrorHelper.Succeeded(retCode))
            {
                return(null);
            }

            return(ShellObjectFactory.Create(nativeShellItem));
        }
        /// <summary>
        /// Constructs a new Shell object from IDList pointer
        /// </summary>
        /// <param name="idListPtr"></param>
        /// <returns></returns>
        internal static ShellObject Create(IntPtr idListPtr)
        {
            // Throw exception if not running on Win7 or newer.
            CoreHelpers.ThrowIfNotVista();

            Guid guid = new Guid(ShellIIDGuid.IShellItem2);

            IShellItem2 nativeShellItem;
            int         retCode = ShellNativeMethods.SHCreateItemFromIDList(idListPtr, ref guid, out nativeShellItem);

            if (!CoreErrorHelper.Succeeded(retCode))
            {
                return(null);
            }
            return(ShellObjectFactory.Create(nativeShellItem));
        }
        /// <summary>
        /// Creates a ShellObject given a parsing name
        /// </summary>
        /// <param name="parsingName"></param>
        /// <returns>A newly constructed ShellObject object</returns>
        internal static ShellObject Create(string parsingName)
        {
            if (string.IsNullOrEmpty(parsingName))
            {
                throw new ArgumentNullException("parsingName");
            }

            // Create a native shellitem from our path
            IShellItem2 nativeShellItem;
            Guid        guid    = new Guid(ShellIIDGuid.IShellItem2);
            int         retCode = ShellNativeMethods.SHCreateItemFromParsingName(parsingName, IntPtr.Zero, ref guid, out nativeShellItem);

            if (!CoreErrorHelper.Succeeded(retCode))
            {
                throw new ShellException(LocalizedMessages.ShellObjectFactoryUnableToCreateItem, Marshal.GetExceptionForHR(retCode));
            }
            return(ShellObjectFactory.Create(nativeShellItem));
        }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public bool MoveNext()
        {
            if (nativeEnumIdList == null)
            {
                return(false);
            }

            IntPtr  item;
            uint    numItemsReturned;
            uint    itemsRequested = 1;
            HResult hr             = nativeEnumIdList.Next(itemsRequested, out item, out numItemsReturned);

            if (numItemsReturned < itemsRequested || hr != HResult.Ok)
            {
                return(false);
            }

            currentItem = ShellObjectFactory.Create(item, nativeShellFolder);

            return(true);
        }
Esempio n. 5
0
        /// <summary>
        /// Creates a ShellObject collection from an IShellItemArray
        /// </summary>
        /// <param name="iArray">IShellItemArray pointer</param>
        /// <param name="readOnly">Indicates whether the collection shouldbe read-only or not</param>
        internal ShellObjectCollection(IShellItemArray iArray, bool readOnly)
        {
            this.readOnly = readOnly;

            if (iArray != null)
            {
                try
                {
                    uint itemCount = 0;
                    iArray.GetCount(out itemCount);
                    content.Capacity = (int)itemCount;
                    for (uint index = 0; index < itemCount; index++)
                    {
                        IShellItem iShellItem = null;
                        iArray.GetItemAt(index, out iShellItem);
                        content.Add(ShellObjectFactory.Create(iShellItem));
                    }
                }
                finally
                {
                    Marshal.ReleaseComObject(iArray);
                }
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Creates a ShellObject subclass given a parsing name.
 /// For file system items, this method will only accept absolute paths.
 /// </summary>
 /// <param name="parsingName">The parsing name of the object.</param>
 /// <returns>A newly constructed ShellObject object.</returns>
 public static ShellObject FromParsingName(string parsingName)
 {
     return(ShellObjectFactory.Create(parsingName));
 }