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
- ModuleConfigurationInfo.cs
- ReachSerializationCacheItems.cs
- DrawingAttributesDefaultValueFactory.cs
- SqlServices.cs
- SqlTransaction.cs
- HttpContextServiceHost.cs
- CallInfo.cs
- ItemDragEvent.cs
- RecommendedAsConfigurableAttribute.cs
- StackSpiller.Temps.cs
- StrongName.cs
- ServiceDocumentFormatter.cs
- AllMembershipCondition.cs
- DocumentPageViewAutomationPeer.cs
- XPathQilFactory.cs
- ToolboxItemAttribute.cs
- SafeThemeHandle.cs
- ResourceProperty.cs
- ChameleonKey.cs
- DbParameterCollection.cs
- IdentityNotMappedException.cs
- ExpressionBuilderCollection.cs
- Timer.cs
- BaseCodeDomTreeGenerator.cs
- SortQuery.cs
- FileNotFoundException.cs
- WebResponse.cs
- DataGridLength.cs
- PersistenceContextEnlistment.cs
- Query.cs
- SelectionListDesigner.cs
- AspNetHostingPermission.cs
- EditorZoneBase.cs
- XmlException.cs
- Verify.cs
- ResourceSetExpression.cs
- WindowsProgressbar.cs
- BaseUriHelper.cs
- TrustManager.cs
- WebControlsSection.cs
- SignatureDescription.cs
- ServiceParser.cs
- WebEventCodes.cs
- ContainsRowNumberChecker.cs
- SslStream.cs
- ConsumerConnectionPointCollection.cs
- XmlSchemaExporter.cs
- InvalidProgramException.cs
- ExceptionHandlers.cs
- MappingModelBuildProvider.cs
- InvalidAsynchronousStateException.cs
- TimeSpanStorage.cs
- CurrentTimeZone.cs
- DataTableMappingCollection.cs
- SectionVisual.cs
- EventHandlerService.cs
- SystemIcons.cs
- SamlDelegatingWriter.cs
- CollectionBuilder.cs
- CSharpCodeProvider.cs
- XmlSchemaExternal.cs
- CodeChecksumPragma.cs
- smtppermission.cs
- XsltException.cs
- HtmlSelect.cs
- BitSet.cs
- PointHitTestResult.cs
- TerminateWorkflow.cs
- SecurityValidationBehavior.cs
- RepeaterItemCollection.cs
- ManagementClass.cs
- NetMsmqBindingElement.cs
- EntityDataSourceChangingEventArgs.cs
- HierarchicalDataBoundControlAdapter.cs
- SendMailErrorEventArgs.cs
- XmlNodeChangedEventArgs.cs
- ProfilePropertySettings.cs
- DataPagerFieldCollection.cs
- InputDevice.cs
- ContentValidator.cs
- storagemappingitemcollection.viewdictionary.cs
- DrawingVisual.cs
- DictionaryCustomTypeDescriptor.cs
- ProcessHostConfigUtils.cs
- InstanceKeyCompleteException.cs
- CompositeTypefaceMetrics.cs
- AuthenticationServiceManager.cs
- WebPartsSection.cs
- ScrollEventArgs.cs
- TextRangeEditTables.cs
- TransactionFormatter.cs
- RichTextBoxDesigner.cs
- DataColumnMapping.cs
- WindowsProgressbar.cs
- SymLanguageType.cs
- TimeIntervalCollection.cs
- EditorPartCollection.cs
- XMLUtil.cs
- DPAPIProtectedConfigurationProvider.cs
- DeploymentSection.cs