Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / UIAutomation / UIAutomationClient / MS / Internal / Automation / SafeProcessHandle.cs / 1 / 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
- WebResourceUtil.cs
- TransactionManager.cs
- XXXOnTypeBuilderInstantiation.cs
- CornerRadiusConverter.cs
- TypeUtil.cs
- RpcAsyncResult.cs
- UnsafeNativeMethods.cs
- TableItemStyle.cs
- HotCommands.cs
- ListSourceHelper.cs
- RequestFactory.cs
- RawKeyboardInputReport.cs
- ProjectedSlot.cs
- DateTimeValueSerializer.cs
- DataSourceView.cs
- UnsafeNativeMethods.cs
- OleDbFactory.cs
- ImplicitInputBrush.cs
- TextRangeAdaptor.cs
- ExceptionRoutedEventArgs.cs
- Page.cs
- TypeLibConverter.cs
- VirtualStackFrame.cs
- RegexReplacement.cs
- ContentType.cs
- MenuTracker.cs
- ExtenderProvidedPropertyAttribute.cs
- InputLangChangeRequestEvent.cs
- TcpSocketManager.cs
- InlineUIContainer.cs
- XXXOnTypeBuilderInstantiation.cs
- ButtonField.cs
- GeneralTransformCollection.cs
- ListCollectionView.cs
- ProjectionPath.cs
- IUnknownConstantAttribute.cs
- ParameterDataSourceExpression.cs
- DocumentViewerBaseAutomationPeer.cs
- RawStylusActions.cs
- QilPatternVisitor.cs
- AbstractDataSvcMapFileLoader.cs
- PresentationTraceSources.cs
- CollaborationHelperFunctions.cs
- FormsAuthenticationTicket.cs
- GregorianCalendarHelper.cs
- SignalGate.cs
- StorageFunctionMapping.cs
- XComponentModel.cs
- ConnectionsZone.cs
- CategoryAttribute.cs
- QilReplaceVisitor.cs
- securitycriticaldataformultiplegetandset.cs
- FreezableDefaultValueFactory.cs
- HostExecutionContextManager.cs
- CharacterBuffer.cs
- COM2ComponentEditor.cs
- ClipboardData.cs
- DrawListViewColumnHeaderEventArgs.cs
- MenuTracker.cs
- PageThemeParser.cs
- ReadOnlyCollection.cs
- KeyBinding.cs
- NegationPusher.cs
- GridEntryCollection.cs
- EDesignUtil.cs
- WindowAutomationPeer.cs
- TextEffectCollection.cs
- ListViewUpdateEventArgs.cs
- MarkerProperties.cs
- FileDialogPermission.cs
- PropertyToken.cs
- TypedDataSourceCodeGenerator.cs
- ToolStripSplitStackLayout.cs
- StackBuilderSink.cs
- XMLSchema.cs
- DocumentGridContextMenu.cs
- ToolStripScrollButton.cs
- AssemblyHelper.cs
- ValueExpressions.cs
- ComponentCollection.cs
- InputLanguageEventArgs.cs
- EventWaitHandleSecurity.cs
- WithStatement.cs
- IISMapPath.cs
- InvalidComObjectException.cs
- ListChangedEventArgs.cs
- VectorCollectionValueSerializer.cs
- SqlException.cs
- CultureTable.cs
- FloaterBaseParagraph.cs
- AndMessageFilter.cs
- SecurityCriticalDataForSet.cs
- Expressions.cs
- autovalidator.cs
- ActivityExecutorOperation.cs
- CustomWebEventKey.cs
- DataGridViewRowStateChangedEventArgs.cs
- ZipIOExtraFieldElement.cs
- StylusLogic.cs
- KeyFrames.cs