Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / 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
- MonitorWrapper.cs
- WebDisplayNameAttribute.cs
- LazyInitializer.cs
- ElementAction.cs
- CaseExpr.cs
- WinHttpWebProxyFinder.cs
- mediapermission.cs
- StructuralObject.cs
- OleDbError.cs
- SendingRequestEventArgs.cs
- ToggleButton.cs
- XmlDomTextWriter.cs
- ComNativeDescriptor.cs
- IndentedWriter.cs
- LinqToSqlWrapper.cs
- GrammarBuilderWildcard.cs
- HtmlInputHidden.cs
- DataGridAddNewRow.cs
- AuthenticationService.cs
- SplitterCancelEvent.cs
- Pkcs7Signer.cs
- ComponentSerializationService.cs
- DataSourceView.cs
- ListItemParagraph.cs
- ZipIOLocalFileHeader.cs
- WebPartCancelEventArgs.cs
- PropertyTabChangedEvent.cs
- RawStylusSystemGestureInputReport.cs
- ServiceMetadataContractBehavior.cs
- BitmapEffectInputConnector.cs
- ResXFileRef.cs
- XPathDocumentBuilder.cs
- PathFigure.cs
- Simplifier.cs
- PrivateFontCollection.cs
- EventBuilder.cs
- MimeMapping.cs
- StreamWriter.cs
- FlowchartDesignerCommands.cs
- TemplateBuilder.cs
- Help.cs
- ToolStripTextBox.cs
- MailMessage.cs
- DbProviderSpecificTypePropertyAttribute.cs
- SequenceRangeCollection.cs
- ObjectDataSourceStatusEventArgs.cs
- UserControlDesigner.cs
- TableItemPatternIdentifiers.cs
- ApplicationCommands.cs
- ApplicationFileParser.cs
- Control.cs
- ControlBindingsCollection.cs
- Merger.cs
- SafeUserTokenHandle.cs
- KnownTypeHelper.cs
- NavigationProgressEventArgs.cs
- RSATokenProvider.cs
- ExtenderProvidedPropertyAttribute.cs
- AppearanceEditorPart.cs
- ContextMenuStripGroup.cs
- xamlnodes.cs
- LayoutEvent.cs
- ResourceExpressionBuilder.cs
- Rotation3D.cs
- IfJoinedCondition.cs
- SoapConverter.cs
- DocumentManager.cs
- validation.cs
- FormatException.cs
- FunctionNode.cs
- PeerNameRegistration.cs
- RealProxy.cs
- GlyphRunDrawing.cs
- InlineCollection.cs
- DatePickerTextBox.cs
- PropertyIdentifier.cs
- KeyValueConfigurationElement.cs
- GeneralTransform3DTo2D.cs
- InputDevice.cs
- WebPartAddingEventArgs.cs
- InternalUserCancelledException.cs
- StringUtil.cs
- Cloud.cs
- SystemPens.cs
- TypeToken.cs
- ResourcesGenerator.cs
- WindowHideOrCloseTracker.cs
- ConfigurationStrings.cs
- DataGridCaption.cs
- Update.cs
- Fault.cs
- WeakHashtable.cs
- LineServices.cs
- SettingsPropertyValue.cs
- BitmapEffectDrawingContent.cs
- DoubleStorage.cs
- CompositeControl.cs
- DataGridCaption.cs
- InProcStateClientManager.cs
- CapabilitiesSection.cs