From 5c04af1684acc1957be3d7604d89e76daca84c9a Mon Sep 17 00:00:00 2001 From: Robin Date: Tue, 26 Apr 2016 23:13:37 +0200 Subject: [PATCH] Undo of some cleanup which causes issues, --- GreenshotPlugin/UnmanagedHelpers/GDI32.cs | 47 +++++++++++++++++++++- GreenshotPlugin/UnmanagedHelpers/User32.cs | 17 ++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/GreenshotPlugin/UnmanagedHelpers/GDI32.cs b/GreenshotPlugin/UnmanagedHelpers/GDI32.cs index dd4c9d604..95462a63b 100644 --- a/GreenshotPlugin/UnmanagedHelpers/GDI32.cs +++ b/GreenshotPlugin/UnmanagedHelpers/GDI32.cs @@ -77,6 +77,16 @@ namespace GreenshotPlugin.UnmanagedHelpers { /// A hbitmap SafeHandle implementation /// public class SafeHBitmapHandle : SafeObjectHandle { + + /// + /// Needed for marshalling return values + /// + [SecurityCritical] + public SafeHBitmapHandle() : base(true) + { + + } + [SecurityCritical] public SafeHBitmapHandle(IntPtr preexistingHandle) : base(true) { SetHandle(preexistingHandle); @@ -87,8 +97,12 @@ namespace GreenshotPlugin.UnmanagedHelpers { /// A hRegion SafeHandle implementation /// public class SafeRegionHandle : SafeObjectHandle { + /// + /// Needed for marshalling return values + /// [SecurityCritical] - private SafeRegionHandle() : base(true) { + public SafeRegionHandle() : base(true) + { } [SecurityCritical] @@ -101,6 +115,14 @@ namespace GreenshotPlugin.UnmanagedHelpers { /// A dibsection SafeHandle implementation /// public class SafeDibSectionHandle : SafeObjectHandle { + /// + /// Needed for marshalling return values + /// + [SecurityCritical] + public SafeDibSectionHandle() : base(true) + { + } + [SecurityCritical] public SafeDibSectionHandle(IntPtr preexistingHandle) : base(true) { SetHandle(preexistingHandle); @@ -116,6 +138,13 @@ namespace GreenshotPlugin.UnmanagedHelpers { private static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject); private readonly SafeHandle _hdc; + /// + /// Needed for marshalling return values + /// + [SecurityCritical] + public SafeSelectObjectHandle() : base(true) + { + } [SecurityCritical] public SafeSelectObjectHandle(SafeDCHandle hdc, SafeHandle newHandle) : base(true) { @@ -141,6 +170,14 @@ namespace GreenshotPlugin.UnmanagedHelpers { [return: MarshalAs(UnmanagedType.Bool)] private static extern bool DeleteDC(IntPtr hDC); + /// + /// Needed for marshalling return values + /// + [SecurityCritical] + public SafeCompatibleDCHandle() : base(true) + { + } + [SecurityCritical] public SafeCompatibleDCHandle(IntPtr preexistingHandle) : base(true) { SetHandle(preexistingHandle); @@ -161,6 +198,14 @@ namespace GreenshotPlugin.UnmanagedHelpers { public class SafeDeviceContextHandle : SafeDCHandle { private readonly Graphics _graphics; + /// + /// Needed for marshalling return values + /// + [SecurityCritical] + public SafeDeviceContextHandle() : base(true) + { + } + [SecurityCritical] public SafeDeviceContextHandle(Graphics graphics, IntPtr preexistingHandle) : base(true) { _graphics = graphics; diff --git a/GreenshotPlugin/UnmanagedHelpers/User32.cs b/GreenshotPlugin/UnmanagedHelpers/User32.cs index ef85d5994..76b7c5056 100644 --- a/GreenshotPlugin/UnmanagedHelpers/User32.cs +++ b/GreenshotPlugin/UnmanagedHelpers/User32.cs @@ -359,6 +359,16 @@ namespace GreenshotPlugin.UnmanagedHelpers { /// A SafeHandle class implementation for the hIcon /// public class SafeIconHandle : SafeHandleZeroOrMinusOneIsInvalid { + + /// + /// Needed for marshalling return values + /// + [SecurityCritical] + public SafeIconHandle() : base(true) + { + } + + public SafeIconHandle(IntPtr hIcon) : base(true) { SetHandle(hIcon); } @@ -380,6 +390,13 @@ namespace GreenshotPlugin.UnmanagedHelpers { private readonly IntPtr _hWnd; + /// + /// Needed for marshalling return values + /// + public SafeWindowDCHandle() : base(true) + { + } + [SecurityCritical] public SafeWindowDCHandle(IntPtr hWnd, IntPtr preexistingHandle) : base(true) { _hWnd = hWnd;