예제 #1
0
        public static unsafe ItemIdList Create(IMalloc m, params byte[][] data)
        {
            //if (m == null)
            {
                //	throw new ArgumentNullException("m");
            }

            int len = ItemId.HeaderSize;             // terminator

            foreach (byte[] item in data)
            {
                len += item.Length + ItemId.HeaderSize;
            }

            IntPtr p = (m == null) ? Marshal.AllocCoTaskMem(len) : m.Alloc(len);

            if (p == IntPtr.Zero)
            {
                throw new OutOfMemoryException("Shell failed to allocate ITEMIDLIST");
            }

            IntPtr workingP = p;

            foreach (byte[] item in data)
            {
                *((ushort *)workingP) = checked ((ushort)(item.Length + ItemId.HeaderSize));
                workingP = (IntPtr)((int)workingP + ItemId.HeaderSize);
                Marshal.Copy(item, 0, workingP, item.Length);
                workingP = (IntPtr)((int)workingP + item.Length);
            }

            *((ushort *)workingP) = 0;

            return(new ItemIdList(p));
        }
예제 #2
0
 public IntPtr Alloc(int cb)
 {
     return(m.Alloc(cb));
 }