Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / 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
- PasswordDeriveBytes.cs
- LazyInitializer.cs
- ReflectionPermission.cs
- XmlResolver.cs
- HttpCachePolicy.cs
- TextContainerHelper.cs
- ContentPosition.cs
- AtomEntry.cs
- ScopelessEnumAttribute.cs
- ResXBuildProvider.cs
- CodeTypeReference.cs
- GenericWebPart.cs
- HttpInputStream.cs
- Baml2006KeyRecord.cs
- PagesChangedEventArgs.cs
- UserControlBuildProvider.cs
- BaseValidator.cs
- ProcessHostFactoryHelper.cs
- Stylesheet.cs
- PaperSource.cs
- DispatcherTimer.cs
- DataKeyCollection.cs
- WindowsToolbarItemAsMenuItem.cs
- KnownIds.cs
- ColorConvertedBitmap.cs
- Stack.cs
- FontWeights.cs
- TextRunCacheImp.cs
- UshortList2.cs
- RadioButtonRenderer.cs
- graph.cs
- ErrorTableItemStyle.cs
- WindowsGraphicsWrapper.cs
- ConfigurationConverterBase.cs
- WebBodyFormatMessageProperty.cs
- StrokeNodeEnumerator.cs
- DocumentReferenceCollection.cs
- ELinqQueryState.cs
- ConfigurationSettings.cs
- FixedPageProcessor.cs
- XmlSchemaObjectTable.cs
- Margins.cs
- ConfigurationStrings.cs
- Int32Storage.cs
- XamlWriter.cs
- HwndHost.cs
- TextTreeFixupNode.cs
- TabletDeviceInfo.cs
- PageCodeDomTreeGenerator.cs
- ExternalDataExchangeClient.cs
- KnownBoxes.cs
- XmlSchemaType.cs
- TextTreeDeleteContentUndoUnit.cs
- TextRangeProviderWrapper.cs
- GacUtil.cs
- Funcletizer.cs
- XmlSchemaImport.cs
- Main.cs
- Pkcs7Recipient.cs
- SynthesizerStateChangedEventArgs.cs
- sapiproxy.cs
- FastEncoder.cs
- WebConfigurationFileMap.cs
- ipaddressinformationcollection.cs
- DataPagerFieldCollection.cs
- JoinGraph.cs
- CapabilitiesPattern.cs
- ToolBarPanel.cs
- EventSetterHandlerConverter.cs
- GPRECT.cs
- RequestTimeoutManager.cs
- SystemDropShadowChrome.cs
- SqlWorkflowInstanceStore.cs
- Int64AnimationUsingKeyFrames.cs
- SoapIgnoreAttribute.cs
- EmptyEnumerable.cs
- SignatureConfirmations.cs
- InkCanvasFeedbackAdorner.cs
- TargetConverter.cs
- ListItemConverter.cs
- DataGridHeaderBorder.cs
- DataServiceResponse.cs
- TraceUtility.cs
- CapiSymmetricAlgorithm.cs
- ThreadExceptionEvent.cs
- LocatorBase.cs
- XomlCompilerResults.cs
- OciEnlistContext.cs
- ObjectDataSourceDisposingEventArgs.cs
- GenerateTemporaryTargetAssembly.cs
- MenuItemBindingCollection.cs
- RotateTransform3D.cs
- BitConverter.cs
- IFlowDocumentViewer.cs
- SerializationHelper.cs
- MessageProperties.cs
- WinCategoryAttribute.cs
- TransactionChannelListener.cs
- FormViewModeEventArgs.cs
- HttpModuleAction.cs