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
- XmlCountingReader.cs
- DataListItemCollection.cs
- SequenceFullException.cs
- NullableDoubleMinMaxAggregationOperator.cs
- CheckBoxStandardAdapter.cs
- FrameworkObject.cs
- CreateUserWizard.cs
- PartialCachingAttribute.cs
- ComplexTypeEmitter.cs
- SingleStorage.cs
- ZoneButton.cs
- SizeFConverter.cs
- WindowsRegion.cs
- CacheVirtualItemsEvent.cs
- DetailsViewPagerRow.cs
- HttpWebResponse.cs
- TransformerInfoCollection.cs
- PeerResolverElement.cs
- BinaryVersion.cs
- LogSwitch.cs
- DataConnectionHelper.cs
- TableLayoutPanel.cs
- XmlWellformedWriter.cs
- CatalogZone.cs
- RoleManagerEventArgs.cs
- hwndwrapper.cs
- SecurityCriticalDataForSet.cs
- bidPrivateBase.cs
- OrderedDictionaryStateHelper.cs
- DynamicDataRoute.cs
- COMException.cs
- TogglePattern.cs
- CursorConverter.cs
- ScriptingRoleServiceSection.cs
- TextSchema.cs
- Context.cs
- ProfilePropertySettingsCollection.cs
- XmlSchemaSimpleType.cs
- StreamGeometry.cs
- StaticTextPointer.cs
- MetadataArtifactLoaderComposite.cs
- XmlCodeExporter.cs
- MultipartIdentifier.cs
- ErrorRuntimeConfig.cs
- PackageRelationshipCollection.cs
- IERequestCache.cs
- SqlDataSourceTableQuery.cs
- TitleStyle.cs
- AuthenticationSection.cs
- PageAsyncTaskManager.cs
- MenuItem.cs
- AmbiguousMatchException.cs
- RTLAwareMessageBox.cs
- precedingsibling.cs
- SamlAuthenticationClaimResource.cs
- Odbc32.cs
- ActiveXHost.cs
- DataServiceQueryOfT.cs
- unitconverter.cs
- CursorEditor.cs
- XsltCompileContext.cs
- TemplatedWizardStep.cs
- AppDomainAttributes.cs
- BitmapScalingModeValidation.cs
- MailAddressCollection.cs
- Range.cs
- RawAppCommandInputReport.cs
- BufferedWebEventProvider.cs
- Property.cs
- ReliabilityContractAttribute.cs
- ScriptReferenceBase.cs
- Vector3DConverter.cs
- AsyncDataRequest.cs
- CFStream.cs
- Throw.cs
- IsolatedStorageFilePermission.cs
- NetMsmqBindingCollectionElement.cs
- QueuePropertyVariants.cs
- OptimisticConcurrencyException.cs
- ChildTable.cs
- DocumentCollection.cs
- PageCodeDomTreeGenerator.cs
- ListViewPagedDataSource.cs
- InputLanguage.cs
- ScriptingSectionGroup.cs
- SettingsPropertyValueCollection.cs
- Rectangle.cs
- Slider.cs
- XmlQualifiedNameTest.cs
- PeerToPeerException.cs
- SourceFilter.cs
- NullableLongAverageAggregationOperator.cs
- MouseActionConverter.cs
- SocketManager.cs
- MemberHolder.cs
- BufferedMessageData.cs
- XslException.cs
- ActivityValidationServices.cs
- MatchNoneMessageFilter.cs
- SimpleWebHandlerParser.cs