Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- WorkflowMarkupSerializationException.cs
- OdbcEnvironment.cs
- RC2.cs
- ContractMethodInfo.cs
- ListControlConvertEventArgs.cs
- Encoder.cs
- NativeConfigurationLoader.cs
- SessionMode.cs
- HttpProfileBase.cs
- DataBindingCollectionConverter.cs
- MenuItemBindingCollection.cs
- wgx_sdk_version.cs
- MethodRental.cs
- ObsoleteAttribute.cs
- Formatter.cs
- StateManagedCollection.cs
- UnitySerializationHolder.cs
- NativeCppClassAttribute.cs
- GraphicsState.cs
- XPathNavigatorReader.cs
- SqlCommand.cs
- IsolatedStorage.cs
- HttpsChannelFactory.cs
- DictationGrammar.cs
- TagMapInfo.cs
- ColorAnimationBase.cs
- TreeIterators.cs
- M3DUtil.cs
- TableLayoutRowStyleCollection.cs
- ClosableStream.cs
- Utils.cs
- AmbientProperties.cs
- DataGridViewRowHeightInfoPushedEventArgs.cs
- TraceContext.cs
- _CommandStream.cs
- RefreshEventArgs.cs
- BufferBuilder.cs
- FixedSchema.cs
- messageonlyhwndwrapper.cs
- DataObject.cs
- MachineKeyConverter.cs
- DocumentPaginator.cs
- WebServiceClientProxyGenerator.cs
- CodeGenerator.cs
- StringArrayConverter.cs
- HttpHeaderCollection.cs
- PassportAuthenticationEventArgs.cs
- CustomLineCap.cs
- ObjectManager.cs
- HttpResponse.cs
- AdvancedBindingPropertyDescriptor.cs
- BindingExpressionBase.cs
- precedingsibling.cs
- BinaryObjectInfo.cs
- FacetEnabledSchemaElement.cs
- GridView.cs
- x509utils.cs
- GroupItemAutomationPeer.cs
- DispatcherProcessingDisabled.cs
- ArrayMergeHelper.cs
- MailAddress.cs
- WindowsListBox.cs
- ApplicationContext.cs
- ObjectTokenCategory.cs
- PopOutPanel.cs
- MergeFilterQuery.cs
- Table.cs
- ContentValidator.cs
- SiteMapHierarchicalDataSourceView.cs
- _SafeNetHandles.cs
- UriSchemeKeyedCollection.cs
- ResourcesChangeInfo.cs
- httpstaticobjectscollection.cs
- DynamicRendererThreadManager.cs
- MarkupObject.cs
- ListMarkerLine.cs
- SemaphoreFullException.cs
- StyleCollectionEditor.cs
- Int32.cs
- RadialGradientBrush.cs
- LayoutUtils.cs
- FixedSchema.cs
- OleDbWrapper.cs
- XmlSiteMapProvider.cs
- PasswordDeriveBytes.cs
- SID.cs
- TraceContextEventArgs.cs
- SID.cs
- ThaiBuddhistCalendar.cs
- SoapRpcMethodAttribute.cs
- SetterTriggerConditionValueConverter.cs
- OdbcConnection.cs
- TreeViewCancelEvent.cs
- ColumnResult.cs
- ReflectionUtil.cs
- GeometryCombineModeValidation.cs
- wmiprovider.cs
- ScriptDescriptor.cs
- LinqDataSourceStatusEventArgs.cs
- AppDomainShutdownMonitor.cs