Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / UIAutomation / UIAutomationClient / MS / Internal / Automation / SafeProcessHandle.cs / 1305600 / SafeProcessHandle.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: // // History: // 10/04/2003 : [....] Created //--------------------------------------------------------------------------- // PRESHARP: In order to avoid generating warnings about unkown message numbers and unknown pragmas. #pragma warning disable 1634, 1691 using System; using System.Security; using System.Security.Permissions; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using System.Windows.Automation; using Microsoft.Win32.SafeHandles; using MS.Win32; namespace MS.Internal.Automation { internal sealed class SafeProcessHandle : SafeHandleZeroOrMinusOneIsInvalid { // This constructor is used by the P/Invoke marshaling layer // to allocate a SafeHandle instance. P/Invoke then does the // appropriate method call, storing the handle in this class. private SafeProcessHandle() : base(true) {} internal SafeProcessHandle(NativeMethods.HWND hwnd) : base(true) { int processId; // Get process id... // GetWindowThreadProcessId does use SetLastError(). So a call to GetLastError() would be meanless. // Disabling the PreSharp warning. #pragma warning suppress 6523 if (SafeNativeMethods.GetWindowThreadProcessId(hwnd, out processId) == 0) { throw new ElementNotAvailableException(); } SetHandle(Misc.OpenProcess(UnsafeNativeMethods.PROCESS_QUERY_INFORMATION | UnsafeNativeMethods.PROCESS_VM_READ, false, processId, hwnd)); } // protected override bool ReleaseHandle() { return Misc.CloseHandle(handle); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- PlatformCulture.cs
- ResourceSet.cs
- FileIOPermission.cs
- DispatcherEventArgs.cs
- Environment.cs
- CodeParameterDeclarationExpressionCollection.cs
- _IPv6Address.cs
- NestedContainer.cs
- LinkAreaEditor.cs
- CompilerGeneratedAttribute.cs
- RoleManagerEventArgs.cs
- DirectionalLight.cs
- StreamResourceInfo.cs
- ServiceInstanceProvider.cs
- DefaultCommandConverter.cs
- TemplatedAdorner.cs
- DataGridViewRowsAddedEventArgs.cs
- Point3DConverter.cs
- EventLogRecord.cs
- FontUnitConverter.cs
- BufferedGraphics.cs
- ColumnResizeUndoUnit.cs
- CryptoApi.cs
- ConsumerConnectionPointCollection.cs
- XmlSerializationReader.cs
- PerfCounters.cs
- WebContext.cs
- MouseButton.cs
- Int32CAMarshaler.cs
- FamilyCollection.cs
- Semaphore.cs
- Argument.cs
- MultiPageTextView.cs
- RequestStatusBarUpdateEventArgs.cs
- InvalidBodyAccessException.cs
- ThreadAttributes.cs
- BinHexDecoder.cs
- RulePatternOps.cs
- WorkflowViewStateService.cs
- SizeF.cs
- PnrpPermission.cs
- ConfigPathUtility.cs
- FixedTextSelectionProcessor.cs
- PasswordTextNavigator.cs
- ValidationPropertyAttribute.cs
- XpsSerializerWriter.cs
- ModifiableIteratorCollection.cs
- FtpRequestCacheValidator.cs
- KnownTypesHelper.cs
- ViewSimplifier.cs
- InheritanceRules.cs
- SrgsSemanticInterpretationTag.cs
- EncoderNLS.cs
- SignedXml.cs
- TogglePatternIdentifiers.cs
- EdmRelationshipRoleAttribute.cs
- UriExt.cs
- ColorConverter.cs
- FileInfo.cs
- ZipIOBlockManager.cs
- DiscoveryExceptionDictionary.cs
- MemoryFailPoint.cs
- QilNode.cs
- ValidatedControlConverter.cs
- NativeWindow.cs
- BitmapEffectvisualstate.cs
- Composition.cs
- SqlAliasesReferenced.cs
- SqlConnectionHelper.cs
- SourceFileInfo.cs
- TextLineResult.cs
- ContextProperty.cs
- CacheEntry.cs
- XmlEntityReference.cs
- WeakReference.cs
- WriteLineDesigner.xaml.cs
- TraceHandlerErrorFormatter.cs
- PersianCalendar.cs
- MatrixKeyFrameCollection.cs
- ConstraintManager.cs
- LZCodec.cs
- DetailsViewUpdatedEventArgs.cs
- HeaderedItemsControl.cs
- ResourceSet.cs
- PrivilegeNotHeldException.cs
- ViewLoader.cs
- XmlSerializerAssemblyAttribute.cs
- EventLogEntryCollection.cs
- LocationInfo.cs
- AgileSafeNativeMemoryHandle.cs
- XmlSchemaCompilationSettings.cs
- FixedSOMLineCollection.cs
- VSWCFServiceContractGenerator.cs
- ModuleBuilder.cs
- DisableDpiAwarenessAttribute.cs
- SerializationFieldInfo.cs
- TreeNodeStyleCollection.cs
- SafeCoTaskMem.cs
- PermissionSet.cs
- Delay.cs