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
- ConfigurationManagerInternal.cs
- TextBounds.cs
- AsymmetricKeyExchangeFormatter.cs
- DiscoveryDocumentLinksPattern.cs
- WebConvert.cs
- ProjectedSlot.cs
- DataGridSortCommandEventArgs.cs
- PageThemeParser.cs
- UnsafeNativeMethods.cs
- CollectionBuilder.cs
- AssemblyResourceLoader.cs
- ContentOperations.cs
- XsdDataContractExporter.cs
- CssTextWriter.cs
- X509IssuerSerialKeyIdentifierClause.cs
- DebugHandleTracker.cs
- AssemblyBuilderData.cs
- RequestResizeEvent.cs
- ProviderUtil.cs
- List.cs
- SMSvcHost.cs
- SystemWebCachingSectionGroup.cs
- ISAPIWorkerRequest.cs
- ContainerControl.cs
- DataServiceHostWrapper.cs
- TableProvider.cs
- HttpCapabilitiesSectionHandler.cs
- MenuItemBinding.cs
- HostingEnvironmentSection.cs
- UdpDiscoveryEndpoint.cs
- MethodExpression.cs
- ServiceParser.cs
- TimeZone.cs
- MouseGestureValueSerializer.cs
- ProcessModule.cs
- HwndPanningFeedback.cs
- ExpressionBinding.cs
- DefinitionBase.cs
- Mutex.cs
- Processor.cs
- QueryableFilterRepeater.cs
- BmpBitmapEncoder.cs
- ProxyElement.cs
- GridSplitterAutomationPeer.cs
- MatrixStack.cs
- TypeGeneratedEventArgs.cs
- WebPartConnectionsDisconnectVerb.cs
- DependencyPropertyChangedEventArgs.cs
- MessageCredentialType.cs
- RepeaterItem.cs
- DataGridCellsPresenter.cs
- _NestedMultipleAsyncResult.cs
- ReferencedType.cs
- ServiceControllerDesigner.cs
- DataControlField.cs
- _SSPISessionCache.cs
- TransactionFlowOption.cs
- _emptywebproxy.cs
- Polyline.cs
- QuotedPrintableStream.cs
- URLIdentityPermission.cs
- IPCCacheManager.cs
- ServicePointManagerElement.cs
- Typeface.cs
- StickyNoteContentControl.cs
- ValueTypeFixupInfo.cs
- PageStatePersister.cs
- ArglessEventHandlerProxy.cs
- GradientStop.cs
- mongolianshape.cs
- ReferentialConstraint.cs
- MultiDataTrigger.cs
- WSDualHttpSecurityMode.cs
- XsltInput.cs
- DataGridViewBindingCompleteEventArgs.cs
- XmlWhitespace.cs
- RecordConverter.cs
- RenderContext.cs
- ZipIOCentralDirectoryBlock.cs
- JsonFormatGeneratorStatics.cs
- PageClientProxyGenerator.cs
- CompilerState.cs
- MemberAccessException.cs
- InstanceView.cs
- Console.cs
- WorkflowPersistenceContext.cs
- ColumnBinding.cs
- PaginationProgressEventArgs.cs
- ChangeBlockUndoRecord.cs
- RegexStringValidator.cs
- ScriptingWebServicesSectionGroup.cs
- KeyEventArgs.cs
- Cursor.cs
- Group.cs
- OverlappedAsyncResult.cs
- ViewBase.cs
- PropertyEmitter.cs
- LogicalCallContext.cs
- X509AsymmetricSecurityKey.cs
- ProvidersHelper.cs