1 // ==++== 2 // 3 // Copyright (c) Microsoft Corporation. All rights reserved. 4 // 5 // ==--== 6 /*============================================================ 7 ** 8 ** Class: SafeEventLogReadHandle 9 ** 10 ** <EMAIL>Author: David Gutierrez (Microsoft) </EMAIL> 11 ** 12 ** A wrapper for event log handles 13 ** 14 ** Date: July 8, 2002 15 ** 16 ===========================================================*/ 17 18 using System; 19 using System.Security; 20 using System.Security.Permissions; 21 using System.Runtime.InteropServices; 22 using System.Runtime.CompilerServices; 23 using Microsoft.Win32; 24 using Microsoft.Win32.SafeHandles; 25 using System.Runtime.ConstrainedExecution; 26 using System.Runtime.Versioning; 27 28 namespace Microsoft.Win32.SafeHandles { 29 [HostProtectionAttribute(MayLeakOnAbort = true)] 30 [SuppressUnmanagedCodeSecurityAttribute] 31 internal sealed class SafeEventLogReadHandle : SafeHandleZeroOrMinusOneIsInvalid 32 { 33 // Note: OpenEventLog returns 0 on failure. 34 SafeEventLogReadHandle()35 internal SafeEventLogReadHandle () : base(true) { } 36 37 38 [DllImport(ExternDll.Advapi32, CharSet=System.Runtime.InteropServices.CharSet.Unicode, SetLastError=true)] 39 [ResourceExposure(ResourceScope.Machine)] OpenEventLog(string UNCServerName, string sourceName)40 internal static extern SafeEventLogReadHandle OpenEventLog(string UNCServerName, string sourceName); 41 42 [DllImport(ExternDll.Advapi32, SetLastError=true)] 43 [ResourceExposure(ResourceScope.None)] 44 [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] CloseEventLog(IntPtr hEventLog)45 private static extern bool CloseEventLog(IntPtr hEventLog); 46 ReleaseHandle()47 override protected bool ReleaseHandle() 48 { 49 return CloseEventLog(handle); 50 } 51 } 52 } 53 54 55