Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / System.Runtime.DurableInstancing / System / Runtime / Interop / SafeEventLogWriteHandle.cs / 1305376 / SafeEventLogWriteHandle.cs
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------
namespace System.Runtime.Interop
{
using Microsoft.Win32.SafeHandles;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Globalization;
using System.Diagnostics;
using System.Security;
[Fx.Tag.SecurityNote(Critical = "Usage of SafeHandleZeroOrMinusOneIsInvalid, which is protected by a LinkDemand and InheritanceDemand")]
[SecurityCritical]
sealed class SafeEventLogWriteHandle : SafeHandleZeroOrMinusOneIsInvalid
{
// Note: RegisterEventSource returns 0 on failure
[Fx.Tag.SecurityNote(Critical = "Usage of SafeHandleZeroOrMinusOneIsInvalid, which is protected by a LinkDemand and InheritanceDemand")]
[SecurityCritical]
SafeEventLogWriteHandle() : base(true) { }
[ResourceConsumption(ResourceScope.Machine)]
[Fx.Tag.SecurityNote(Critical = "Usage of SafeHandleZeroOrMinusOneIsInvalid, which is protected by a LinkDemand and InheritanceDemand")]
[SecurityCritical]
public static SafeEventLogWriteHandle RegisterEventSource(string uncServerName, string sourceName)
{
SafeEventLogWriteHandle retval = UnsafeNativeMethods.RegisterEventSource(uncServerName, sourceName);
int error = Marshal.GetLastWin32Error();
if (retval.IsInvalid)
{
Debug.Print("SafeEventLogWriteHandle::RegisterEventSource[" + uncServerName + ", " + sourceName + "] Failed. Last Error: " +
error.ToString(CultureInfo.InvariantCulture));
}
return retval;
}
[DllImport("advapi32", SetLastError = true)]
[ResourceExposure(ResourceScope.None)]
static extern bool DeregisterEventSource(IntPtr hEventLog);
[Fx.Tag.SecurityNote(Critical = "Usage of SafeHandleZeroOrMinusOneIsInvalid, which is protected by a LinkDemand and InheritanceDemand")]
[SecurityCritical]
protected override bool ReleaseHandle()
{
return DeregisterEventSource(this.handle);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------
namespace System.Runtime.Interop
{
using Microsoft.Win32.SafeHandles;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Globalization;
using System.Diagnostics;
using System.Security;
[Fx.Tag.SecurityNote(Critical = "Usage of SafeHandleZeroOrMinusOneIsInvalid, which is protected by a LinkDemand and InheritanceDemand")]
[SecurityCritical]
sealed class SafeEventLogWriteHandle : SafeHandleZeroOrMinusOneIsInvalid
{
// Note: RegisterEventSource returns 0 on failure
[Fx.Tag.SecurityNote(Critical = "Usage of SafeHandleZeroOrMinusOneIsInvalid, which is protected by a LinkDemand and InheritanceDemand")]
[SecurityCritical]
SafeEventLogWriteHandle() : base(true) { }
[ResourceConsumption(ResourceScope.Machine)]
[Fx.Tag.SecurityNote(Critical = "Usage of SafeHandleZeroOrMinusOneIsInvalid, which is protected by a LinkDemand and InheritanceDemand")]
[SecurityCritical]
public static SafeEventLogWriteHandle RegisterEventSource(string uncServerName, string sourceName)
{
SafeEventLogWriteHandle retval = UnsafeNativeMethods.RegisterEventSource(uncServerName, sourceName);
int error = Marshal.GetLastWin32Error();
if (retval.IsInvalid)
{
Debug.Print("SafeEventLogWriteHandle::RegisterEventSource[" + uncServerName + ", " + sourceName + "] Failed. Last Error: " +
error.ToString(CultureInfo.InvariantCulture));
}
return retval;
}
[DllImport("advapi32", SetLastError = true)]
[ResourceExposure(ResourceScope.None)]
static extern bool DeregisterEventSource(IntPtr hEventLog);
[Fx.Tag.SecurityNote(Critical = "Usage of SafeHandleZeroOrMinusOneIsInvalid, which is protected by a LinkDemand and InheritanceDemand")]
[SecurityCritical]
protected override bool ReleaseHandle()
{
return DeregisterEventSource(this.handle);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- HtmlShim.cs
- TextCompositionEventArgs.cs
- BaseTemplateCodeDomTreeGenerator.cs
- BinaryWriter.cs
- ActiveXHelper.cs
- XmlQualifiedName.cs
- ClientConfigPaths.cs
- BinaryObjectWriter.cs
- BitmapEffectOutputConnector.cs
- UInt32.cs
- SignatureToken.cs
- ExceptionTrace.cs
- Utils.cs
- MetadataArtifactLoaderComposite.cs
- SpecularMaterial.cs
- CompositeCollectionView.cs
- LocalizabilityAttribute.cs
- AddInSegmentDirectoryNotFoundException.cs
- DurableInstanceContextProvider.cs
- PageAsyncTaskManager.cs
- CalendarModeChangedEventArgs.cs
- GenericUriParser.cs
- Authorization.cs
- Timer.cs
- ReflectionUtil.cs
- ContentValidator.cs
- keycontainerpermission.cs
- XhtmlConformanceSection.cs
- CounterSample.cs
- TypeSemantics.cs
- XmlSchemaImporter.cs
- WebControlsSection.cs
- TraceAsyncResult.cs
- SineEase.cs
- RegistrationProxy.cs
- PolyLineSegment.cs
- glyphs.cs
- ContextItemManager.cs
- CapacityStreamGeometryContext.cs
- ClientTargetCollection.cs
- SimpleWebHandlerParser.cs
- MetadataArtifactLoaderResource.cs
- CalendarDay.cs
- WorkflowExecutor.cs
- BamlTreeMap.cs
- SourceElementsCollection.cs
- WebServiceAttribute.cs
- ConfigXmlText.cs
- ListBoxItemWrapperAutomationPeer.cs
- CoTaskMemHandle.cs
- webclient.cs
- XmlReaderSettings.cs
- UIElementIsland.cs
- ListControlConvertEventArgs.cs
- CommonGetThemePartSize.cs
- Range.cs
- RemoteWebConfigurationHostStream.cs
- IResourceProvider.cs
- TrackingParticipant.cs
- PolyBezierSegmentFigureLogic.cs
- NotifyCollectionChangedEventArgs.cs
- HMAC.cs
- PostBackOptions.cs
- SqlDataReader.cs
- ReceiveMessageContent.cs
- XhtmlMobileTextWriter.cs
- JumpItem.cs
- PresentationTraceSources.cs
- BStrWrapper.cs
- IHttpResponseInternal.cs
- DashStyle.cs
- XmlSchemaObjectCollection.cs
- ServicePointManager.cs
- ManifestBasedResourceGroveler.cs
- SingleObjectCollection.cs
- Propagator.JoinPropagator.JoinPredicateVisitor.cs
- CLSCompliantAttribute.cs
- MasterPageBuildProvider.cs
- IdentifierService.cs
- EmptyElement.cs
- Event.cs
- RelatedEnd.cs
- XmlnsDictionary.cs
- UrlMappingsSection.cs
- TreeIterator.cs
- CaseStatementSlot.cs
- UpWmlPageAdapter.cs
- ProcessThread.cs
- LinkArea.cs
- SafeNativeMethods.cs
- BindingContext.cs
- Walker.cs
- ProcessManager.cs
- NotSupportedException.cs
- PropertyDescriptorComparer.cs
- Directory.cs
- ListViewUpdatedEventArgs.cs
- EventSetterHandlerConverter.cs
- ParseHttpDate.cs
- Double.cs