markus / ImageComparer / Markus.ImageComparer / SafeHBitmapHandle.cs @ 84605c0c
이력 | 보기 | 이력해설 | 다운로드 (963 Bytes)
1 |
using Microsoft.Win32.SafeHandles; |
---|---|
2 |
using System; |
3 |
using System.Collections.Generic; |
4 |
using System.Linq; |
5 |
using System.Runtime.InteropServices; |
6 |
using System.Security; |
7 |
using System.Text; |
8 |
using System.Threading.Tasks; |
9 |
|
10 |
namespace Markus.Image |
11 |
{ |
12 |
class SafeHBitmapHandle : SafeHandleZeroOrMinusOneIsInvalid |
13 |
{ |
14 |
[SecurityCritical] |
15 |
public SafeHBitmapHandle(IntPtr preexistingHandle, bool ownsHandle) |
16 |
: base(ownsHandle) |
17 |
{ |
18 |
SetHandle(preexistingHandle); |
19 |
} |
20 |
|
21 |
protected override bool ReleaseHandle() |
22 |
{ |
23 |
return NativeMethods.DeleteObject(handle); |
24 |
} |
25 |
} |
26 |
|
27 |
/// <summary> |
28 |
/// FxCop requires all Marshalled functions to be in a class called NativeMethods. |
29 |
/// </summary> |
30 |
internal static class NativeMethods |
31 |
{ |
32 |
[DllImport("gdi32.dll")] |
33 |
[return: MarshalAs(UnmanagedType.Bool)] |
34 |
internal static extern bool DeleteObject(IntPtr hObject); |
35 |
} |
36 |
} |