mirror of
https://github.com/ZuneDev/ZuneShell.dll.git
synced 2026-07-27 13:11:51 -07:00
36 lines
880 B
C#
36 lines
880 B
C#
using System;
|
|
using System.Runtime.ConstrainedExecution;
|
|
using System.Runtime.InteropServices;
|
|
using System.Security.Permissions;
|
|
using Microsoft.Win32.SafeHandles;
|
|
|
|
namespace MicrosoftZuneLibrary
|
|
{
|
|
[SecurityPermission(SecurityAction.InheritanceDemand, UnmanagedCode = true)]
|
|
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
|
|
public class SafeBitmap : SafeHandleZeroOrMinusOneIsInvalid
|
|
{
|
|
public unsafe SafeBitmap(HBITMAP* hBitmap)
|
|
: base(ownsHandle: true)
|
|
{
|
|
try
|
|
{
|
|
IntPtr intPtr = (handle = (IntPtr)hBitmap);
|
|
}
|
|
catch
|
|
{
|
|
//try-fault
|
|
base.Dispose(disposing: true);
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
|
|
[return: MarshalAs(UnmanagedType.U1)]
|
|
protected unsafe override bool ReleaseHandle()
|
|
{
|
|
return (Module.DeleteObject((void*)handle) != 0) ? true : false;
|
|
}
|
|
}
|
|
}
|