Exemple #1
0
        /// <devdoc>
        ///     Loads a picture from the requested stream.
        /// </devdoc>
        private void LoadPicture(UnsafeNativeMethods.IStream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            try {
                Guid g = typeof(UnsafeNativeMethods.IPicture).GUID;
                UnsafeNativeMethods.IPicture picture = null;

                new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Assert();

                try {
                    picture = UnsafeNativeMethods.OleCreateIPictureIndirect(null, ref g, true);
                    UnsafeNativeMethods.IPersistStream ipictureAsIPersist = (UnsafeNativeMethods.IPersistStream)picture;
                    ipictureAsIPersist.Load(stream);

                    if (picture != null && picture.GetPictureType() == NativeMethods.Ole.PICTYPE_ICON)
                    {
                        IntPtr cursorHandle = picture.GetHandle();
                        Size   picSize      = GetIconSize(cursorHandle);
                        if (DpiHelper.IsScalingRequired)
                        {
                            picSize = DpiHelper.LogicalToDeviceUnits(picSize);
                        }

                        handle = SafeNativeMethods.CopyImageAsCursor(new HandleRef(this, cursorHandle), NativeMethods.IMAGE_CURSOR,
                                                                     picSize.Width, picSize.Height, 0);
                        ownHandle = true;
                    }
                    else
                    {
                        throw new ArgumentException(string.Format(SR.InvalidPictureType,
                                                                  "picture",
                                                                  "Cursor"), "picture");
                    }
                }
                finally {
                    CodeAccessPermission.RevertAssert();
                    // destroy the picture...
                    if (picture != null)
                    {
                        Marshal.ReleaseComObject(picture);
                    }
                }
            }
            catch (COMException e) {
                Debug.Fail(e.ToString());
                throw new ArgumentException(SR.InvalidPictureFormat, "stream", e);
            }
        }
Exemple #2
0
 // FIXME what's it doing here? There's probably a reason this was added here.
 static public void RevertAssert()
 {
     CodeAccessPermission.RevertAssert();
 }
Exemple #3
0
        // FIXME what's it doing here? There's probably a reason this was added here.
        static public void RevertAssert()
        {
#if !DISABLE_CAS_USE
            CodeAccessPermission.RevertAssert();
#endif
        }