Code:
/ 4.0 / 4.0 / 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. //---------------------------------------------------------------------------- // //// 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
- PeerCollaborationPermission.cs
- MatrixAnimationUsingKeyFrames.cs
- PagePropertiesChangingEventArgs.cs
- SqlError.cs
- LoadRetryHandler.cs
- Point3D.cs
- SqlCrossApplyToCrossJoin.cs
- StateItem.cs
- ApplicationServiceManager.cs
- DBAsyncResult.cs
- TextBoxLine.cs
- BeginEvent.cs
- DecimalAnimation.cs
- BatchStream.cs
- CollaborationHelperFunctions.cs
- ExchangeUtilities.cs
- RubberbandSelector.cs
- ProtectedConfiguration.cs
- KeyFrames.cs
- WindowsFormsSynchronizationContext.cs
- KeyPressEvent.cs
- URI.cs
- XmlSerializerSection.cs
- WindowsTooltip.cs
- StreamReader.cs
- DataControlPagerLinkButton.cs
- AutomationProperties.cs
- ImmutablePropertyDescriptorGridEntry.cs
- UriSectionData.cs
- TextBox.cs
- IRCollection.cs
- HostingEnvironmentException.cs
- WindowsUpDown.cs
- UrlMappingsModule.cs
- WebGetAttribute.cs
- HostingEnvironmentException.cs
- KnownAssemblyEntry.cs
- DataGridSortingEventArgs.cs
- ChineseLunisolarCalendar.cs
- ReadingWritingEntityEventArgs.cs
- CodeMethodReturnStatement.cs
- UrlPath.cs
- SmtpNtlmAuthenticationModule.cs
- ExpressionTextBox.xaml.cs
- TextDecoration.cs
- Random.cs
- ScriptingJsonSerializationSection.cs
- PeerCustomResolverSettings.cs
- AdornerHitTestResult.cs
- BitConverter.cs
- ClusterSafeNativeMethods.cs
- JsonWriterDelegator.cs
- SmiRequestExecutor.cs
- METAHEADER.cs
- FileSystemWatcher.cs
- InputLanguageEventArgs.cs
- MSG.cs
- XsdBuildProvider.cs
- ExceptionHandler.cs
- BookmarkUndoUnit.cs
- PositiveTimeSpanValidatorAttribute.cs
- WorkflowInstance.cs
- CodeVariableDeclarationStatement.cs
- Internal.cs
- Latin1Encoding.cs
- TextElementAutomationPeer.cs
- DataExpression.cs
- SettingsProviderCollection.cs
- Sql8ExpressionRewriter.cs
- MenuAutomationPeer.cs
- WinCategoryAttribute.cs
- Vector3D.cs
- QilLiteral.cs
- ObjectSecurity.cs
- CompositeDataBoundControl.cs
- DataObjectFieldAttribute.cs
- SchemaCompiler.cs
- SamlSubjectStatement.cs
- ZipIOCentralDirectoryBlock.cs
- _ConnectionGroup.cs
- CroppedBitmap.cs
- altserialization.cs
- SimpleWebHandlerParser.cs
- BezierSegment.cs
- ExpressionVisitor.cs
- IBuiltInEvidence.cs
- ButtonBase.cs
- InternalBase.cs
- WebPartHeaderCloseVerb.cs
- BoundsDrawingContextWalker.cs
- WindowsListViewGroup.cs
- HtmlForm.cs
- FontDriver.cs
- MatrixIndependentAnimationStorage.cs
- ZipIOEndOfCentralDirectoryBlock.cs
- LocatorPart.cs
- TempFiles.cs
- controlskin.cs
- CryptoProvider.cs
- DayRenderEvent.cs