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
- EntityProviderServices.cs
- Constraint.cs
- PageStatePersister.cs
- FrameworkTextComposition.cs
- WindowsContainer.cs
- CodeEventReferenceExpression.cs
- WorkflowNamespace.cs
- Boolean.cs
- Pkcs7Recipient.cs
- ReceiveMessageContent.cs
- ToolStripDropDown.cs
- TextElement.cs
- DiscriminatorMap.cs
- Rijndael.cs
- SystemSounds.cs
- WorkingDirectoryEditor.cs
- PartialArray.cs
- XmlDataDocument.cs
- SignatureHelper.cs
- MetadataUtilsSmi.cs
- AuthenticationModuleElementCollection.cs
- XmlSchemaSimpleContent.cs
- XmlToDatasetMap.cs
- AttachedPropertyBrowsableWhenAttributePresentAttribute.cs
- QueryStringParameter.cs
- Mouse.cs
- DataGridViewCellStyleConverter.cs
- CommonDialog.cs
- SoapSchemaMember.cs
- StylusTip.cs
- WebPartConnectionsCancelEventArgs.cs
- StreamInfo.cs
- TransformGroup.cs
- ExternalCalls.cs
- NoneExcludedImageIndexConverter.cs
- WindowsListViewItemStartMenu.cs
- TcpServerChannel.cs
- GetPageCompletedEventArgs.cs
- ScrollChangedEventArgs.cs
- PersonalizationStateInfoCollection.cs
- CompoundFileStorageReference.cs
- FormViewUpdatedEventArgs.cs
- PropertyPath.cs
- PersonalizablePropertyEntry.cs
- Attributes.cs
- DocumentApplicationJournalEntry.cs
- DeferredSelectedIndexReference.cs
- NavigationWindowAutomationPeer.cs
- WindowPattern.cs
- RSAOAEPKeyExchangeDeformatter.cs
- GZipDecoder.cs
- XmlLanguage.cs
- CodeSnippetStatement.cs
- WindowsSpinner.cs
- DataGridColumnHeaderItemAutomationPeer.cs
- UnicastIPAddressInformationCollection.cs
- RadioButton.cs
- Popup.cs
- SamlSecurityToken.cs
- SmiContextFactory.cs
- TraceContextRecord.cs
- cookieexception.cs
- OutputCacheSettings.cs
- AxHost.cs
- ToggleButton.cs
- DrawingAttributes.cs
- CapiSafeHandles.cs
- ToolboxItem.cs
- RuntimeVariablesExpression.cs
- MemoryFailPoint.cs
- BitmapEffectDrawingContextState.cs
- ErrorHandler.cs
- AnnotationAdorner.cs
- __Filters.cs
- FixedDocumentSequencePaginator.cs
- HandleCollector.cs
- StrokeCollectionDefaultValueFactory.cs
- NameValuePermission.cs
- WebConfigurationHostFileChange.cs
- Literal.cs
- StringFunctions.cs
- ParameterBuilder.cs
- CatalogPart.cs
- SpellerError.cs
- ExceptionHandlerDesigner.cs
- DataGridCellsPanel.cs
- InfoCard.cs
- SchemaObjectWriter.cs
- QueryableFilterRepeater.cs
- OneWayChannelFactory.cs
- AsyncInvokeContext.cs
- FunctionCommandText.cs
- DataGridViewTextBoxCell.cs
- TransformerConfigurationWizardBase.cs
- QuinticEase.cs
- TextSelection.cs
- RijndaelCryptoServiceProvider.cs
- MouseActionValueSerializer.cs
- SQLInt16Storage.cs
- XamlFrame.cs