Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / UIAutomation / Win32Providers / MS / Internal / AutomationProxies / SafeProcessHandle.cs / 1 / SafeProcessHandle.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: // // History: // 10/04/2003 : [....] Created //--------------------------------------------------------------------------- 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.AutomationProxies { 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(IntPtr hwnd) : base(true) { uint processId; if (hwnd == IntPtr.Zero) { processId = UnsafeNativeMethods.GetCurrentProcessId(); } else { // Get process id... Misc.GetWindowThreadProcessId(hwnd, out processId); } // handle might be used to query for Wow64 information (_QUERY_), or to do cross-process allocs (VM_*) SetHandle(Misc.OpenProcess(NativeMethods.PROCESS_QUERY_INFORMATION | NativeMethods.PROCESS_VM_OPERATION | NativeMethods.PROCESS_VM_READ | NativeMethods.PROCESS_VM_WRITE, false, processId, hwnd)); } // Uncomment this if & only if we need a constructor // that takes a handle from external code //internal SafeProcessHandle(IntPtr preexistingHandle, bool ownsHandle) : base(ownsHandle) //{ // SetHandle(preexistingHandle); //} // 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 //--------------------------------------------------------------------------- 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.AutomationProxies { 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(IntPtr hwnd) : base(true) { uint processId; if (hwnd == IntPtr.Zero) { processId = UnsafeNativeMethods.GetCurrentProcessId(); } else { // Get process id... Misc.GetWindowThreadProcessId(hwnd, out processId); } // handle might be used to query for Wow64 information (_QUERY_), or to do cross-process allocs (VM_*) SetHandle(Misc.OpenProcess(NativeMethods.PROCESS_QUERY_INFORMATION | NativeMethods.PROCESS_VM_OPERATION | NativeMethods.PROCESS_VM_READ | NativeMethods.PROCESS_VM_WRITE, false, processId, hwnd)); } // Uncomment this if & only if we need a constructor // that takes a handle from external code //internal SafeProcessHandle(IntPtr preexistingHandle, bool ownsHandle) : base(ownsHandle) //{ // SetHandle(preexistingHandle); //} // 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
- SelectedDatesCollection.cs
- EventMap.cs
- RangeValuePattern.cs
- XPathDocument.cs
- ApplicationException.cs
- AutomationIdentifierGuids.cs
- TextLine.cs
- HierarchicalDataSourceControl.cs
- ComponentChangedEvent.cs
- ReferenceEqualityComparer.cs
- ToolStripArrowRenderEventArgs.cs
- PolicyVersion.cs
- XmlILModule.cs
- SignatureDescription.cs
- LoginCancelEventArgs.cs
- BrowserCapabilitiesFactory.cs
- SystemNetworkInterface.cs
- XPathItem.cs
- Invariant.cs
- WebPageTraceListener.cs
- WebZone.cs
- SqlCacheDependencySection.cs
- LineServicesCallbacks.cs
- ItemCheckedEvent.cs
- WebBrowserNavigatedEventHandler.cs
- SimpleFileLog.cs
- PageContent.cs
- SqlDataSourceQueryEditor.cs
- Ipv6Element.cs
- DependencyPropertyValueSerializer.cs
- TimelineCollection.cs
- BinaryObjectReader.cs
- XsltLoader.cs
- CodeGen.cs
- FirstMatchCodeGroup.cs
- ClientSettingsSection.cs
- TreeViewItem.cs
- sqlinternaltransaction.cs
- CounterCreationDataCollection.cs
- DataGridRowHeader.cs
- TableCellCollection.cs
- NavigationWindow.cs
- FunctionQuery.cs
- WmlValidationSummaryAdapter.cs
- _FixedSizeReader.cs
- BuildProviderAppliesToAttribute.cs
- AllowedAudienceUriElement.cs
- StyleXamlParser.cs
- Variant.cs
- MergeLocalizationDirectives.cs
- HMACSHA512.cs
- Win32Native.cs
- HtmlInputText.cs
- PaperSize.cs
- SqlLiftIndependentRowExpressions.cs
- ErrorRuntimeConfig.cs
- PropertyGridEditorPart.cs
- SQLSingle.cs
- IxmlLineInfo.cs
- OracleColumn.cs
- WinInet.cs
- SmtpMail.cs
- EntityReference.cs
- SocketElement.cs
- ClientConfigPaths.cs
- ResourcePool.cs
- SqlExpressionNullability.cs
- InstanceLockLostException.cs
- HandleTable.cs
- EFTableProvider.cs
- IdentityNotMappedException.cs
- CodeSnippetTypeMember.cs
- ReliableDuplexSessionChannel.cs
- UpDownBase.cs
- PlaceHolder.cs
- AnimatedTypeHelpers.cs
- TextEditorParagraphs.cs
- SoapInteropTypes.cs
- ScrollContentPresenter.cs
- SessionState.cs
- MsmqEncryptionAlgorithm.cs
- BaseParser.cs
- ConfigXmlComment.cs
- TrackingStringDictionary.cs
- AsyncOperation.cs
- PermissionRequestEvidence.cs
- ExceptionUtility.cs
- CheckBox.cs
- ValidationResults.cs
- _ContextAwareResult.cs
- BaseCollection.cs
- XslAst.cs
- KeyValueConfigurationElement.cs
- EdmConstants.cs
- ContextBase.cs
- CodeMemberMethod.cs
- ToolboxItemImageConverter.cs
- CryptoProvider.cs
- SHA1.cs
- ItemCollection.cs