Ejemplo n.º 1
0
        internal static IEnumerable <Pidl> ConvertPidlEnumeration(Native.IEnumIDList pEnum)
        {
            List <Pidl> children = new List <Pidl>();

            IntPtr pidl  = IntPtr.Zero;
            int    count = 0;

            // get the first value in the enumeration (the args in the native method signature are more "ref" rather than "out")
            pEnum.Next(1, out pidl, out count);

            // check and loop if value is valid
            while (!IntPtr.Zero.Equals(pidl) && count == 1)
            {
                children.Add(new Pidl(pidl, true));

                // reset counters (required, see note above)
                pidl  = IntPtr.Zero;
                count = 0;

                // get the next value in the enumeration
                pEnum.Next(1, out pidl, out count);
            }

            return(children);
        }
Ejemplo n.º 2
0
        private IEnumerable <Pidl> EnumerateChildPidls(Native.SHCONTF flags)
        {
            if (!_isFolder)
            {
                throw new InvalidOperationException("Children can only be enumerated on a folder-type item.");
            }
            if (_shellFolder == null)
            {
                return(new Pidl[0]);
            }

            // Get the IEnumIDList interface pointer.
            Native.IEnumIDList pEnum = null;
            uint hRes = _shellFolder.EnumObjects(IntPtr.Zero, flags, out pEnum);

            if (hRes != 0)
            {
                throw new Exception("IShellFolder::EnumObjects failed to enumerate child objects.", Marshal.GetExceptionForHR((int)hRes));
            }

            try
            {
                return(Pidl.ConvertPidlEnumeration(pEnum));
            }
            finally
            {
                // Free the interface pointer.
                Marshal.ReleaseComObject(pEnum);
            }
        }