Win7PlusCoreSystem
This commit is contained in:
parent
93a0a99784
commit
47f0699235
|
|
@ -69,6 +69,7 @@ namespace Microsoft.Win32.SafeHandles
|
||||||
public static SafeLibraryHandle Open(string filename)
|
public static SafeLibraryHandle Open(string filename)
|
||||||
{
|
{
|
||||||
SafeLibraryHandle handle = UnsafeNativeMethods.LoadLibrary(filename);
|
SafeLibraryHandle handle = UnsafeNativeMethods.LoadLibrary(filename);
|
||||||
|
|
||||||
if (handle == null || handle.IsInvalid)
|
if (handle == null || handle.IsInvalid)
|
||||||
{
|
{
|
||||||
UnsafeNativeMethods.ThrowExceptionForLastWin32Error();
|
UnsafeNativeMethods.ThrowExceptionForLastWin32Error();
|
||||||
|
|
@ -85,34 +86,59 @@ namespace Microsoft.Win32.SafeHandles
|
||||||
[SuppressUnmanagedCodeSecurity]
|
[SuppressUnmanagedCodeSecurity]
|
||||||
private static class UnsafeNativeMethods
|
private static class UnsafeNativeMethods
|
||||||
{
|
{
|
||||||
|
#if ASPNETCORE50
|
||||||
|
private const string api_ms_win_core_libraryloader_LIB = "api-ms-win-core-libraryloader-l1-1-0.dll";
|
||||||
|
#else
|
||||||
private const string KERNEL32_LIB = "kernel32.dll";
|
private const string KERNEL32_LIB = "kernel32.dll";
|
||||||
|
#endif
|
||||||
// http://msdn.microsoft.com/en-us/library/ms683152(v=vs.85).aspx
|
// http://msdn.microsoft.com/en-us/library/ms683152(v=vs.85).aspx
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
#if NET45
|
#if ASPNETCORE50
|
||||||
|
[DllImport(api_ms_win_core_libraryloader_LIB, ExactSpelling = true, SetLastError = true)]
|
||||||
|
#else
|
||||||
|
[DllImport(KERNEL32_LIB, CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode)]
|
||||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||||
#endif
|
#endif
|
||||||
[DllImport(KERNEL32_LIB, CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode)]
|
public static extern bool FreeLibrary(IntPtr hModule);
|
||||||
internal static extern bool FreeLibrary(IntPtr hModule);
|
|
||||||
|
|
||||||
// http://msdn.microsoft.com/en-us/library/ms683200(v=vs.85).aspx
|
// http://msdn.microsoft.com/en-us/library/ms683200(v=vs.85).aspx
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
|
#if ASPNETCORE50
|
||||||
|
[DllImport(api_ms_win_core_libraryloader_LIB, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
||||||
|
#else
|
||||||
[DllImport(KERNEL32_LIB, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
[DllImport(KERNEL32_LIB, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
||||||
|
#endif
|
||||||
internal static extern bool GetModuleHandleEx(
|
internal static extern bool GetModuleHandleEx(
|
||||||
[In] uint dwFlags,
|
[In] uint dwFlags,
|
||||||
[In] SafeLibraryHandle lpModuleName, // can point to a location within the module if GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS is set
|
[In] SafeLibraryHandle lpModuleName, // can point to a location within the module if GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS is set
|
||||||
[Out] out IntPtr phModule);
|
[Out] out IntPtr phModule);
|
||||||
|
|
||||||
|
#if ASPNETCORE50
|
||||||
|
[DllImport(api_ms_win_core_libraryloader_LIB, CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true, BestFitMapping = false, ThrowOnUnmappableChar = true)]
|
||||||
|
#else
|
||||||
// http://msdn.microsoft.com/en-us/library/ms683212(v=vs.85).aspx
|
// http://msdn.microsoft.com/en-us/library/ms683212(v=vs.85).aspx
|
||||||
[DllImport(KERNEL32_LIB, CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true, BestFitMapping = false, ThrowOnUnmappableChar = true)]
|
[DllImport(KERNEL32_LIB, CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true, BestFitMapping = false, ThrowOnUnmappableChar = true)]
|
||||||
|
#endif
|
||||||
|
|
||||||
internal static extern IntPtr GetProcAddress(
|
internal static extern IntPtr GetProcAddress(
|
||||||
[In] SafeLibraryHandle hModule,
|
[In] SafeLibraryHandle hModule,
|
||||||
[In, MarshalAs(UnmanagedType.LPStr)] string lpProcName);
|
[In, MarshalAs(UnmanagedType.LPStr)] string lpProcName);
|
||||||
|
|
||||||
|
#if ASPNETCORE50
|
||||||
|
[DllImport(api_ms_win_core_libraryloader_LIB, CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode, SetLastError = true)]
|
||||||
|
internal static extern SafeLibraryHandle LoadLibraryExW([In,MarshalAs(UnmanagedType.LPWStr)] string lpFileName, IntPtr hFile, uint dwFlags);
|
||||||
|
|
||||||
|
internal static SafeLibraryHandle LoadLibrary(string lpFileName)
|
||||||
|
{
|
||||||
|
return LoadLibraryExW(lpFileName, IntPtr.Zero, 0);
|
||||||
|
}
|
||||||
|
#else
|
||||||
// http://msdn.microsoft.com/en-us/library/ms684175(v=vs.85).aspx
|
// http://msdn.microsoft.com/en-us/library/ms684175(v=vs.85).aspx
|
||||||
[DllImport(KERNEL32_LIB, CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode, SetLastError = true)]
|
[DllImport(KERNEL32_LIB, CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode, SetLastError = true)]
|
||||||
internal static extern SafeLibraryHandle LoadLibrary(
|
internal static extern SafeLibraryHandle LoadLibrary(
|
||||||
[In, MarshalAs(UnmanagedType.LPWStr)]string lpFileName);
|
[In, MarshalAs(UnmanagedType.LPWStr)]string lpFileName);
|
||||||
|
#endif
|
||||||
|
|
||||||
internal static void ThrowExceptionForLastWin32Error()
|
internal static void ThrowExceptionForLastWin32Error()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,11 @@ namespace Microsoft.AspNet.Security.DataProtection
|
||||||
{
|
{
|
||||||
private const string BCRYPT_LIB = "bcrypt.dll";
|
private const string BCRYPT_LIB = "bcrypt.dll";
|
||||||
private const string CRYPT32_LIB = "crypt32.dll";
|
private const string CRYPT32_LIB = "crypt32.dll";
|
||||||
|
private const string NTDLL_LIB = "ntdll.dll";
|
||||||
|
|
||||||
|
#if !ASPNETCORE50
|
||||||
private const string KERNEL32_LIB = "kernel32.dll";
|
private const string KERNEL32_LIB = "kernel32.dll";
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* BCRYPT.DLL
|
* BCRYPT.DLL
|
||||||
|
|
@ -199,13 +203,16 @@ namespace Microsoft.AspNet.Security.DataProtection
|
||||||
[In] uint cbData,
|
[In] uint cbData,
|
||||||
[In] uint dwFlags);
|
[In] uint dwFlags);
|
||||||
|
|
||||||
/*
|
#if ASPNETCORE50
|
||||||
* KERNEL32.DLL
|
[DllImport(NTDLL_LIB)]
|
||||||
*/
|
internal static extern void RtlZeroMemory(
|
||||||
|
[In] IntPtr Destination,
|
||||||
|
[In] UIntPtr /* SIZE_T */ Length);
|
||||||
|
#else
|
||||||
[DllImport(KERNEL32_LIB, CallingConvention = CallingConvention.Winapi)]
|
[DllImport(KERNEL32_LIB, CallingConvention = CallingConvention.Winapi)]
|
||||||
internal static extern void RtlZeroMemory(
|
internal static extern void RtlZeroMemory(
|
||||||
[In] IntPtr Destination,
|
[In] IntPtr Destination,
|
||||||
[In] UIntPtr /* SIZE_T */ Length);
|
[In] UIntPtr /* SIZE_T */ Length);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue