SafeNativeMethods.cs source code in C# .NET

Source code for the .NET framework in C#



/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / System.ServiceModel.Activation / System / ServiceModel / Activation / Interop / SafeNativeMethods.cs / 1305376 / SafeNativeMethods.cs

// Copyright (c) Microsoft Corporation.  All rights reserved.

namespace System.ServiceModel.Activation.Interop 
    using System; 
    using System.Security; 
    using System.Runtime.InteropServices;
    using System.Security.Principal; 
    using System.Runtime.Versioning;
    using System.Runtime;

    static class SafeNativeMethods
        public const int ERROR_NO_TOKEN = 1008; 

        const string ADVAPI32 = "advapi32.dll"; 
        const string KERNEL32 = "kernel32.dll";

        [DllImport(ADVAPI32, SetLastError = true, EntryPoint = "OpenThreadToken")]
        static extern bool OpenThreadTokenCritical(
            [In] IntPtr ThreadHandle, 
            [In] TokenAccessLevels DesiredAccess, 
            [In] bool OpenAsSelf,
            [Out] out SafeCloseHandleCritical TokenHandle); 

        [DllImport(KERNEL32, SetLastError = true)]
        static extern IntPtr GetCurrentThread(); 

        [Fx.Tag.SecurityNote(Critical = "Calls two safe native methods: GetCurrentThread and OpenThreadToken." + 
            "Marshal.GetLastWin32Error captures current thread token in a SecurityCritical field.")] 
        internal static bool OpenCurrentThreadTokenCritical(TokenAccessLevels desiredAccess, bool openAsSelf, out SafeCloseHandleCritical tokenHandle, out int error) 
            bool result = OpenThreadTokenCritical(GetCurrentThread(), desiredAccess, openAsSelf, out tokenHandle);
            error = Marshal.GetLastWin32Error();
            return result; 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.


Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK