提交 f2e4ee37 编写于 作者: J John Chen (CLR)

Replace API Set with Win32 DLL in tests

API Sets are not available on Windows 7, thus tests need to
import from Win32 DLL to run successfully on Windows 7.
Resolves issue dotnet/corefx#14728.


Commit migrated from https://github.com/dotnet/corefx/commit/21296d01c360e5febf4f9d7c501158cf740c604c
上级 5078ee16
......@@ -16,7 +16,7 @@ public static partial class Win32ExceptionTestType
private const int ERROR_INSUFFICIENT_BUFFER = 0x7A;
private const int FirstPassBufferSize = 256;
[DllImport("api-ms-win-core-localization-l1-2-0.dll", CharSet = CharSet.Unicode, EntryPoint = "FormatMessageW", SetLastError = true, BestFitMapping = true)]
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "FormatMessageW", SetLastError = true, BestFitMapping = true)]
private static extern int FormatMessage(
int dwFlags,
IntPtr lpSource_mustBeNull,
......
......@@ -52,10 +52,10 @@ public struct SID_AND_ATTRIBUTES
public int Attributes;
}
[DllImport("api-ms-win-core-memory-l1-1-1.dll")]
[DllImport("kernel32.dll")]
public static extern bool GetProcessWorkingSetSizeEx(SafeProcessHandle hProcess, out IntPtr lpMinimumWorkingSetSize, out IntPtr lpMaximumWorkingSetSize, out uint flags);
[DllImport("api-ms-win-core-processthreads-l1-1-0.dll")]
[DllImport("kernel32.dll")]
internal static extern int GetCurrentProcessId();
[DllImport("libc")]
......@@ -64,22 +64,22 @@ public struct SID_AND_ATTRIBUTES
[DllImport("libc")]
internal static extern int getsid(int pid);
[DllImport("api-ms-win-core-processthreads-l1-1-0.dll")]
[DllImport("kernel32.dll")]
internal static extern bool ProcessIdToSessionId(uint dwProcessId, out uint pSessionId);
[DllImport("api-ms-win-core-processthreads-l1-1-0.dll")]
[DllImport("kernel32.dll")]
public static extern int GetProcessId(SafeProcessHandle nativeHandle);
[DllImport("api-ms-win-core-console-l1-1-0.dll")]
[DllImport("kernel32.dll")]
internal extern static int GetConsoleCP();
[DllImport("api-ms-win-core-console-l1-1-0.dll")]
[DllImport("kernel32.dll")]
internal extern static int GetConsoleOutputCP();
[DllImport("api-ms-win-core-console-l1-1-0.dll")]
[DllImport("kernel32.dll")]
internal extern static int SetConsoleCP(int codePage);
[DllImport("api-ms-win-core-console-l1-1-0.dll")]
[DllImport("kernel32.dll")]
internal extern static int SetConsoleOutputCP(int codePage);
[DllImport("netapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
......
......@@ -500,25 +500,25 @@ private int GetLocaleInfoAsInt(CultureInfo ci, uint lcType)
internal const int CAL_PERSIAN = 22;
internal const int CAL_UMALQURA = 23;
[DllImport("api-ms-win-core-localization-l1-2-0.dll", CharSet = CharSet.Unicode)]
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
internal extern static int GetLocaleInfoEx(string lpLocaleName, uint LCType, StringBuilder data, int cchData);
[DllImport("api-ms-win-core-localization-l1-2-0.dll", CharSet = CharSet.Unicode)]
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
internal extern static int GetLocaleInfoEx(string lpLocaleName, uint LCType, ref int data, int cchData);
[DllImport("api-ms-win-core-localization-l1-2-1.dll", CharSet = CharSet.Unicode)]
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
internal extern static bool EnumSystemLocalesEx(EnumLocalesProcEx lpLocaleEnumProcEx, uint dwFlags, IntPtr lParam, IntPtr reserved);
[DllImport("api-ms-win-core-localization-l1-2-0.dll", CharSet = CharSet.Unicode)]
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
internal extern static int GetCalendarInfoEx(string lpLocaleName, int Calendar, IntPtr lpReserved, uint CalType, StringBuilder lpCalData, int cchData, IntPtr lpValue);
[DllImport("api-ms-win-core-localization-l1-2-1.dll", CharSet = CharSet.Unicode)]
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
internal extern static int GetCalendarInfoEx(string lpLocaleName, int Calendar, IntPtr lpReserved, uint CalType, StringBuilder lpCalData, int cchData, ref uint lpValue);
[DllImport("api-ms-win-core-localization-l2-1-0.dll", CharSet = CharSet.Unicode)]
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
internal extern static bool EnumCalendarInfoExEx(EnumCalendarInfoProcExEx pCalInfoEnumProcExEx, string lpLocaleName, uint Calendar, string lpReserved, uint CalType, IntPtr lParam);
[DllImport("api-ms-win-core-localization-l2-1-0.dll", CharSet = CharSet.Unicode)]
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
internal extern static bool EnumTimeFormatsEx(EnumTimeFormatsProcEx lpTimeFmtEnumProcEx, string lpLocaleName, uint dwFlags, IntPtr lParam);
}
}
......@@ -206,16 +206,16 @@ public void VolumeLabelOnNetworkOrCdRom_Throws()
}
}
[DllImport("api-ms-win-core-file-l1-1-0.dll", SetLastError = true)]
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern int GetLogicalDrives();
[DllImport("api-ms-win-core-file-l1-1-0.dll", EntryPoint = "GetVolumeInformationW", CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false)]
[DllImport("kernel32.dll", EntryPoint = "GetVolumeInformationW", CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false)]
internal static extern bool GetVolumeInformation(string drive, StringBuilder volumeName, int volumeNameBufLen, out int volSerialNumber, out int maxFileNameLen, out int fileSystemFlags, StringBuilder fileSystemName, int fileSystemNameBufLen);
[DllImport("api-ms-win-core-file-l1-1-0.dll", SetLastError = true)]
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern int GetDriveType(string drive);
[DllImport("api-ms-win-core-file-l1-1-0.dll", SetLastError = true)]
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool GetDiskFreeSpaceEx(string drive, out long freeBytesForUser, out long totalBytes, out long freeBytes);
private IEnumerable<char> GetValidDriveLettersOnMachine()
......
......@@ -10,7 +10,7 @@ namespace System.IO.Tests
{
public class Directory_NotifyFilter_Tests : FileSystemWatcherTest
{
[DllImport( "api-ms-win-security-provider-l1-1-0.dll", EntryPoint = "SetNamedSecurityInfoW",
[DllImport("advapi32.dll", EntryPoint = "SetNamedSecurityInfoW",
CallingConvention = CallingConvention.Winapi, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
private static extern uint SetSecurityInfoByHandle( string name, uint objectType, uint securityInformation,
IntPtr owner, IntPtr group, IntPtr dacl, IntPtr sacl);
......
......@@ -12,7 +12,7 @@ namespace System.IO.Tests
{
public class File_NotifyFilter_Tests : FileSystemWatcherTest
{
[DllImport("api-ms-win-security-provider-l1-1-0.dll", EntryPoint = "SetNamedSecurityInfoW",
[DllImport("advapi32.dll", EntryPoint = "SetNamedSecurityInfoW",
CallingConvention = CallingConvention.Winapi, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
private static extern uint SetSecurityInfoByHandle(string name, uint objectType, uint securityInformation,
IntPtr owner, IntPtr group, IntPtr dacl, IntPtr sacl);
......
......@@ -14,10 +14,10 @@ internal static class DllImports
[DllImport("kernel32.dll", EntryPoint = "GetDiskFreeSpaceExW", CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false)]
internal static extern bool GetDiskFreeSpaceEx(String drive, out long freeBytesForUser, out long totalBytes, out long freeBytes);
[DllImport("api-ms-win-core-file-l1-1-0.dll", EntryPoint = "GetVolumeInformationW", CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false)]
[DllImport("kernel32.dll", EntryPoint = "GetVolumeInformationW", CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false)]
internal static extern bool GetVolumeInformation(String drive, [Out]StringBuilder volumeName, int volumeNameBufLen, out int volSerialNumber, out int maxFileNameLen, out int fileSystemFlags, [Out]StringBuilder fileSystemName, int fileSystemNameBufLen);
[DllImport("api-ms-win-core-file-l1-1-0.dll", EntryPoint = "GetDriveTypeW", CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false)]
[DllImport("kernel32.dll", EntryPoint = "GetDriveTypeW", CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false)]
internal static extern int GetDriveType(string drive);
}
......@@ -21,12 +21,12 @@
using System.Threading.Tasks;
public static class MountHelper
{
[DllImport("api-ms-win-core-file-l1-2-0.dll", EntryPoint = "GetVolumeNameForVolumeMountPointW", CharSet = CharSet.Unicode, BestFitMapping = false, SetLastError = true)]
[DllImport("kernel32.dll", EntryPoint = "GetVolumeNameForVolumeMountPointW", CharSet = CharSet.Unicode, BestFitMapping = false, SetLastError = true)]
private static extern bool GetVolumeNameForVolumeMountPoint(String volumeName, StringBuilder uniqueVolumeName, int uniqueNameBufferCapacity);
// unique volume name must be "\\?\Volume{GUID}\"
[DllImport("api-ms-win-core-kernel32-legacy-l1-1-1.dll", EntryPoint = "SetVolumeMountPointW", CharSet = CharSet.Unicode, BestFitMapping = false, SetLastError = true)]
[DllImport("kernel32.dll", EntryPoint = "SetVolumeMountPointW", CharSet = CharSet.Unicode, BestFitMapping = false, SetLastError = true)]
private static extern bool SetVolumeMountPoint(String mountPoint, String uniqueVolumeName);
[DllImport("api-ms-win-core-file-l1-1-0.dll", EntryPoint = "DeleteVolumeMountPointW", CharSet = CharSet.Unicode, BestFitMapping = false, SetLastError = true)]
[DllImport("kernel32.dll", EntryPoint = "DeleteVolumeMountPointW", CharSet = CharSet.Unicode, BestFitMapping = false, SetLastError = true)]
private static extern bool DeleteVolumeMountPoint(String mountPoint);
/// <summary>Creates a symbolic link using command line tools</summary>
......
......@@ -328,7 +328,7 @@ protected static void AssertInheritability(SafeHandle handle, HandleInheritabili
private const uint HANDLE_FLAG_INHERIT = 0x00000001;
[DllImport("api-ms-win-core-sysinfo-l1-1-0.dll")]
[DllImport("kernel32.dll")]
private static extern void GetSystemInfo(out SYSTEM_INFO input);
[StructLayout(LayoutKind.Sequential)]
......
......@@ -224,7 +224,7 @@ private static void SetEnvironmentVariableWithPInvoke(string name, string value)
Assert.True(success);
}
[DllImport("api-ms-win-core-processenvironment-l1-1-0.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern bool SetEnvironmentVariable(string lpName, string lpValue);
[DllImport("libc")]
......
......@@ -48,7 +48,7 @@ public void Unix_ProcessorCountTest()
[DllImport("libc")]
private static extern long sysconf(int name);
[DllImport("api-ms-win-core-sysinfo-l1-1-0.dll", SetLastError = true)]
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern void GetSystemInfo(ref SYSTEM_INFO lpSystemInfo);
[StructLayout(LayoutKind.Sequential)]
......
......@@ -345,7 +345,7 @@ public void GetLogicalDrives_Windows_MatchesExpectedLetters()
}
}
[DllImport("api-ms-win-core-file-l1-1-0.dll", SetLastError = true)]
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern int GetLogicalDrives();
[DllImport("shell32.dll", SetLastError = false, BestFitMapping = false, ExactSpelling = true)]
......
......@@ -8,20 +8,20 @@
internal static class DllImport
{
[DllImport("api-ms-win-core-file-l1-1-0.dll", SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false)]
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false)]
internal static extern Win32Handle CreateFile(String lpFileName,
FileAccess dwDesiredAccess, FileShare dwShareMode,
IntPtr securityAttrs, CreationDisposition dwCreationDisposition,
FileAttributes dwFlagsAndAttributes, IntPtr hTemplateFile);
[DllImport("api-ms-win-core-file-l1-1-0.dll", SetLastError = true)]
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern unsafe int WriteFile(SafeHandle handle, byte* bytes, int numBytesToWrite, IntPtr numBytesWritten_mustBeZero, NativeOverlapped* lpOverlapped);
[DllImport("api-ms-win-core-handle-l1-1-0.dll", SetLastError = true)]
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool CloseHandle(IntPtr handle);
[DllImport("api-ms-win-core-handle-l1-1-0.dll", ExactSpelling = true, SetLastError = true)]
[DllImport("kernel32.dll", ExactSpelling = true, SetLastError = true)]
internal static extern bool GetHandleInformation(IntPtr handle, out int flags);
internal const int ERROR_IO_PENDING = 0x000003E5;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册