More nullability work on Kernel32 and its unit tests

nullableenabled
David Hall 2023-09-24 19:15:49 -06:00
parent f96aeb0d43
commit 3e459127e9
30 changed files with 180 additions and 129 deletions

View File

@ -946,7 +946,7 @@ public static partial class Kernel32
/// call GetLastError.
/// </returns>
[PInvokeData("WinBase.h", MSDNShortId = "ms679351")]
public static string FormatMessage(string formatString, object[]? args, FormatMessageFlags flags = 0)
public static string? FormatMessage(string? formatString, object[]? args, FormatMessageFlags flags = 0)
{
if (string.IsNullOrEmpty(formatString) || args == null || args.Length == 0 || flags.IsFlagSet(FormatMessageFlags.FORMAT_MESSAGE_IGNORE_INSERTS)) return formatString;
flags &= ~(FormatMessageFlags.FORMAT_MESSAGE_FROM_HMODULE | FormatMessageFlags.FORMAT_MESSAGE_FROM_SYSTEM);

View File

@ -6216,7 +6216,59 @@ public static partial class Kernel32
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("FileAPI.h", MSDNShortId = "ms724933")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern unsafe bool SetFileTime([In] HFILE hFile, [In, Optional] PFILETIME lpCreationTime, [In, Optional] PFILETIME lpLastAccessTime, [In, Optional] PFILETIME lpLastWriteTime);
public static extern bool SetFileTime([In] HFILE hFile, [In, Optional] PFILETIME lpCreationTime, [In, Optional] PFILETIME lpLastAccessTime, [In, Optional] PFILETIME lpLastWriteTime);
/// <summary>
/// <para>Sets the date and time that the specified file or directory was created, last accessed, or last modified.</para>
/// </summary>
/// <param name="hFile">
/// <para>
/// A handle to the file or directory. The handle must have been created using the <c>CreateFile</c> function with the
/// <c>FILE_WRITE_ATTRIBUTES</c> access right. For more information, see File Security and Access Rights.
/// </para>
/// </param>
/// <param name="lpCreationTime">
/// <para>
/// A pointer to a <c>FILETIME</c> structure that contains the new creation date and time for the file or directory. If the
/// application does not need to change this information, set this parameter either to <c>NULL</c> or to a pointer to a
/// <c>FILETIME</c> structure that has both the <c>dwLowDateTime</c> and <c>dwHighDateTime</c> members set to 0.
/// </para>
/// </param>
/// <param name="lpLastAccessTime">
/// <para>
/// A pointer to a <c>FILETIME</c> structure that contains the new last access date and time for the file or directory. The last
/// access time includes the last time the file or directory was written to, read from, or (in the case of executable files) run. If
/// the application does not need to change this information, set this parameter either to <c>NULL</c> or to a pointer to a
/// <c>FILETIME</c> structure that has both the <c>dwLowDateTime</c> and <c>dwHighDateTime</c> members set to 0.
/// </para>
/// <para>
/// To prevent file operations using the given handle from modifying the last access time, call <c>SetFileTime</c> immediately after
/// opening the file handle and pass a <c>FILETIME</c> structure that has both the <c>dwLowDateTime</c> and <c>dwHighDateTime</c>
/// members set to 0xFFFFFFFF.
/// </para>
/// </param>
/// <param name="lpLastWriteTime">
/// <para>
/// A pointer to a <c>FILETIME</c> structure that contains the new last modified date and time for the file or directory. If the
/// application does not need to change this information, set this parameter either to <c>NULL</c> or to a pointer to a
/// <c>FILETIME</c> structure that has both the <c>dwLowDateTime</c> and <c>dwHighDateTime</c> members set to 0.
/// </para>
/// <para>
/// To prevent file operations using the given handle from modifying the last access time, call <c>SetFileTime</c> immediately after
/// opening the file handle and pass a <c>FILETIME</c> structure that has both the <c>dwLowDateTime</c> and <c>dwHighDateTime</c>
/// members set to 0xFFFFFFFF.
/// </para>
/// </param>
/// <returns>
/// <para>If the function succeeds, the return value is nonzero.</para>
/// <para>If the function fails, the return value is zero. To get extended error information, call <c>GetLastError</c>.</para>
/// </returns>
// BOOL WINAPI SetFileTime( _In_ HANDLE hFile, _In_opt_ const FILETIME *lpCreationTime, _In_opt_ const FILETIME *lpLastAccessTime,
// _In_opt_ const FILETIME *lpLastWriteTime);
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("FileAPI.h", MSDNShortId = "ms724933")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetFileTime([In] HFILE hFile, in FILETIME lpCreationTime, in FILETIME lpLastAccessTime, in FILETIME lpLastWriteTime);
/// <summary>
/// Sets the valid data length of the specified file. This function is useful in very limited scenarios. For more information, see

View File

@ -1542,7 +1542,7 @@ public static partial class Kernel32
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("WinBase.h", MSDNShortId = "aa366753")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MapUserPhysicalPages([In] IntPtr lpAddress, SizeT NumberOfPages, [In, MarshalAs(UnmanagedType.LPArray)] IntPtr[] UserPfnArray);
public static extern bool MapUserPhysicalPages([In] IntPtr lpAddress, SizeT NumberOfPages, [In, MarshalAs(UnmanagedType.LPArray)] IntPtr[]? UserPfnArray);
/// <summary>
/// <para>Maps previously allocated physical memory pages at a specified address in an Address Windowing Extensions (AWE) region.</para>
@ -1583,7 +1583,7 @@ public static partial class Kernel32
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("WinBase.h", MSDNShortId = "aa366755")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MapUserPhysicalPagesScatter([In] IntPtr VirtualAddresses, SizeT NumberOfPages, [In, MarshalAs(UnmanagedType.LPArray)] IntPtr[] PageArray);
public static extern bool MapUserPhysicalPagesScatter([In] IntPtr VirtualAddresses, SizeT NumberOfPages, [In, MarshalAs(UnmanagedType.LPArray)] IntPtr[]? PageArray);
/// <summary>
/// <para>Maps a view of a file mapping into the address space of a calling process.</para>

View File

@ -34,7 +34,7 @@ public static partial class Kernel32
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("processtopologyapi.h", MSDNShortId = "e22a4910-45dd-4eb6-9ed5-a8e0bcdfad7b")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetProcessGroupAffinity(HPROCESS hProcess, ref ushort GroupCount, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] ushort[] GroupArray);
public static extern bool GetProcessGroupAffinity(HPROCESS hProcess, ref ushort GroupCount, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] ushort[]? GroupArray);
/// <summary>Retrieves the processor group affinity of the specified thread.</summary>
/// <param name="hThread">

View File

@ -1417,7 +1417,7 @@ public static partial class Kernel32
// https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-lstrcmpa int lstrcmpA( LPCSTR lpString1, LPCSTR lpString2 );
[DllImport(Lib.Kernel32, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("winbase.h", MSDNShortId = "windows/desktop/api/winbase/nf-winbase-lstrcmpa")]
public static extern int lstrcmp(string lpString1, string lpString2);
public static extern int lstrcmp(string? lpString1, string? lpString2);
/// <summary>
/// <para>Compares two character strings. The comparison is not case-sensitive.</para>
@ -1471,7 +1471,7 @@ public static partial class Kernel32
// lpString2 );
[DllImport(Lib.Kernel32, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("winbase.h", MSDNShortId = "windows/desktop/api/winbase/nf-winbase-lstrcmpia")]
public static extern int lstrcmpi(string lpString1, string lpString2);
public static extern int lstrcmpi(string? lpString1, string? lpString2);
/// <summary>
/// <para>Copies a specified number of characters from a source string into a buffer.</para>
@ -1538,7 +1538,7 @@ public static partial class Kernel32
// lpString2, int iMaxLength );
[DllImport(Lib.Kernel32, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("winbase.h")]
public static extern StrPtrAuto lstrcpyn(StringBuilder lpString1, string lpString2, int iMaxLength);
public static extern StrPtrAuto lstrcpyn(StringBuilder lpString1, string? lpString2, int iMaxLength);
/// <summary>Determines the length of the specified string (not including the terminating null character).</summary>
/// <param name="lpString">
@ -1552,7 +1552,7 @@ public static partial class Kernel32
// int WINAPI lstrlen( _In_ LPCTSTR lpString); https://msdn.microsoft.com/en-us/library/windows/desktop/ms647492(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = false, CharSet = CharSet.Auto, BestFitMapping = false, ThrowOnUnmappableChar = true)]
[PInvokeData("Winbase.h", MSDNShortId = "ms647492")]
public static extern int lstrlen(string lpString);
public static extern int lstrlen(string? lpString);
/// <summary>
/// Multiplies two 32-bit values and then divides the 64-bit result by a third 32-bit value. The final result is rounded to the

View File

@ -3662,7 +3662,7 @@ public static partial class Kernel32
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("Winnls.h", MSDNShortId = "dd317805")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumCalendarInfoExEx(EnumCalendarInfoProcExEx pCalInfoEnumProcExEx, string lpLocaleName, CALID Calendar, [Optional] string? lpReserved, CALTYPE CalType, [Optional] IntPtr lParam);
public static extern bool EnumCalendarInfoExEx(EnumCalendarInfoProcExEx pCalInfoEnumProcExEx, string? lpLocaleName, CALID Calendar, [Optional] string? lpReserved, CALTYPE CalType, [Optional] IntPtr lParam);
/// <summary>Enumerates calendar information for a locale specified by name.</summary>
/// <param name="lpLocaleName">Pointer to a locale name, or one of the following predefined values.</param>
@ -3676,7 +3676,7 @@ public static partial class Kernel32
/// </param>
/// <returns>The requested list of calendar information.</returns>
[PInvokeData("Winnls.h", MSDNShortId = "dd317805")]
public static IEnumerable<(CALID, string)> EnumCalendarInfoExEx(string lpLocaleName, CALID Calendar, CALTYPE CalType)
public static IEnumerable<(CALID, string)> EnumCalendarInfoExEx(string? lpLocaleName, CALID Calendar, CALTYPE CalType)
{
var l = new List<(CALID, string)>();
if (!EnumCalendarInfoExEx((s, c, i, p) => { l.Add((c, s)); return true; }, lpLocaleName, Calendar, null, CalType))
@ -3798,7 +3798,7 @@ public static partial class Kernel32
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("Winnls.h", MSDNShortId = "dd317812")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumDateFormatsExEx(EnumDateFormatsProcExEx lpDateFmtEnumProcExEx, string lpLocaleName, DATE_FORMAT dwFlags, [Optional] IntPtr lParam);
public static extern bool EnumDateFormatsExEx(EnumDateFormatsProcExEx lpDateFmtEnumProcExEx, string? lpLocaleName, DATE_FORMAT dwFlags, [Optional] IntPtr lParam);
/// <summary>Enumerates the long date, short date, or year/month formats that are available for a locale specified by name.</summary>
/// <param name="lpLocaleName">Pointer to a locale name, or one of the following predefined values.</param>
@ -3830,7 +3830,7 @@ public static partial class Kernel32
/// </para>
/// </param>
/// <returns>Returns the list of requested formats.</returns>
public static IEnumerable<(CALID, string)> EnumDateFormatsExEx(string lpLocaleName, DATE_FORMAT dwFlags)
public static IEnumerable<(CALID, string)> EnumDateFormatsExEx(string? lpLocaleName, DATE_FORMAT dwFlags)
{
var l = new List<(CALID, string)>();
if (!EnumDateFormatsExEx((s, c, p) => { l.Add((c, s)); return true; }, lpLocaleName, dwFlags))
@ -4330,7 +4330,7 @@ public static partial class Kernel32
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("Winnls.h", MSDNShortId = "dd317831")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumTimeFormatsEx(EnumTimeFormatsProcEx lpTimeFmtEnumProcEx, string lpLocaleName, TIME_FORMAT_ENUM dwFlags, [Optional] IntPtr lParam);
public static extern bool EnumTimeFormatsEx(EnumTimeFormatsProcEx lpTimeFmtEnumProcEx, string? lpLocaleName, TIME_FORMAT_ENUM dwFlags, [Optional] IntPtr lParam);
/// <summary>Enumerates the time formats that are available for a locale specified by name.</summary>
/// <param name="lpLocaleName">Pointer to a locale name, or one of the following predefined values.</param>
@ -4340,7 +4340,7 @@ public static partial class Kernel32
/// </param>
/// <returns>List of time formats.</returns>
[PInvokeData("Winnls.h", MSDNShortId = "dd317831")]
public static IEnumerable<string> EnumTimeFormatsEx(string lpLocaleName, TIME_FORMAT_ENUM dwFlags)
public static IEnumerable<string> EnumTimeFormatsEx(string? lpLocaleName, TIME_FORMAT_ENUM dwFlags)
{
var list = new List<string>();
if (!EnumTimeFormatsEx((s, p) => { list.Add(s); return true; }, lpLocaleName, dwFlags))
@ -4654,7 +4654,7 @@ public static partial class Kernel32
// lpVersionInformation, _In_opt_ LPVOID lpReserved, _In_opt_ LPARAM sortHandle); https://msdn.microsoft.com/en-us/library/windows/desktop/dd318059(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("Winnls.h", MSDNShortId = "dd318059")]
public static extern int FindNLSStringEx(string lpLocaleName, COMPARE_STRING dwFindNLSStringFlags, string lpStringSource, int cchSource, string lpStringValue, int cchValue, out int pcchFound, [Optional] IntPtr lpVersionInformation, [Optional] IntPtr lpReserved, [Optional] IntPtr sortHandle);
public static extern int FindNLSStringEx(string? lpLocaleName, COMPARE_STRING dwFindNLSStringFlags, string lpStringSource, int cchSource, string lpStringValue, int cchValue, out int pcchFound, [Optional] IntPtr lpVersionInformation, [Optional] IntPtr lpReserved, [Optional] IntPtr sortHandle);
/// <summary>Retrieves the current Windows ANSI code page identifier for the operating system.</summary>
/// <returns>
@ -4741,7 +4741,7 @@ public static partial class Kernel32
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("", MSDNShortId = "eb2622bc-a98d-42bd-ab59-7a849000d79d")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetCalendarDateFormatEx(string lpszLocale, DATE_FORMAT dwFlags, in CALDATETIME lpCalDateTime, string lpFormat, StringBuilder lpDateStr, int cchDate);
public static extern bool GetCalendarDateFormatEx(string? lpszLocale, DATE_FORMAT dwFlags, in CALDATETIME lpCalDateTime, string lpFormat, StringBuilder lpDateStr, int cchDate);
/// <summary>
/// Retrieves information about a calendar for a locale specified by identifier. <note type="note">For interoperability reasons, the
@ -4884,7 +4884,7 @@ public static partial class Kernel32
// _Out_opt_ LPWSTR lpCalData, _In_ int cchData, _Out_opt_ LPDWORD lpValue); https://msdn.microsoft.com/en-us/library/windows/desktop/dd318075(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("Winnls.h", MSDNShortId = "dd318075")]
public static extern int GetCalendarInfoEx(string lpLocaleName, CALID Calendar, [Optional] string? lpReserved, CALTYPE CalType, [Optional] IntPtr lpCalData, [Optional] int cchData, out uint lpValue);
public static extern int GetCalendarInfoEx(string? lpLocaleName, CALID Calendar, [Optional] string? lpReserved, CALTYPE CalType, [Optional] IntPtr lpCalData, [Optional] int cchData, out uint lpValue);
/// <summary>Retrieves information about a calendar for a locale specified by name.</summary>
/// <param name="lpLocaleName">Pointer to a locale name, or one of the following predefined values.</param>
@ -4927,7 +4927,7 @@ public static partial class Kernel32
// _Out_opt_ LPWSTR lpCalData, _In_ int cchData, _Out_opt_ LPDWORD lpValue); https://msdn.microsoft.com/en-us/library/windows/desktop/dd318075(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("Winnls.h", MSDNShortId = "dd318075")]
public static extern int GetCalendarInfoEx(string lpLocaleName, CALID Calendar, [Optional] string? lpReserved, CALTYPE CalType, StringBuilder lpCalData, int cchData, [Optional] IntPtr lpValue);
public static extern int GetCalendarInfoEx(string? lpLocaleName, CALID Calendar, [Optional] string? lpReserved, CALTYPE CalType, StringBuilder lpCalData, int cchData, [Optional] IntPtr lpValue);
/// <summary>Deprecated. Gets the supported date range for a specified calendar.</summary>
/// <param name="Calendar">The calendar.</param>
@ -5137,7 +5137,7 @@ public static partial class Kernel32
// *lpFormat, _Out_opt_ LPWSTR lpCurrencyStr, _In_ int cchCurrency); https://msdn.microsoft.com/en-us/library/windows/desktop/dd318084(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("Winnls.h", MSDNShortId = "dd318084")]
public static extern int GetCurrencyFormatEx(string lpLocaleName, LOCALE_FORMAT_FLAG dwFlags, [Optional] string? lpValue, in CURRENCYFMT lpFormat, StringBuilder lpCurrencyStr, int cchCurrency);
public static extern int GetCurrencyFormatEx(string? lpLocaleName, LOCALE_FORMAT_FLAG dwFlags, [Optional] string? lpValue, in CURRENCYFMT lpFormat, StringBuilder lpCurrencyStr, int cchCurrency);
/// <summary>Formats a number string as a currency string for a locale specified by name.</summary>
/// <param name="lpLocaleName">Pointer to a locale name or one of the following predefined values.</param>
@ -5176,7 +5176,7 @@ public static partial class Kernel32
// *lpFormat, _Out_opt_ LPWSTR lpCurrencyStr, _In_ int cchCurrency); https://msdn.microsoft.com/en-us/library/windows/desktop/dd318084(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("Winnls.h", MSDNShortId = "dd318084")]
public static extern int GetCurrencyFormatEx(string lpLocaleName, LOCALE_FORMAT_FLAG dwFlags, [Optional] string? lpValue, [Optional] IntPtr lpFormat, StringBuilder lpCurrencyStr, int cchCurrency);
public static extern int GetCurrencyFormatEx(string? lpLocaleName, LOCALE_FORMAT_FLAG dwFlags, [Optional] string? lpValue, [Optional] IntPtr lpFormat, StringBuilder lpCurrencyStr, int cchCurrency);
/// <summary>Formats a duration of time as a time string for a locale specified by identifier.</summary>
/// <param name="Locale">
@ -5381,7 +5381,7 @@ public static partial class Kernel32
// ullDuration, _In_opt_ LPCWSTR lpFormat, _Out_opt_ LPWSTR lpDurationStr, _In_ int cchDuration); https://msdn.microsoft.com/en-us/library/windows/desktop/dd318092(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("Winnls.h", MSDNShortId = "dd318092")]
public static extern int GetDurationFormatEx(string lpLocaleName, LOCALE_FORMAT_FLAG dwFlags, in SYSTEMTIME lpDuration, [Optional] ulong ullDuration, [Optional] string? lpFormat, StringBuilder lpDurationStr, int cchDuration);
public static extern int GetDurationFormatEx(string? lpLocaleName, LOCALE_FORMAT_FLAG dwFlags, in SYSTEMTIME lpDuration, [Optional] ulong ullDuration, [Optional] string? lpFormat, StringBuilder lpDurationStr, int cchDuration);
/// <summary>Formats a duration of time as a time string for a locale specified by name.</summary>
/// <param name="lpLocaleName">Pointer to a locale name, or one of the following predefined values.</param>
@ -5476,7 +5476,7 @@ public static partial class Kernel32
// ullDuration, _In_opt_ LPCWSTR lpFormat, _Out_opt_ LPWSTR lpDurationStr, _In_ int cchDuration); https://msdn.microsoft.com/en-us/library/windows/desktop/dd318092(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("Winnls.h", MSDNShortId = "dd318092")]
public static extern int GetDurationFormatEx(string lpLocaleName, LOCALE_FORMAT_FLAG dwFlags, [Optional] IntPtr lpDuration, [Optional] ulong ullDuration, [Optional] string? lpFormat, StringBuilder lpDurationStr, int cchDuration);
public static extern int GetDurationFormatEx(string? lpLocaleName, LOCALE_FORMAT_FLAG dwFlags, [Optional] IntPtr lpDuration, [Optional] ulong ullDuration, [Optional] string? lpFormat, StringBuilder lpDurationStr, int cchDuration);
/// <summary>Retrieves resource-related information about a file.</summary>
/// <param name="dwFlags">
@ -5848,7 +5848,7 @@ public static partial class Kernel32
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("Winnls.h", MSDNShortId = "dd318097")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetFileMUIPath(MUI_LANGUAGE_PATH dwFlags, string pcwszFilePath, StringBuilder pwszLanguage, ref uint pcchLanguage, StringBuilder pwszFileMUIPath, ref uint pcchFileMUIPath, ref ulong pululEnumerator);
public static extern bool GetFileMUIPath(MUI_LANGUAGE_PATH dwFlags, string pcwszFilePath, StringBuilder? pwszLanguage, ref uint pcchLanguage, StringBuilder? pwszFileMUIPath, ref uint pcchFileMUIPath, ref ulong pululEnumerator);
/// <summary>
/// <para>
@ -6025,7 +6025,7 @@ public static partial class Kernel32
// int GetLocaleInfoEx( _In_opt_ LPCWSTR lpLocaleName, _In_ LCTYPE LCType, _Out_opt_ LPWSTR lpLCData, _In_ int cchData); https://msdn.microsoft.com/en-us/library/windows/desktop/dd318103(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("Winnls.h", MSDNShortId = "dd318103")]
public static extern int GetLocaleInfoEx(string lpLocaleName, LCTYPE LCType, StringBuilder lpLCData, int cchData);
public static extern int GetLocaleInfoEx(string? lpLocaleName, LCTYPE LCType, StringBuilder lpLCData, int cchData);
/// <summary>Retrieves information about a locale specified by name.</summary>
/// <param name="lpLocaleName">Pointer to a locale name, or one of the following predefined values.</param>
@ -6069,7 +6069,7 @@ public static partial class Kernel32
// int GetLocaleInfoEx( _In_opt_ LPCWSTR lpLocaleName, _In_ LCTYPE LCType, _Out_opt_ LPWSTR lpLCData, _In_ int cchData); https://msdn.microsoft.com/en-us/library/windows/desktop/dd318103(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("Winnls.h", MSDNShortId = "dd318103")]
public static extern int GetLocaleInfoEx(string lpLocaleName, LCTYPE LCType, IntPtr lpLCData, int cchData);
public static extern int GetLocaleInfoEx(string? lpLocaleName, LCTYPE LCType, IntPtr lpLCData, int cchData);
/// <summary>Retrieves information about the current version of a specified NLS capability for a locale specified by identifier.</summary>
/// <param name="Function">The NLS capability to query. This value must be COMPARE_STRING. See the <c>SYSNLS_FUNCTION</c> enumeration.</param>
@ -6107,7 +6107,7 @@ public static partial class Kernel32
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("Winnls.h", MSDNShortId = "dd318107")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetNLSVersionEx(SYSNLS_FUNCTION function, string lpLocaleName, ref NLSVERSIONINFOEX lpVersionInformation);
public static extern bool GetNLSVersionEx(SYSNLS_FUNCTION function, string? lpLocaleName, ref NLSVERSIONINFOEX lpVersionInformation);
/// <summary>Formats a number string as a number string customized for a locale specified by identifier.</summary>
/// <param name="Locale">
@ -6151,7 +6151,7 @@ public static partial class Kernel32
// LPTSTR lpNumberStr, _In_ int cchNumber); https://msdn.microsoft.com/en-us/library/windows/desktop/dd318110(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("Winnls.h", MSDNShortId = "dd318110")]
public static extern int GetNumberFormat(LCID Locale, LOCALE_FORMAT_FLAG dwFlags, string lpValue, in NUMBERFMT lpFormat, StringBuilder lpNumberStr, int cchNumber);
public static extern int GetNumberFormat(LCID Locale, LOCALE_FORMAT_FLAG dwFlags, string? lpValue, in NUMBERFMT lpFormat, StringBuilder lpNumberStr, int cchNumber);
/// <summary>Formats a number string as a number string customized for a locale specified by identifier.</summary>
/// <param name="Locale">
@ -6195,7 +6195,7 @@ public static partial class Kernel32
// LPTSTR lpNumberStr, _In_ int cchNumber); https://msdn.microsoft.com/en-us/library/windows/desktop/dd318110(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("Winnls.h", MSDNShortId = "dd318110")]
public static extern int GetNumberFormat(LCID Locale, LOCALE_FORMAT_FLAG dwFlags, string lpValue, [Optional] IntPtr lpFormat, StringBuilder lpNumberStr, int cchNumber);
public static extern int GetNumberFormat(LCID Locale, LOCALE_FORMAT_FLAG dwFlags, string? lpValue, [Optional] IntPtr lpFormat, StringBuilder lpNumberStr, int cchNumber);
/// <summary>Formats a number string as a number string customized for a locale specified by name.</summary>
/// <param name="lpLocaleName">Pointer to a locale name, or one of the following predefined values.</param>
@ -6238,7 +6238,7 @@ public static partial class Kernel32
// *lpFormat, _Out_opt_ LPWSTR lpNumberStr, _In_ int cchNumber); https://msdn.microsoft.com/en-us/library/windows/desktop/dd318113(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("Winnls.h", MSDNShortId = "dd318113")]
public static extern int GetNumberFormatEx(string lpLocaleName, LOCALE_FORMAT_FLAG dwFlags, string lpValue, in NUMBERFMT lpFormat, StringBuilder lpNumberStr, int cchNumber);
public static extern int GetNumberFormatEx(string? lpLocaleName, LOCALE_FORMAT_FLAG dwFlags, string? lpValue, in NUMBERFMT lpFormat, StringBuilder lpNumberStr, int cchNumber);
/// <summary>Formats a number string as a number string customized for a locale specified by name.</summary>
/// <param name="lpLocaleName">Pointer to a locale name, or one of the following predefined values.</param>
@ -6281,7 +6281,7 @@ public static partial class Kernel32
// *lpFormat, _Out_opt_ LPWSTR lpNumberStr, _In_ int cchNumber); https://msdn.microsoft.com/en-us/library/windows/desktop/dd318113(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("Winnls.h", MSDNShortId = "dd318113")]
public static extern int GetNumberFormatEx(string lpLocaleName, LOCALE_FORMAT_FLAG dwFlags, string lpValue, [Optional] IntPtr lpFormat, StringBuilder lpNumberStr, int cchNumber);
public static extern int GetNumberFormatEx(string? lpLocaleName, LOCALE_FORMAT_FLAG dwFlags, string? lpValue, [Optional] IntPtr lpFormat, StringBuilder lpNumberStr, int cchNumber);
/// <summary>Returns the current original equipment manufacturer (OEM) code page identifier for the operating system.</summary>
/// <returns>Returns the current OEM code page identifier for the operating system.</returns>
@ -6446,7 +6446,7 @@ public static partial class Kernel32
// cchScripts); https://msdn.microsoft.com/en-us/library/windows/desktop/dd318116(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("Winnls.h", MSDNShortId = "dd318116")]
public static extern int GetStringScripts(GetStringScriptsFlag dwFlags, string lpString, int cchString, StringBuilder lpScripts, int cchScripts);
public static extern int GetStringScripts(GetStringScriptsFlag dwFlags, string lpString, int cchString, StringBuilder? lpScripts, int cchScripts);
/// <summary>Returns the language identifier for the system locale.</summary>
/// <returns>
@ -7532,7 +7532,7 @@ public static partial class Kernel32
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("Winnls.h", MSDNShortId = "dd318681")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsValidLocaleName(string lpLocaleName);
public static extern bool IsValidLocaleName(string? lpLocaleName);
/// <summary>Determines if the NLS version is valid for a given NLS function.</summary>
/// <param name="function">The NLS capability to query. This value must be COMPARE_STRING. See the <c>SYSNLS_FUNCTION</c> enumeration.</param>
@ -7545,7 +7545,7 @@ public static partial class Kernel32
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("Winnls.h", MSDNShortId = "hh706739")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsValidNLSVersion(SYSNLS_FUNCTION function, string lpLocaleName, ref NLSVERSIONINFOEX lpVersionInformation);
public static extern bool IsValidNLSVersion(SYSNLS_FUNCTION function, string? lpLocaleName, ref NLSVERSIONINFOEX lpVersionInformation);
/// <summary>Converts a locale identifier to a locale name.</summary>
/// <param name="Locale">
@ -7863,7 +7863,7 @@ public static partial class Kernel32
// sortHandle); https://msdn.microsoft.com/en-us/library/windows/desktop/dd318702(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("Winnls.h", MSDNShortId = "dd318702")]
public static extern int LCMapStringEx(string lpLocaleName, uint dwMapFlags, string lpSrcStr, int cchSrc, StringBuilder lpDestStr, int cchDest, ref NLSVERSIONINFO lpVersionInformation, [Optional] IntPtr lpReserved, [Optional] IntPtr sortHandle);
public static extern int LCMapStringEx(string? lpLocaleName, uint dwMapFlags, string lpSrcStr, int cchSrc, StringBuilder lpDestStr, int cchDest, ref NLSVERSIONINFO lpVersionInformation, [Optional] IntPtr lpReserved, [Optional] IntPtr sortHandle);
/// <summary>
/// For a locale specified by name, maps an input character string to another using a specified transformation, or generates a sort
@ -8072,7 +8072,7 @@ public static partial class Kernel32
// sortHandle); https://msdn.microsoft.com/en-us/library/windows/desktop/dd318702(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("Winnls.h", MSDNShortId = "dd318702")]
public static extern int LCMapStringEx(string lpLocaleName, uint dwMapFlags, string lpSrcStr, int cchSrc, StringBuilder lpDestStr, int cchDest, [Optional] IntPtr lpVersionInformation, [Optional] IntPtr lpReserved, [Optional] IntPtr sortHandle);
public static extern int LCMapStringEx(string? lpLocaleName, uint dwMapFlags, string lpSrcStr, int cchSrc, StringBuilder lpDestStr, int cchDest, [Optional] IntPtr lpVersionInformation, [Optional] IntPtr lpReserved, [Optional] IntPtr sortHandle);
/// <summary>
/// <para>Unsupported. <c>LoadStringByReference</c> may be altered or unavailable. Instead, use SHLoadIndirectString.</para>
@ -8135,7 +8135,7 @@ public static partial class Kernel32
// LCID LocaleNameToLCID( _In_ LPCWSTR lpName, _In_ DWORD dwFlags); https://msdn.microsoft.com/en-us/library/windows/desktop/dd318711(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("Winnls.h", MSDNShortId = "dd318711")]
public static extern LCID LocaleNameToLCID(string lpName, LCTYPE dwFlags);
public static extern LCID LocaleNameToLCID(string? lpName, LCTYPE dwFlags);
/// <summary>Creates a language identifier from a primary language identifier and a sublanguage identifier.</summary>
/// <param name="usPrimaryLanguage">
@ -8248,7 +8248,7 @@ public static partial class Kernel32
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
[PInvokeData("Winnls.h", MSDNShortId = "dd319112")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool ResolveLocaleName(string lpNameToResolve, StringBuilder lpLocaleName, int cchLocaleName);
public static extern bool ResolveLocaleName(string? lpNameToResolve, StringBuilder lpLocaleName, int cchLocaleName);
/// <summary>Sets an item of locale information for a calendar. For more information, see Date and Calendar.</summary>
/// <param name="Locale">
@ -8528,7 +8528,7 @@ public static partial class Kernel32
[PInvokeData("Winnls.h", MSDNShortId = "dd374052")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetThreadPreferredUILanguages(MUI_LANGUAGE_FLAGS dwFlags,
[In, MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(NullTermStringArrayMarshaler), MarshalCookie = "Unicode")] string[] pwszLanguagesBuffer, out uint pulNumLanguages);
[In, MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(NullTermStringArrayMarshaler), MarshalCookie = "Unicode")] string[]? pwszLanguagesBuffer, out uint pulNumLanguages);
/// <summary>
/// <para>Sets the user interface language for the current thread.</para>

View File

@ -111,10 +111,10 @@ Simple:
static long GetTypeSize(Type t) { try { return (long)InteropExtensions.SizeOf(t); } catch { return -1; } }
}
public static void RunForEach<TEnum>(Type lib, string name, Func<TEnum, object[]> makeParam, Action<TEnum, object?, object[]>? action = null, Action<Exception?>? error = null) where TEnum : Enum =>
public static void RunForEach<TEnum>(Type lib, string name, Func<TEnum, object?[]> makeParam, Action<TEnum, object?, object?[]>? action = null, Action<Exception?>? error = null) where TEnum : Enum =>
RunForEach(lib, name, makeParam, (e, ex) => error?.Invoke(ex), action);
public static void RunForEach<TEnum>(Type lib, string name, Func<TEnum, object[]> makeParam, Action<TEnum, Exception?>? error = null, Action<TEnum, object?, object[]>? action = null, CorrespondingAction? filter = null) where TEnum : Enum
public static void RunForEach<TEnum>(Type lib, string name, Func<TEnum, object?[]> makeParam, Action<TEnum, Exception?>? error = null, Action<TEnum, object?, object?[]>? action = null, CorrespondingAction? filter = null) where TEnum : Enum
{
MethodInfo mi = lib.GetMethods(BindingFlags.Public | BindingFlags.Static).Where(m => m.IsGenericMethod && m.Name == name).First() ?? throw new ArgumentException("Unable to find method.");
foreach (TEnum e in Enum.GetValues(typeof(TEnum)).Cast<TEnum>())

View File

@ -7,13 +7,13 @@ namespace Vanara.PInvoke.Tests;
[TestFixture]
public class AppModelTests
{
public string pkgFamilyName = "DesktopView_cw5n1h2txyewy", pkgFullName = "DesktopView_10.0.22621.1_neutral_neutral_cw5n1h2txyewy";
public string? pkgFamilyName = "DesktopView_cw5n1h2txyewy", pkgFullName = "DesktopView_10.0.22621.1_neutral_neutral_cw5n1h2txyewy";
//[OneTimeSetUp]
public void _Setup()
{
FunctionHelper.CallMethodWithStrBuf((StringBuilder sb, ref uint sz) => GetCurrentPackageFamilyName(ref sz, sb), out pkgFamilyName).ThrowIfFailed();
FunctionHelper.CallMethodWithStrBuf((StringBuilder sb, ref uint sz) => GetCurrentPackageFullName(ref sz, sb), out pkgFullName).ThrowIfFailed();
FunctionHelper.CallMethodWithStrBuf((StringBuilder? sb, ref uint sz) => GetCurrentPackageFamilyName(ref sz, sb), out pkgFamilyName).ThrowIfFailed();
FunctionHelper.CallMethodWithStrBuf((StringBuilder? sb, ref uint sz) => GetCurrentPackageFullName(ref sz, sb), out pkgFullName).ThrowIfFailed();
}
[Test]
@ -52,7 +52,7 @@ public class AppModelTests
[Test]
public void FindPackagesByPackageFamilyTest()
{
Assert.That(FindPackagesByPackageFamily(pkgFamilyName, PACKAGE_FLAGS.PACKAGE_FILTER_HEAD | PACKAGE_FLAGS.PACKAGE_INFORMATION_BASIC, out string[] fullNames, out uint[] props), ResultIs.Successful);
Assert.That(FindPackagesByPackageFamily(pkgFamilyName!, PACKAGE_FLAGS.PACKAGE_FILTER_HEAD | PACKAGE_FLAGS.PACKAGE_INFORMATION_BASIC, out string?[] fullNames, out uint[] props), ResultIs.Successful);
for (int i = 0; i < fullNames.Length; i++)
TestContext.WriteLine($"{pkgFamilyName} = {fullNames[i]} : {props[i]}");
Assert.That(fullNames, Is.Not.Empty);
@ -61,7 +61,7 @@ public class AppModelTests
[Test]
public void GetPackagesByPackageFamilyTest()
{
Assert.That(GetPackagesByPackageFamily(pkgFamilyName, out string[] pkgNames), ResultIs.Successful);
Assert.That(GetPackagesByPackageFamily(pkgFamilyName!, out string?[] pkgNames), ResultIs.Successful);
pkgNames.WriteValues();
}
@ -69,7 +69,7 @@ public class AppModelTests
public void GetPackageApplicationIdsTest()
{
PACKAGE_INFO_REFERENCE pir = new();
Assert.That(OpenPackageInfoByFullName(pkgFullName, 0, ref pir), ResultIs.Successful);
Assert.That(OpenPackageInfoByFullName(pkgFullName!, 0, ref pir), ResultIs.Successful);
uint sz = 0;
Assert.That(GetPackageApplicationIds(pir, ref sz, default, out _), ResultIs.FailureCode(Win32Error.ERROR_INSUFFICIENT_BUFFER));
using SafeCoTaskMemHandle buffer = new(sz);

View File

@ -45,10 +45,10 @@ public static class ConsoleTestProcess
private static int Aliases()
{
if (!AddConsoleAlias("test", "expansion string", Assembly.GetEntryAssembly().Location))
if (!AddConsoleAlias("test", "expansion string", Assembly.GetEntryAssembly()!.Location))
return ShowErr("AddConsoleAlias");
StringBuilder sb = new(256);
if (!GetConsoleAlias("test", sb, (uint)sb.Capacity, Assembly.GetEntryAssembly().Location))
if (!GetConsoleAlias("test", sb, (uint)sb.Capacity, Assembly.GetEntryAssembly()!.Location))
return ShowErr("GetConsoleAlias");
foreach (string exe in GetConsoleAliasExes())
{

View File

@ -43,7 +43,7 @@ public class ErrHandlingApiTests
Assert.That(FormatMessage("X", null), Is.EqualTo("X"));
Assert.That(FormatMessage("X", objs), Is.EqualTo("X"));
Assert.That(FormatMessage("X %1", new[] { "YZ" }), Is.EqualTo("X YZ"));
string s = FormatMessage("%1 %2 %3 %4 %5 %6 %7 %8", objs);
string? s = FormatMessage("%1 %2 %3 %4 %5 %6 %7 %8", objs);
Assert.That(s, Is.EqualTo(string.Join(" ", objs)));
s = FormatMessage("%1 %2", new object[] { 4, "Alan" }, FormatMessageFlags.FORMAT_MESSAGE_IGNORE_INSERTS);
Assert.That(s, Is.EqualTo("%1 %2"));

View File

@ -42,8 +42,8 @@ public class FileApiTests
[Test]
public void CompareFileTimeTest()
{
System.Runtime.InteropServices.ComTypes.FILETIME now = DateTime.Now.ToFileTimeStruct();
System.Runtime.InteropServices.ComTypes.FILETIME today = DateTime.Today.ToFileTimeStruct();
FILETIME now = DateTime.Now.ToFileTimeStruct();
FILETIME today = DateTime.Today.ToFileTimeStruct();
Assert.That(CompareFileTime(now, today), Is.GreaterThan(0));
Assert.That(CompareFileTime(now, now), Is.Zero);
}
@ -68,7 +68,7 @@ public class FileApiTests
Assert.That(b);
if (read < sb.Capacity) Marshal.WriteInt16((IntPtr)sb, (int)read, '\0');
Assert.That(read, Is.Not.Zero.And.LessThanOrEqualTo(sb.Capacity));
Assert.That((string)sb, Is.EqualTo(tmpstr));
Assert.That((string?)sb, Is.EqualTo(tmpstr));
b = SetFilePointerEx(f, 0, out long pos, SeekOrigin.Begin);
if (!b) TestContext.WriteLine($"SetFilePointerEx:{Win32Error.GetLastError()}");
@ -134,12 +134,12 @@ public class FileApiTests
[Test]
public void FileTimeToLocalFileTimeTest()
{
System.Runtime.InteropServices.ComTypes.FILETIME utc = DateTime.UtcNow.ToFileTimeStruct();
FILETIME utc = DateTime.UtcNow.ToFileTimeStruct();
FileTimeToSystemTime(utc, out SYSTEMTIME st);
Assert.That(FileTimeToLocalFileTime(utc, out System.Runtime.InteropServices.ComTypes.FILETIME ftlocal), Is.True);
Assert.That(FileTimeToLocalFileTime(utc, out FILETIME ftlocal), Is.True);
FileTimeToSystemTime(ftlocal, out SYSTEMTIME stl);
Assert.That(stl.wHour, Is.EqualTo(DateTime.Now.Hour));
Assert.That(LocalFileTimeToFileTime(ftlocal, out System.Runtime.InteropServices.ComTypes.FILETIME utc2), Is.True);
Assert.That(LocalFileTimeToFileTime(ftlocal, out FILETIME utc2), Is.True);
Assert.That(utc.ToUInt64(), Is.EqualTo(utc2.ToUInt64()));
}
@ -211,7 +211,7 @@ public class FileApiTests
public void GetFileInformationByHandleTest()
{
using TempFile tmp = new(Kernel32.FileAccess.FILE_GENERIC_READ, FileShare.Read);
Assert.That(GetFileInformationByHandle(tmp.hFile, out BY_HANDLE_FILE_INFORMATION fi), Is.True);
Assert.That(GetFileInformationByHandle(tmp.hFile!, out BY_HANDLE_FILE_INFORMATION fi), Is.True);
Assert.That(fi.nFileSizeLow, Is.EqualTo(tmpstr.Length));
}
@ -219,9 +219,9 @@ public class FileApiTests
public void GetFileSizeTest()
{
using TempFile tmp = new(Kernel32.FileAccess.FILE_GENERIC_READ, FileShare.Read);
Assert.That(GetFileSize(tmp.hFile, out uint hw), Is.EqualTo(TempFile.tmpstr.Length));
Assert.That(GetFileSize(tmp.hFile!, out uint hw), Is.EqualTo(TempFile.tmpstr.Length));
Assert.That(hw, Is.Zero);
Assert.That(GetFileSizeEx(tmp.hFile, out long sz), Is.True);
Assert.That(GetFileSizeEx(tmp.hFile!, out long sz), Is.True);
Assert.That(sz, Is.EqualTo(TempFile.tmpstr.Length));
}
@ -229,7 +229,7 @@ public class FileApiTests
public void GetFileTypeTest()
{
using TempFile tmp = new(Kernel32.FileAccess.FILE_GENERIC_READ, FileShare.Read);
Assert.That(GetFileType(tmp.hFile), Is.EqualTo(FileType.FILE_TYPE_DISK));
Assert.That(GetFileType(tmp.hFile!), Is.EqualTo(FileType.FILE_TYPE_DISK));
}
[Test]
@ -237,7 +237,7 @@ public class FileApiTests
{
StringBuilder sb = new(MAX_PATH);
using TempFile tmp = new(Kernel32.FileAccess.FILE_GENERIC_READ, FileShare.Read);
uint u = GetFinalPathNameByHandle(tmp.hFile, sb, MAX_PATH, FinalPathNameOptions.FILE_NAME_NORMALIZED);
uint u = GetFinalPathNameByHandle(tmp.hFile!, sb, MAX_PATH, FinalPathNameOptions.FILE_NAME_NORMALIZED);
Assert.That(u, Is.Not.Zero);
TestContext.WriteLine(sb);
}
@ -280,12 +280,12 @@ public class FileApiTests
public void GetSetFileTimeTest()
{
using TempFile tmp = new(Kernel32.FileAccess.FILE_ALL_ACCESS, FileShare.Read);
Assert.That(GetFileTime(tmp.hFile, out System.Runtime.InteropServices.ComTypes.FILETIME ft1, out System.Runtime.InteropServices.ComTypes.FILETIME ft2, out System.Runtime.InteropServices.ComTypes.FILETIME ft3), Is.True);
System.Runtime.InteropServices.ComTypes.FILETIME nft = DateTime.UtcNow.ToFileTimeStruct();
bool b = SetFileTime(tmp.hFile, ft1, ft2, nft);
Assert.That(GetFileTime(tmp.hFile!, out FILETIME ft1, out FILETIME ft2, out FILETIME ft3), Is.True);
FILETIME nft = DateTime.UtcNow.ToFileTimeStruct();
bool b = SetFileTime(tmp.hFile!, ft1, ft2, nft);
if (!b) TestContext.WriteLine($"SetFileTime:{Win32Error.GetLastError()}");
Assert.That(b, Is.True);
Assert.That(GetFileTime(tmp.hFile, out System.Runtime.InteropServices.ComTypes.FILETIME nft1, out System.Runtime.InteropServices.ComTypes.FILETIME nft2, out System.Runtime.InteropServices.ComTypes.FILETIME nft3), Is.True);
Assert.That(GetFileTime(tmp.hFile!, out FILETIME nft1, out FILETIME nft2, out FILETIME nft3), Is.True);
Assert.That(ft1, Is.EqualTo(nft1));
Assert.That(nft, Is.EqualTo(nft3));
}
@ -324,7 +324,7 @@ public class FileApiTests
StringBuilder vn = new(1024);
StringBuilder fsn = new(1024);
using TempFile tmp = new(Kernel32.FileAccess.FILE_GENERIC_READ, FileShare.Read);
bool b = GetVolumeInformationByHandleW(tmp.hFile, vn, (uint)vn.Capacity, out uint vsn, out uint mcl, out FileSystemFlags fsf, fsn, (uint)fsn.Capacity);
bool b = GetVolumeInformationByHandleW(tmp.hFile!, vn, (uint)vn.Capacity, out uint vsn, out uint mcl, out FileSystemFlags fsf, fsn, (uint)fsn.Capacity);
Assert.That(b, Is.True);
Assert.That(vn.ToString(), Is.Not.Null.And.Not.Empty);
Assert.That(vsn, Is.Not.EqualTo(0));
@ -375,9 +375,9 @@ public class FileApiTests
{
using TempFile tmp = new(Kernel32.FileAccess.FILE_GENERIC_READ, FileShare.Read);
NativeOverlapped nativeOverlapped = new();
Assert.That(LockFileEx(tmp.hFile, LOCKFILE.LOCKFILE_FAIL_IMMEDIATELY, 0, 5, 0, &nativeOverlapped), Is.True);
Assert.That(LockFileEx(tmp.hFile!, LOCKFILE.LOCKFILE_FAIL_IMMEDIATELY, 0, 5, 0, &nativeOverlapped), Is.True);
SleepEx(0, true);
Assert.That(UnlockFileEx(tmp.hFile, 0, 5, 0, &nativeOverlapped), Is.True);
Assert.That(UnlockFileEx(tmp.hFile!, 0, 5, 0, &nativeOverlapped), Is.True);
SleepEx(0, true);
}
@ -385,8 +385,8 @@ public class FileApiTests
public void LockFileTest()
{
using TempFile tmp = new(Kernel32.FileAccess.FILE_GENERIC_READ, FileShare.Read);
Assert.That(LockFile(tmp.hFile, 0, 0, 5, 0), Is.True);
Assert.That(UnlockFile(tmp.hFile, 0, 0, 5, 0), Is.True);
Assert.That(LockFile(tmp.hFile!, 0, 0, 5, 0), Is.True);
Assert.That(UnlockFile(tmp.hFile!, 0, 0, 5, 0), Is.True);
}
[Test]
@ -396,7 +396,7 @@ public class FileApiTests
using SafeCoTaskMemString sb = new(100, CharSet.Ansi);
uint read = 0U;
NativeOverlapped nativeOverlapped = new();
bool b = ReadFileEx(tmp.hFile, (byte*)(IntPtr)sb, (uint)sb.Capacity, &nativeOverlapped, fnComplete);
bool b = ReadFileEx(tmp.hFile!, (byte*)(IntPtr)sb, (uint)sb.Capacity, &nativeOverlapped, fnComplete);
if (!b) TestContext.WriteLine($"ReadFileEx:{Win32Error.GetLastError()}");
Assert.That(b);
SleepEx(0, true);
@ -407,7 +407,7 @@ public class FileApiTests
unsafe void fnComplete(uint dwErrorCode, uint dwNumberOfBytesTransfered, NativeOverlapped* lpOverlapped)
{
if (dwErrorCode == 0)
GetOverlappedResult(tmp.hFile, lpOverlapped, out read, false);
GetOverlappedResult(tmp.hFile!, lpOverlapped, out read, false);
else
read = dwNumberOfBytesTransfered;
}
@ -418,7 +418,7 @@ public class FileApiTests
{
using TempFile tmp = new(Kernel32.FileAccess.FILE_ALL_ACCESS, FileShare.Read);
FILE_ALLOCATION_INFO fai = new() { AllocationSize = 512 };
bool b = SetFileInformationByHandle(tmp.hFile, FILE_INFO_BY_HANDLE_CLASS.FileAllocationInfo, fai);
bool b = SetFileInformationByHandle(tmp.hFile!, FILE_INFO_BY_HANDLE_CLASS.FileAllocationInfo, fai);
if (!b) TestContext.WriteLine($"SetFileInformationByHandle:{Win32Error.GetLastError()}");
Assert.That(b, Is.True);
}

View File

@ -38,7 +38,7 @@ public class InterlockedApiTests
PROGRAM_ITEM? programItem = pListEntry.ToNullableStructure<PROGRAM_ITEM>();
if (!programItem.HasValue)
Assert.Fail("NULL from InterlockedPopEntrySList");
Assert.That(Count, Is.EqualTo(programItem.Value.Signature));
Assert.That(Count, Is.EqualTo(programItem!.Value.Signature));
Marshal.FreeHGlobal(pListEntry);
}

View File

@ -64,9 +64,6 @@ public class SafeLocalHandleTests
Assert.That(!h.IsClosed && !h.IsInvalid);
Assert.That((int)h.Size, Is.EqualTo(IntPtr.Size + r.Length * (4 + IntPtr.Size)));
Assert.That(h.ToStringEnum(4, CharSet.Unicode), Has.Exactly(4).EqualTo("5").And.Exactly(4).Items);
h = SafeLocalHandle.CreateFromStringList(null);
Assert.That((int)h.Size, Is.EqualTo(StringHelper.GetCharSize()));
}
[Test(Description = "Allocate a structure")]

View File

@ -93,10 +93,10 @@ public class Kernel32Tests
[Test]
public void QueryDosDeviceTest()
{
System.Collections.Generic.IEnumerable<string> ie = null;
System.Collections.Generic.IEnumerable<string>? ie = null;
Assert.That(() => ie = QueryDosDevice("C:"), Throws.Nothing);
Assert.That(ie, Is.Not.Null);
TestContext.WriteLine(string.Join(",", ie));
TestContext.WriteLine(string.Join(",", ie!));
Assert.That(ie, Is.Not.Empty);
}

View File

@ -79,7 +79,7 @@ public class ProcessEnvTests
public void SearchPathTest()
{
StringBuilder sb = new(MAX_PATH);
Assert.That(SearchPath(null, "notepad.exe", null, (uint)sb.Capacity, sb, out InteropServices.StrPtrAuto ptr), Is.Not.Zero);
Assert.That(SearchPath(null, "notepad.exe", null, (uint)sb.Capacity, sb, out StrPtrAuto ptr), Is.Not.Zero);
Assert.That(sb.ToString().StartsWith("C:"));
Assert.That(ptr.ToString(), Is.EqualTo("notepad.exe"));
}

View File

@ -223,18 +223,18 @@ public class ProcessThreadsTests
public void GetProcessMitigationPolicyTest()
{
HPROCESS hProc = GetCurrentProcess();
TestHelper.RunForEach<PROCESS_MITIGATION_POLICY>(typeof(Kernel32), "GetProcessMitigationPolicy", e => new object[] { hProc, e, null }, (e, ret, param) =>
TestHelper.RunForEach<PROCESS_MITIGATION_POLICY>(typeof(Kernel32), "GetProcessMitigationPolicy", e => new object?[] { hProc, e, null }, (e, ret, param) =>
{
if (!(bool)ret) TestContext.WriteLine($"{e} -> {Win32Error.GetLastError()}");
if (!(bool)ret!) TestContext.WriteLine($"{e} -> {Win32Error.GetLastError()}");
Assert.That(ret, Is.True);
param[2].WriteValues();
param?[2]?.WriteValues();
});
}
[Test]
public void GetProcessTimesTest()
{
Assert.That(GetProcessTimes(GetCurrentProcess(), out System.Runtime.InteropServices.ComTypes.FILETIME ct, out System.Runtime.InteropServices.ComTypes.FILETIME xt, out System.Runtime.InteropServices.ComTypes.FILETIME kt, out System.Runtime.InteropServices.ComTypes.FILETIME ut), Is.True);
Assert.That(GetProcessTimes(GetCurrentProcess(), out FILETIME ct, out FILETIME xt, out FILETIME kt, out FILETIME ut), Is.True);
Assert.That(ct.ToDateTime(), Is.LessThan(DateTime.Now));
TestContext.Write($"{ct.ToDateTime()}, {xt.ToDateTime()}, {kt.ToDateTime()}, {ut.ToDateTime()}");
}
@ -348,7 +348,7 @@ public class ProcessThreadsTests
[Test]
public void GetSystemTimesTest()
{
Assert.That(GetSystemTimes(out System.Runtime.InteropServices.ComTypes.FILETIME idle, out System.Runtime.InteropServices.ComTypes.FILETIME kern, out System.Runtime.InteropServices.ComTypes.FILETIME user), Is.True);
Assert.That(GetSystemTimes(out FILETIME idle, out FILETIME kern, out FILETIME user), Is.True);
Assert.That(kern.ToDateTime(), Is.GreaterThan(idle.ToDateTime()));
Assert.That(user.ToUInt64(), Is.Not.Zero);
}
@ -364,7 +364,7 @@ public class ProcessThreadsTests
public void GetThreadInformationTest()
{
TestHelper.RunForEach<THREAD_INFORMATION_CLASS>(typeof(Kernel32), "GetThreadInformation", e => new object[] { GetCurrentThread(), e },
(e, ret, param) => ret.WriteValues(), ex => throw ex);
(e, ret, param) => ret?.WriteValues(), ex => throw ex!);
}
[Test]
@ -376,7 +376,7 @@ public class ProcessThreadsTests
[Test]
public void GetThreadTimesTest()
{
Assert.That(GetThreadTimes(GetCurrentThread(), out System.Runtime.InteropServices.ComTypes.FILETIME ct, out System.Runtime.InteropServices.ComTypes.FILETIME xt, out System.Runtime.InteropServices.ComTypes.FILETIME kt, out System.Runtime.InteropServices.ComTypes.FILETIME ut), Is.True);
Assert.That(GetThreadTimes(GetCurrentThread(), out FILETIME ct, out FILETIME xt, out FILETIME kt, out FILETIME ut), Is.True);
Assert.That(ct.ToDateTime(), Is.LessThan(DateTime.Now));
TestContext.Write($"{ct.ToDateTime()}, {xt.ToDateTime()}, {kt.ToDateTime()}, {ut.ToDateTime()}");
}

View File

@ -45,7 +45,7 @@ public class PsApiTests
[Test]
public void GetDeviceDriverBaseFileNameTest()
{
System.IntPtr imgBase = EnumDeviceDrivers()[0];
IntPtr imgBase = EnumDeviceDrivers()[0];
StringBuilder sb = new(MAX_PATH);
Assert.That(GetDeviceDriverBaseName(imgBase, sb, (uint)sb.Capacity), Is.Not.Zero);
TestContext.Write(sb + " : ");

View File

@ -771,7 +771,7 @@ public class SynchApiTests
Assert.That(WaitForSingleObject(gDoneEvent, INFINITE), Is.EqualTo(WAIT_STATUS.WAIT_OBJECT_0));
Assert.That(timerOrWaitFired.HasValue, Is.True);
Assert.That(timerOrWaitFired.Value, Is.True);
Assert.That(timerOrWaitFired!.Value, Is.True);
}
void TimerRoutine(IntPtr lpParameter, bool TimerOrWaitFired)
@ -789,7 +789,7 @@ public class SynchApiTests
Assert.That(hTimer.IsNull, Is.False);
// Set a timer to wait for 2 seconds.
System.Runtime.InteropServices.ComTypes.FILETIME liDueTime = TimeSpan.FromSeconds(2).ToFileTimeStruct();
FILETIME liDueTime = TimeSpan.FromSeconds(2).ToFileTimeStruct();
Assert.That(SetWaitableTimerEx(hTimer, liDueTime, 0, null, default, new REASON_CONTEXT("Because"), 50), ResultIs.Successful);
// Wait for the timer.
@ -808,7 +808,7 @@ public class SynchApiTests
new System.Threading.Thread(ThreadProc).Start();
// Set a timer to wait for 2 seconds.
System.Runtime.InteropServices.ComTypes.FILETIME liDueTime = TimeSpan.FromSeconds(2).ToFileTimeStruct();
FILETIME liDueTime = TimeSpan.FromSeconds(2).ToFileTimeStruct();
Assert.That(SetWaitableTimer(hTimer, liDueTime, 0, null, default, false), ResultIs.Successful);
// Wait for the timer.

View File

@ -9,8 +9,8 @@ public class SysInfoTests
[Test]
public void DnsHostnameToComputerNameTest()
{
Assert.That(GetComputerNameEx(COMPUTER_NAME_FORMAT.ComputerNameDnsFullyQualified, out string name), ResultIs.Successful);
Assert.That(DnsHostnameToComputerName(name, out string compName), ResultIs.Successful);
Assert.That(GetComputerNameEx(COMPUTER_NAME_FORMAT.ComputerNameDnsFullyQualified, out var name), ResultIs.Successful);
Assert.That(DnsHostnameToComputerName(name!, out var compName), ResultIs.Successful);
Assert.That(compName, Is.EqualTo(Environment.MachineName));
TestContext.WriteLine($"{name} => {compName}");
}
@ -18,15 +18,15 @@ public class SysInfoTests
[Test]
public void EnumSystemFirmwareTablesTest()
{
Assert.That(EnumSystemFirmwareTables(FirmwareTableProviderId.ACPI, out uint[] ids), ResultIs.Successful);
Assert.That(ids.Length, Is.GreaterThan(0));
ids.WriteValues();
Assert.That(EnumSystemFirmwareTables(FirmwareTableProviderId.ACPI, out var ids), ResultIs.Successful);
Assert.That(ids?.Length, Is.GreaterThan(0));
ids?.WriteValues();
}
[Test]
public void GetComputerNameTest()
{
Assert.That(GetComputerName(out string name), ResultIs.Successful);
Assert.That(GetComputerName(out var name), ResultIs.Successful);
Assert.That(name, Is.EqualTo(Environment.MachineName));
TestContext.WriteLine(name);
}
@ -89,9 +89,9 @@ public class SysInfoTests
[Test]
public void GetLogicalProcessorInformationTest()
{
Assert.That(GetLogicalProcessorInformation(out SYSTEM_LOGICAL_PROCESSOR_INFORMATION[] info), ResultIs.Successful);
Assert.That(info.Length, Is.GreaterThan(0));
info.WriteValues();
Assert.That(GetLogicalProcessorInformation(out var info), ResultIs.Successful);
Assert.That(info?.Length, Is.GreaterThan(0));
info?.WriteValues();
}
[Test]
@ -125,9 +125,9 @@ public class SysInfoTests
[Test]
public void GetProcessorSystemCycleTimeTest()
{
Assert.That(GetProcessorSystemCycleTime(0, out SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION[] info), ResultIs.Successful);
Assert.That(info.Length, Is.GreaterThan(0));
info.WriteValues();
Assert.That(GetProcessorSystemCycleTime(0, out var info), ResultIs.Successful);
Assert.That(info?.Length, Is.GreaterThan(0));
info?.WriteValues();
}
[Test]
@ -188,14 +188,14 @@ public class SysInfoTests
[Test]
public void GetSystemTimeAsFileTimeTest()
{
GetSystemTimeAsFileTime(out System.Runtime.InteropServices.ComTypes.FILETIME ft);
GetSystemTimeAsFileTime(out FILETIME ft);
Assert.That(ft.ToSYSTEMTIME().Ticks, Is.Not.Zero);
}
[Test]
public void GetSystemTimePreciseAsFileTimeTest()
{
GetSystemTimePreciseAsFileTime(out System.Runtime.InteropServices.ComTypes.FILETIME ft);
GetSystemTimePreciseAsFileTime(out FILETIME ft);
Assert.That(ft.ToSYSTEMTIME().Ticks, Is.Not.Zero);
}

View File

@ -51,7 +51,7 @@ public class TLHelp32Tests
[Test]
public void Toolhelp32ReadProcessMemoryTest()
{
throw new System.NotImplementedException("No documentation on how.");
throw new NotImplementedException("No documentation on how.");
//Assert.That(Toolhelp32ReadProcessMemory(), Is.True);
}
}

View File

@ -55,7 +55,7 @@ public class ThreadPoolApiSetTests
Assert.That(timer, ResultIs.ValidHandle);
// Set the timer to fire in one second.
System.Runtime.InteropServices.ComTypes.FILETIME FileDueTime = TimeSpan.FromSeconds(-1).ToFileTimeStruct();
FILETIME FileDueTime = TimeSpan.FromSeconds(-1).ToFileTimeStruct();
Assert.That(SetThreadpoolTimerEx(timer, FileDueTime, 0, 0), Is.False);
Assert.That(IsThreadpoolTimerSet(timer), Is.True);

View File

@ -18,7 +18,7 @@ public class TimeZoneApiTests
public void FileTimeToSystemTimeTest()
{
DateTime dt = DateTime.Today;
System.Runtime.InteropServices.ComTypes.FILETIME ft = dt.ToFileTimeStruct();
FILETIME ft = dt.ToFileTimeStruct();
Assert.That(FileTimeToSystemTime(ft, out SYSTEMTIME st), ResultIs.Successful);
Assert.That(dt.Year, Is.EqualTo(st.wYear));
Assert.That(dt.Day, Is.EqualTo(st.wDay));
@ -84,7 +84,7 @@ public class TimeZoneApiTests
DateTime dt = new(2000, 1, 1, 4, 4, 4, 444, DateTimeKind.Utc);
SYSTEMTIME st = new(dt, DateTimeKind.Utc);
Assert.That(st.ToString(DateTimeKind.Utc, null, null), Is.EqualTo(dt.ToString()));
Assert.That(SystemTimeToFileTime(st, out System.Runtime.InteropServices.ComTypes.FILETIME ft), ResultIs.Successful);
Assert.That(SystemTimeToFileTime(st, out FILETIME ft), ResultIs.Successful);
Assert.That(FileTimeExtensions.Equals(ft, dt.ToFileTimeStruct()));
}

View File

@ -38,10 +38,10 @@ public class WerApiTests
// Print a few lines into the log file.
byte[] BytesToPrint = Encoding.Unicode.GetBytes("Line 1\nLine 2\n");
Assert.That(WriteFile(LogFileHandle.hFile, BytesToPrint, (uint)BytesToPrint.Length, out uint BytesWritten), ResultIs.Successful);
Assert.That(WriteFile(LogFileHandle.hFile!, BytesToPrint, (uint)BytesToPrint.Length, out uint BytesWritten), ResultIs.Successful);
// Make sure we flush the log file so the bytes actually make it to the file-system.
Assert.That(FlushFileBuffers(LogFileHandle.hFile), ResultIs.Successful);
Assert.That(FlushFileBuffers(LogFileHandle.hFile!), ResultIs.Successful);
// Get the full path to the log file. We need this because WerRegisterFile requires a full path.
string LogFullPath = LogFileHandle.FullName;

View File

@ -12,7 +12,7 @@ public partial class WinBaseTests
// No tape drives to test against, so just checking each method runs.
Assert.That(() =>
{
BackupRead(HFILE.NULL, default, 0, out _, false, false, out System.IntPtr ctx);
BackupRead(HFILE.NULL, default, 0, out _, false, false, out IntPtr ctx);
BackupSeek(HFILE.NULL, 0, 0, out _, out _, ref ctx);
BackupWrite(HFILE.NULL, default, 0, out _, false, false, out ctx);
CreateTapePartition(HFILE.NULL, TAPE_PARTITION_METHOD.TAPE_FIXED_PARTITIONS, 1, 1);

View File

@ -135,8 +135,8 @@ public partial class WinBaseTests_File
using TempFile tmp = new(FileAccess.GENERIC_READ, FileShare.Read);
using SafeHFILE hDir = CreateFile(TestCaseSources.TempDirWhack, FileAccess.GENERIC_READ, FileShare.Read, null, FileMode.Open, FileFlagsAndAttributes.FILE_FLAG_BACKUP_SEMANTICS);
List<Exception> exes = new();
TestHelper.RunForEach<FILE_INFO_BY_HANDLE_CLASS>(typeof(Kernel32), "GetFileInformationByHandleEx", e => new object[] { IsDir(e) ? (HFILE)hDir : (HFILE)tmp.hFile, e },
(e, ex) => { ex.Source = e.ToString(); exes.Add(ex); }, (e, ret, param) => ret.WriteValues(), CorrespondingAction.Get);
TestHelper.RunForEach<FILE_INFO_BY_HANDLE_CLASS>(typeof(Kernel32), "GetFileInformationByHandleEx", e => new object[] { IsDir(e) ? (HFILE)hDir : (HFILE)tmp.hFile!, e },
(e, ex) => { ex!.Source = e.ToString(); exes.Add(ex); }, (e, ret, param) => ret?.WriteValues(), CorrespondingAction.Get);
if (exes.Count > 0)
throw new AggregateException(exes.ToArray());
@ -149,8 +149,8 @@ public partial class WinBaseTests_File
{
using TempFile tmp = new(FileAccess.GENERIC_READ, FileShare.Read);
// This shouldn't work on NTFS vols.
Assert.That(GetFileBandwidthReservation(tmp.hFile, out uint per, out uint bpp, out bool disc, out uint tsz, out uint reqs), ResultIs.FailureCode(Win32Error.ERROR_INVALID_FUNCTION));
Assert.That(SetFileBandwidthReservation(tmp.hFile, per, bpp, disc, out tsz, out reqs), ResultIs.FailureCode(Win32Error.ERROR_INVALID_FUNCTION));
Assert.That(GetFileBandwidthReservation(tmp.hFile!, out uint per, out uint bpp, out bool disc, out uint tsz, out uint reqs), ResultIs.FailureCode(Win32Error.ERROR_INVALID_FUNCTION));
Assert.That(SetFileBandwidthReservation(tmp.hFile!, per, bpp, disc, out tsz, out reqs), ResultIs.FailureCode(Win32Error.ERROR_INVALID_FUNCTION));
}
[Test]
@ -197,7 +197,7 @@ public partial class WinBaseTests_File
[Test]
public unsafe void ReadDirectoryChangesExWTest()
{
string newFile = Path.Combine(Path.GetDirectoryName(fn), "X.ico");
string newFile = Path.Combine(Path.GetDirectoryName(fn)!, "X.ico");
using SafeHFILE hDir = CreateFile(TestCaseSources.TempDirWhack, FileAccess.GENERIC_READ, FileShare.Read, null, FileMode.Open, FileFlagsAndAttributes.FILE_FLAG_BACKUP_SEMANTICS);
using SafeHGlobalHandle mem = new(4096);
new Thread(() => { Sleep(100); DeleteFile(newFile); CopyFile(fn, newFile, false); DeleteFile(newFile); }).Start();
@ -208,7 +208,7 @@ public partial class WinBaseTests_File
do
{
FILE_NOTIFY_EXTENDED_INFORMATION i = mem.DangerousGetHandle().Offset(nxt).ToStructure<FILE_NOTIFY_EXTENDED_INFORMATION>();
i.FileName = StringHelper.GetString(mem.DangerousGetHandle().Offset(nxt + 76), CharSet.Unicode, i.FileNameLength);
i.FileName = StringHelper.GetString(mem.DangerousGetHandle().Offset(nxt + 76), CharSet.Unicode, i.FileNameLength)!;
nxt += i.NextEntryOffset;
list.Add(i);
} while (nxt > 0);
@ -223,7 +223,7 @@ public partial class WinBaseTests_File
[Test]
public void ReadDirectoryChangesTest()
{
string newFile = Path.Combine(Path.GetDirectoryName(fn), "X.ico");
string newFile = Path.Combine(Path.GetDirectoryName(fn)!, "X.ico");
using SafeHFILE hDir = CreateFile(TestCaseSources.TempDirWhack, FileAccess.GENERIC_READ, FileShare.Read, null, FileMode.Open, FileFlagsAndAttributes.FILE_FLAG_BACKUP_SEMANTICS);
using SafeHGlobalHandle mem = new(4096);
new Thread(() => { Sleep(100); DeleteFile(newFile); CopyFile(fn, newFile, false); DeleteFile(newFile); }).Start();
@ -234,7 +234,7 @@ public partial class WinBaseTests_File
do
{
FILE_NOTIFY_INFORMATION i = mem.DangerousGetHandle().Offset(nxt).ToStructure<FILE_NOTIFY_INFORMATION>();
i.FileName = StringHelper.GetString(mem.DangerousGetHandle().Offset(nxt + 12), CharSet.Unicode, i.FileNameLength);
i.FileName = StringHelper.GetString(mem.DangerousGetHandle().Offset(nxt + 12), CharSet.Unicode, i.FileNameLength)!;
nxt += i.NextEntryOffset;
list.Add(i);
} while (nxt > 0);
@ -251,7 +251,7 @@ public partial class WinBaseTests_File
{
using TempFile tmp = new(FileAccess.GENERIC_WRITE, FileShare.Read);
Assert.That(tmp, ResultIs.ValidHandle);
using SafeHFILE hRe = ReOpenFile(tmp.hFile, FileAccess.GENERIC_READ, FileShare.ReadWrite, 0);
using SafeHFILE hRe = ReOpenFile(tmp.hFile!, FileAccess.GENERIC_READ, FileShare.ReadWrite, 0);
Assert.That(hRe, ResultIs.ValidHandle);
}
@ -267,7 +267,7 @@ public partial class WinBaseTests_File
public void SetFileCompletionNotificationModesTest()
{
using TempFile tmp = new(FileAccess.GENERIC_WRITE, FileShare.Read, FileMode.Create, FileFlagsAndAttributes.FILE_FLAG_OVERLAPPED);
Assert.That(SetFileCompletionNotificationModes(tmp.hFile, FILE_NOTIFICATION_MODE.FILE_SKIP_SET_EVENT_ON_HANDLE), ResultIs.Successful);
Assert.That(SetFileCompletionNotificationModes(tmp.hFile!, FILE_NOTIFICATION_MODE.FILE_SKIP_SET_EVENT_ON_HANDLE), ResultIs.Successful);
}
[Test]
@ -276,7 +276,7 @@ public partial class WinBaseTests_File
using ElevPriv priv = new("SeLockMemoryPrivilege");
using TempFile tmp = new(FileAccess.FILE_READ_ATTRIBUTES | FileAccess.GENERIC_READ, FileShare.Read, FileMode.Create, FileFlagsAndAttributes.FILE_FLAG_OVERLAPPED | FileFlagsAndAttributes.FILE_FLAG_NO_BUFFERING);
using AlignedMemory<HGlobalMemoryMethods> mem = new(1024, 1024);
Assert.That(SetFileIoOverlappedRange(tmp.hFile, mem, (uint)mem.Size), ResultIs.Failure); // Not sure why I'm having permissions problems.
Assert.That(SetFileIoOverlappedRange(tmp.hFile!, mem, (uint)mem.Size), ResultIs.Failure); // Not sure why I'm having permissions problems.
}
[Test]
@ -284,7 +284,7 @@ public partial class WinBaseTests_File
{
using (new ElevPriv("SeRestorePrivilege"))
using (TempFile tmp = new(FileAccess.GENERIC_ALL, FileShare.ReadWrite, dwFlagsAndAttributes: FileFlagsAndAttributes.FILE_FLAG_BACKUP_SEMANTICS))
Assert.That(SetFileShortName(tmp.hFile, "SN.TXT"), ResultIs.Successful);
Assert.That(SetFileShortName(tmp.hFile!, "SN.TXT"), ResultIs.Successful);
}
[Test]

View File

@ -10,7 +10,7 @@ public partial class WinBaseTests_Power
public void GetSetDevicePowerStateTest()
{
using TempFile tmp = new(FileAccess.GENERIC_READ, System.IO.FileShare.Read);
Assert.That(GetDevicePowerState(tmp.hFile.DangerousGetHandle(), out bool on), ResultIs.Successful);
Assert.That(GetDevicePowerState(tmp.hFile!.DangerousGetHandle(), out bool on), ResultIs.Successful);
Assert.That(on);
}

View File

@ -72,7 +72,7 @@ public partial class WinBaseTests_ProcessThread
public void GetNumaNodeNumberFromHandleTest()
{
using TempFile tmp = new(FileAccess.GENERIC_READ, System.IO.FileShare.Read);
Assert.That(GetNumaNodeNumberFromHandle(tmp.hFile, out ushort num), ResultIs.Successful);
Assert.That(GetNumaNodeNumberFromHandle(tmp.hFile!, out ushort num), ResultIs.Successful);
TestContext.Write(num);
}

View File

@ -30,7 +30,7 @@ public partial class WinBaseTests_Resource
Assert.That(hResLoad, ResultIs.ValidHandle);
// Lock the resource into global memory.
System.IntPtr lpResLock = LockResource(hResLoad);
IntPtr lpResLock = LockResource(hResLoad);
Assert.That(lpResLock, ResultIs.ValidHandle);
// Open the file to which you want to add the resource resource.

View File

@ -9,10 +9,10 @@ public partial class WinBaseTests_Time
[Test]
public void DosDateTimeToFileTimeTest()
{
System.Runtime.InteropServices.ComTypes.FILETIME ft = new DateTime(2019, 10, 29, 13, 51, 24, DateTimeKind.Local).ToFileTimeStruct();
FILETIME ft = new DateTime(2019, 10, 29, 13, 51, 24, DateTimeKind.Local).ToFileTimeStruct();
Assert.That(FileTimeToDosDateTime(ft, out ushort fatDate, out ushort fatTime), ResultIs.Successful);
Assert.That(BitHelper.GetBits(fatDate, 5, 4), Is.EqualTo(10));
Assert.That(DosDateTimeToFileTime(fatDate, fatTime, out System.Runtime.InteropServices.ComTypes.FILETIME outFt), ResultIs.Successful);
Assert.That(DosDateTimeToFileTime(fatDate, fatTime, out FILETIME outFt), ResultIs.Successful);
Assert.That(outFt.ToUInt64(), Is.EqualTo(ft.ToUInt64()));
}

View File

@ -13,6 +13,7 @@ public partial class WinBaseTests_TxF
Assert.That(() =>
{
bool b = false;
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
CopyFileTransacted(default, default, default, default, ref b, default, default);
CreateDirectoryTransacted(default, default, default, default);
CreateFileTransacted(default, default, default, default, default, default, default, default, default, default);
@ -29,6 +30,7 @@ public partial class WinBaseTests_TxF
MoveFileTransacted(default, default, default, default, default, default);
RemoveDirectoryTransacted(default, default);
SetFileAttributesTransacted(default, default, default);
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
}, Throws.Nothing);
}
}