Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / CompMod / Microsoft / Win32 / SafeHandles / SafeProcessHandle.cs / 1 / SafeProcessHandle.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: SafeProcessHandle ** ** A wrapper for a process handle ** ** ===========================================================*/ using System; using System.Security; using System.Diagnostics; using System.Security.Permissions; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using Microsoft.Win32; using Microsoft.Win32.SafeHandles; using System.Runtime.ConstrainedExecution; namespace Microsoft.Win32.SafeHandles { [HostProtectionAttribute(MayLeakOnAbort = true)] [SuppressUnmanagedCodeSecurityAttribute] internal sealed class SafeProcessHandle : SafeHandleZeroOrMinusOneIsInvalid { internal static SafeProcessHandle InvalidHandle = new SafeProcessHandle(IntPtr.Zero); // Note that OpenProcess returns 0 on failure internal SafeProcessHandle() : base(true) {} [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode=true)] internal SafeProcessHandle(IntPtr handle) : base (true) { SetHandle(handle); } // Not currently called //[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode=true)] //internal SafeProcessHandle(IntPtr existingHandle, bool ownsHandle) : base(ownsHandle) { // SetHandle(existingHandle); //} [DllImport(ExternDll.Kernel32, CharSet=System.Runtime.InteropServices.CharSet.Auto, SetLastError=true)] internal static extern SafeProcessHandle OpenProcess(int access, bool inherit, int processId); internal void InitialSetHandle(IntPtr h){ Debug.Assert(base.IsInvalid, "Safe handle should only be set once"); base.handle = h; } override protected bool ReleaseHandle() { return SafeNativeMethods.CloseHandle(handle); } } }
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ConditionalAttribute.cs
- UndoEngine.cs
- ToolStripItemEventArgs.cs
- Size3D.cs
- DatatypeImplementation.cs
- BitmapVisualManager.cs
- StylusPointProperty.cs
- ObjectDataSource.cs
- FixedSOMFixedBlock.cs
- PreApplicationStartMethodAttribute.cs
- UniqueEventHelper.cs
- InstanceDescriptor.cs
- TrustManagerMoreInformation.cs
- CommandHelper.cs
- ToolBarTray.cs
- LinkDescriptor.cs
- StubHelpers.cs
- TiffBitmapDecoder.cs
- RelationshipEnd.cs
- TreeViewAutomationPeer.cs
- ArrayWithOffset.cs
- FutureFactory.cs
- Themes.cs
- Vector3DValueSerializer.cs
- IgnoreSectionHandler.cs
- DbConnectionPoolCounters.cs
- ProfileSection.cs
- DesignerForm.cs
- LoadItemsEventArgs.cs
- ScriptRegistrationManager.cs
- RMEnrollmentPage1.cs
- LiteralText.cs
- XmlSchemaDatatype.cs
- CryptoStream.cs
- Part.cs
- SecUtil.cs
- StringUtil.cs
- ResourceAssociationSetEnd.cs
- DbConnectionPoolIdentity.cs
- Drawing.cs
- EditorAttribute.cs
- ToolBarButton.cs
- DuplicateWaitObjectException.cs
- ErrorWrapper.cs
- TargetPerspective.cs
- KeyTime.cs
- XPathNavigator.cs
- AdapterUtil.cs
- LicenseManager.cs
- NetStream.cs
- XmlUtil.cs
- SqlClientFactory.cs
- ProgressBarAutomationPeer.cs
- ITextView.cs
- TagPrefixAttribute.cs
- AnimationStorage.cs
- Vector3dCollection.cs
- ZipIOFileItemStream.cs
- ImageFormatConverter.cs
- DataGridSortCommandEventArgs.cs
- XmlReader.cs
- TcpStreams.cs
- OracleColumn.cs
- PathFigureCollectionValueSerializer.cs
- FormsAuthenticationUserCollection.cs
- documentsequencetextview.cs
- TypeResolvingOptionsAttribute.cs
- EntityDataSourceSelectingEventArgs.cs
- TextReader.cs
- BindingGroup.cs
- XXXOnTypeBuilderInstantiation.cs
- WebRequestModuleElement.cs
- PathStreamGeometryContext.cs
- DockPatternIdentifiers.cs
- RootProfilePropertySettingsCollection.cs
- WebPartConnectionsCancelVerb.cs
- recordstatescratchpad.cs
- SingleBodyParameterMessageFormatter.cs
- HttpCachePolicy.cs
- StringSource.cs
- SchemaCollectionPreprocessor.cs
- TagNameToTypeMapper.cs
- BaseDataList.cs
- CorrelationQueryBehavior.cs
- XmlLinkedNode.cs
- BufferBuilder.cs
- WrapPanel.cs
- DataGridViewSelectedRowCollection.cs
- BufferedGraphicsManager.cs
- DebugView.cs
- TypedTableBase.cs
- EntryPointNotFoundException.cs
- DoubleAnimationUsingPath.cs
- PropertyMappingExceptionEventArgs.cs
- EntityProxyTypeInfo.cs
- DispatcherExceptionEventArgs.cs
- DefaultMergeHelper.cs
- DoubleAnimationUsingPath.cs
- PolicyImporterElementCollection.cs
- DataGridViewRowCancelEventArgs.cs