private ImageListStreamer(SerializationInfo info, StreamingContext context)
 {
     SerializationInfoEnumerator enumerator = info.GetEnumerator();
     if (enumerator != null)
     {
         while (enumerator.MoveNext())
         {
             if (string.Equals(enumerator.Name, "Data", StringComparison.OrdinalIgnoreCase))
             {
                 byte[] input = (byte[]) enumerator.Value;
                 if (input != null)
                 {
                     IntPtr userCookie = System.Windows.Forms.UnsafeNativeMethods.ThemingScope.Activate();
                     try
                     {
                         MemoryStream dataStream = new MemoryStream(this.Decompress(input));
                         lock (internalSyncObject)
                         {
                             SafeNativeMethods.InitCommonControls();
                             this.nativeImageList = new ImageList.NativeImageList(SafeNativeMethods.ImageList_Read(new System.Windows.Forms.UnsafeNativeMethods.ComStreamFromDataStream(dataStream)));
                         }
                     }
                     finally
                     {
                         System.Windows.Forms.UnsafeNativeMethods.ThemingScope.Deactivate(userCookie);
                     }
                     if (this.nativeImageList.Handle == IntPtr.Zero)
                     {
                         throw new InvalidOperationException(System.Windows.Forms.SR.GetString("ImageListStreamerLoadFailed"));
                     }
                 }
             }
         }
     }
 }
 private void Dispose(bool disposing)
 {
     if (disposing && (this.nativeImageList != null))
     {
         this.nativeImageList.Dispose();
         this.nativeImageList = null;
     }
 }
Пример #3
0
 private void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (nativeImageList != null)
         {
             nativeImageList.Dispose();
             nativeImageList = null;
         }
     }
 }
Пример #4
0
        private ImageListStreamer(SerializationInfo info, StreamingContext context)
        {
            SerializationInfoEnumerator sie = info.GetEnumerator();

            if (sie is null)
            {
                return;
            }

            while (sie.MoveNext())
            {
                if (string.Equals(sie.Name, "Data", StringComparison.OrdinalIgnoreCase))
                {
#if DEBUG
                    try
                    {
#endif
                    byte[] dat = (byte[])sie.Value;
                    if (dat != null)
                    {
                        // We enclose this imagelist handle create in a theming scope.
                        IntPtr userCookie = ThemingScope.Activate(Application.UseVisualStyles);

                        try
                        {
                            using MemoryStream ms = new MemoryStream(Decompress(dat));
                            lock (internalSyncObject)
                            {
                                ComCtl32.InitCommonControls();
                                nativeImageList = new ImageList.NativeImageList(new Ole32.GPStream(ms));
                            }
                        }
                        finally
                        {
                            ThemingScope.Deactivate(userCookie);
                        }

                        if (nativeImageList.Handle == IntPtr.Zero)
                        {
                            throw new InvalidOperationException(SR.ImageListStreamerLoadFailed);
                        }
                    }
#if DEBUG
                }
                catch (Exception e)
                {
                    Debug.Fail("ImageList serialization failure: " + e.ToString());
                    throw;
                }
#endif
                }
            }
        }
Пример #5
0
        /**
         * Constructor used in deserialization
         */
        private ImageListStreamer(SerializationInfo info, StreamingContext context)
        {
            SerializationInfoEnumerator sie = info.GetEnumerator();

            if (sie == null)
            {
                return;
            }
            while (sie.MoveNext())
            {
                if (String.Equals(sie.Name, "Data", StringComparison.OrdinalIgnoreCase))
                {
#if DEBUG
                    try {
#endif
                    byte[] dat = (byte[])sie.Value;
                    if (dat != null)
                    {
                        //VSW #123063: We enclose this imagelist handle create in a theming scope. This is a temporary
                        //             solution till we tackle the bigger issue tracked by VSW #95247
                        IntPtr userCookie = UnsafeNativeMethods.ThemingScope.Activate();

                        try
                        {
                            MemoryStream ms = new MemoryStream(Decompress(dat));

                            lock (internalSyncObject) {
                                SafeNativeMethods.InitCommonControls();
                                nativeImageList = new ImageList.NativeImageList(
                                    SafeNativeMethods.ImageList_Read(new UnsafeNativeMethods.ComStreamFromDataStream(ms)));
                            }
                        }
                        finally
                        {
                            UnsafeNativeMethods.ThemingScope.Deactivate(userCookie);
                        }
                        if (nativeImageList.Handle == IntPtr.Zero)
                        {
                            throw new InvalidOperationException(SR.GetString(SR.ImageListStreamerLoadFailed));
                        }
                    }
#if DEBUG
                }
                catch (Exception e) {
                    Debug.Fail("ImageList serialization failure: " + e.ToString());
                    throw;
                }
#endif
                }
            }
        }
        /**
         * Constructor used in deserialization
         */
        private ImageListStreamer(SerializationInfo info, StreamingContext context)
        {
            SerializationInfoEnumerator sie = info.GetEnumerator();
            if (sie == null)
            {
                return;
            }
            while (sie.MoveNext())
            {
                if (String.Equals(sie.Name, "Data", StringComparison.OrdinalIgnoreCase))
                {
#if DEBUG
                    try {
#endif
                    byte[] dat = (byte[])sie.Value;
                    if (dat != null)
                    {
                        //VSW #123063: We enclose this imagelist handle create in a theming scope. This is a temporary 
                        //             solution till we tackle the bigger issue tracked by VSW #95247
                        IntPtr userCookie = UnsafeNativeMethods.ThemingScope.Activate();

                        try
                        {
                            MemoryStream ms = new MemoryStream(Decompress(dat));

                            lock (internalSyncObject) {
                                SafeNativeMethods.InitCommonControls();
                                nativeImageList = new ImageList.NativeImageList(
                                    SafeNativeMethods.ImageList_Read(new UnsafeNativeMethods.ComStreamFromDataStream(ms)));
                            }
                        }
                        finally
                        {
                            UnsafeNativeMethods.ThemingScope.Deactivate(userCookie);
                        }
                        if (nativeImageList.Handle == IntPtr.Zero)
                        {
                            throw new InvalidOperationException(SR.GetString(SR.ImageListStreamerLoadFailed));
                        }
                    }
#if DEBUG
                    }
                    catch (Exception e) {
                        Debug.Fail("ImageList serialization failure: " + e.ToString());
                        throw;
                    }
#endif
                }
            }
        }
Пример #7
0
        /**
         * Constructor used in deserialization
         */
        private ImageListStreamer(SerializationInfo info, StreamingContext context)
        {
            SerializationInfoEnumerator sie = info.GetEnumerator();

            if (sie == null)
            {
                return;
            }
            for (; sie.MoveNext();)
            {
                if (String.Compare(sie.Name, "Data", true, CultureInfo.InvariantCulture) == 0)
                {
#if DEBUG
                    try {
#endif
                    byte[] dat = (byte[])sie.Value;
                    if (dat != null)
                    {
                        SafeNativeMethods.InitCommonControls();
                        nativeImageList = new ImageList.NativeImageList(
                            SafeNativeMethods.ImageList_Read(new UnsafeNativeMethods.ComStreamFromDataStream(new MemoryStream(Decompress(dat)))));
                        if (nativeImageList.Handle == IntPtr.Zero)
                        {
                            throw new InvalidOperationException(SR.GetString(SR.ImageListStreamerLoadFailed));
                        }
                    }
#if DEBUG
                }
                catch (Exception e) {
                    Debug.Fail("imagelist serialization failure: " + e.ToString());
                    throw e;
                }
#endif
                }
            }
        }
        private ImageListStreamer(SerializationInfo info, StreamingContext context)
        {
            SerializationInfoEnumerator enumerator = info.GetEnumerator();

            if (enumerator != null)
            {
                while (enumerator.MoveNext())
                {
                    if (string.Equals(enumerator.Name, "Data", StringComparison.OrdinalIgnoreCase))
                    {
                        byte[] input = (byte[])enumerator.Value;
                        if (input != null)
                        {
                            IntPtr userCookie = System.Windows.Forms.UnsafeNativeMethods.ThemingScope.Activate();
                            try
                            {
                                MemoryStream dataStream = new MemoryStream(this.Decompress(input));
                                lock (internalSyncObject)
                                {
                                    SafeNativeMethods.InitCommonControls();
                                    this.nativeImageList = new ImageList.NativeImageList(SafeNativeMethods.ImageList_Read(new System.Windows.Forms.UnsafeNativeMethods.ComStreamFromDataStream(dataStream)));
                                }
                            }
                            finally
                            {
                                System.Windows.Forms.UnsafeNativeMethods.ThemingScope.Deactivate(userCookie);
                            }
                            if (this.nativeImageList.Handle == IntPtr.Zero)
                            {
                                throw new InvalidOperationException(System.Windows.Forms.SR.GetString("ImageListStreamerLoadFailed"));
                            }
                        }
                    }
                }
            }
        }
 private void Dispose(bool disposing) {
     if (disposing) {
         if (nativeImageList != null) {
             nativeImageList.Dispose();
             nativeImageList = null;
         }
     }
 }
 private void Dispose(bool disposing)
 {
     if (disposing && (this.nativeImageList != null))
     {
         this.nativeImageList.Dispose();
         this.nativeImageList = null;
     }
 }