C # is not recognizing SafeTokenHandle

I have a compilation error with C #

using System; using System.Collections.Generic; using System.ComponentModel; using System.Windows.Forms; using System.Security.Principal; using System.Security.Permissions; using System.Runtime.ConstrainedExecution; using System.Runtime.InteropServices; using Microsoft.Win32.SafeHandles; [DllImport("advapi32.dll", SetLastError = true,CharSet = CharSet.Unicode)] public static extern bool ***LogonUser***(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, out ***SafeTokenHandle*** phToken); 

The word in the sign * (LogonUser and SafeTokenHandle). My C # compiler cannot compile due to an unknown type. I am developing Visual Studio 2012, Windows 64, Framework 4.0.

Please, help.

+4
source share
2 answers

because these structures are not defined in your project.

from what I know, you want the method to be as follows:

 [DllImport("advapi32.dll", SetLastError=true)] public static extern bool LogonUser( string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, out IntPtr phToken ); 

here is an explanation of the function

0
source

SafeTokenHandle not part of the .Net infrastructure. I assume your code is somewhat related to this article , so you are missing a definition:

 public sealed class SafeTokenHandle : SafeHandleZeroOrMinusOneIsInvalid { private SafeTokenHandle() : base(true) { } [DllImport("kernel32.dll")] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [SuppressUnmanagedCodeSecurity] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool CloseHandle(IntPtr handle); protected override bool ReleaseHandle() { return CloseHandle(handle); } } 
+8
source

Source: https://habr.com/ru/post/1491332/


All Articles