Skip to content

Commit 3f16954

Browse files
author
dahall
committed
Lots of updates based on new generated code. Mostly cosmetic, removing duplicate functions that are now generated, adjusting attributes to get the correct generation, and fixing a few bugs along the way.
1 parent 59b6245 commit 3f16954

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1171
-929
lines changed

PInvoke/ActiveDS/ActiveDS.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ public static extern HRESULT ADsGetLastError(out Win32Error lpError, [Out, Marsh
382382
[PInvokeData("adshlp.h", MSDNShortId = "NF:adshlp.ADsGetObject")]
383383
[DllImport(Lib_Activeds, SetLastError = false, ExactSpelling = true)]
384384
public static extern HRESULT ADsGetObject([MarshalAs(UnmanagedType.LPWStr)] string lpszPathName, in Guid riid,
385-
[MarshalAs(UnmanagedType.Interface, IidParameterIndex = 1)] out object? ppObject);
385+
[MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 1)] out object? ppObject);
386386

387387
/// <summary>
388388
/// The <c>ADsOpenObject</c> function binds to an ADSI object using explicit user name and password credentials. <c>ADsOpenObject</c> is
@@ -485,7 +485,7 @@ public static extern HRESULT ADsGetObject([MarshalAs(UnmanagedType.LPWStr)] stri
485485
[PInvokeData("adshlp.h", MSDNShortId = "NF:adshlp.ADsOpenObject")]
486486
[DllImport(Lib_Activeds, SetLastError = false, ExactSpelling = true)]
487487
public static extern HRESULT ADsOpenObject([MarshalAs(UnmanagedType.LPWStr)] string lpszPathName, [MarshalAs(UnmanagedType.LPWStr), Optional] string? lpszUserName,
488-
[MarshalAs(UnmanagedType.LPWStr), Optional] string? lpszPassword, [Optional] ADS_AUTHENTICATION dwReserved, in Guid riid, [MarshalAs(UnmanagedType.Interface, IidParameterIndex = 4)] out object? ppObject);
488+
[MarshalAs(UnmanagedType.LPWStr), Optional] string? lpszPassword, [Optional] ADS_AUTHENTICATION dwReserved, in Guid riid, [MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 4)] out object? ppObject);
489489

490490
/// <summary>
491491
/// The <c>ADsSetLastError</c> sets the last-error code value for the calling thread. Directory service providers can use this function

PInvoke/Kernel32/AppModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1828,7 +1828,7 @@ public static extern Win32Error GetPackagePath(in PACKAGE_ID packageId, [Optiona
18281828
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)]
18291829
[PInvokeData("appmodel.h", MSDNShortId = "9C25708C-1464-4C59-9740-E9F105116385")]
18301830
public static extern Win32Error GetPackagePathByFullName(string packageFullName, ref uint pathLength,
1831-
[Optional, SizeDef(nameof(packageFullName), SizingMethod.Query)] StringBuilder? path);
1831+
[Optional, SizeDef(nameof(pathLength), SizingMethod.Query)] StringBuilder? path);
18321832

18331833
/// <summary>Gets the path of the specified package, with the option to specify the type of folder path to retrieve for the package.</summary>
18341834
/// <param name="packageFullName">

PInvoke/Kernel32/FileApi.cs

Lines changed: 6 additions & 236 deletions
Original file line numberDiff line numberDiff line change
@@ -5762,7 +5762,7 @@ public static IEnumerable<WIN32_FIND_DATA> EnumFilesEx(string lpFileName, FINDEX
57625762
static void ThrowIfNotNoMore() => Win32Error.ThrowLastErrorUnless(Win32Error.ERROR_NO_MORE_FILES);
57635763
}
57645764

5765-
/// <summary>Retrieves the names of the volumes on a computer using <see cref="FindFirstVolume"/> and <see cref="FindNextVolume"/>.</summary>
5765+
/// <summary>Retrieves the names of the volumes on a computer using <see cref="FindFirstVolume(StringBuilder, uint)"/> and <see cref="FindNextVolume(SafeVolumeSearchHandle, StringBuilder, uint)"/>.</summary>
57665766
/// <returns>An enumeration of the volume names.</returns>
57675767
public static IEnumerable<string> EnumVolumes()
57685768
{
@@ -7152,82 +7152,7 @@ public static extern uint GetTempPath2([Optional, Range(0, MAX_PATH + 1)] uint B
71527152
[PInvokeData("FileAPI.h", MSDNShortId = "aa364993")]
71537153
public static extern bool GetVolumeInformation([Optional] string? lpRootPathName, [SizeDef(nameof(nVolumeNameSize))] StringBuilder? lpVolumeNameBuffer,
71547154
[Range(0, MAX_PATH + 1)] int nVolumeNameSize, out uint lpVolumeSerialNumber, out uint lpMaximumComponentLength, out FileSystemFlags lpFileSystemFlags,
7155-
[SizeDef(nameof(nVolumeNameSize))] StringBuilder? lpFileSystemNameBuffer, [Range(0, MAX_PATH + 1)] int nFileSystemNameSize);
7156-
7157-
/// <summary>Retrieves information about the file system and volume associated with the specified root directory.</summary>
7158-
/// <param name="rootPathName">
7159-
/// A string that contains the root directory of the volume to be described.
7160-
/// <para>
7161-
/// If this parameter is NULL, the root of the current directory is used. A trailing backslash is required. For example, you specify
7162-
/// \\MyServer\MyShare as "\\MyServer\MyShare\", or the C drive as "C:\".
7163-
/// </para>
7164-
/// </param>
7165-
/// <param name="volumeName">Receives the name of a specified volume.</param>
7166-
/// <param name="volumeSerialNumber">
7167-
/// Receives the volume serial number.
7168-
/// <para>
7169-
/// This function returns the volume serial number that the operating system assigns when a hard disk is formatted. To
7170-
/// programmatically obtain the hard disk's serial number that the manufacturer assigns, use the Windows Management Instrumentation
7171-
/// (WMI) Win32_PhysicalMedia property SerialNumber.
7172-
/// </para>
7173-
/// </param>
7174-
/// <param name="maximumComponentLength">
7175-
/// Receives the maximum length, in characters, of a file name component that a specified file system supports.
7176-
/// <para>A file name component is the portion of a file name between backslashes.</para>
7177-
/// <para>
7178-
/// The value that is stored in the variable that <paramref name="maximumComponentLength"/> returns is used to indicate that a
7179-
/// specified file system supports long names. For example, for a FAT file system that supports long names, the function stores the
7180-
/// value 255, rather than the previous 8.3 indicator. Long names can also be supported on systems that use the NTFS file system.
7181-
/// </para>
7182-
/// </param>
7183-
/// <param name="fileSystemFlags">
7184-
/// Receives the flags associated with the specified file system.
7185-
/// <para>
7186-
/// This parameter can be one or more of the <c>FileSystemFlags</c> values. However, FILE_FILE_COMPRESSION and FILE_VOL_IS_COMPRESSED
7187-
/// are mutually exclusive.
7188-
/// </para>
7189-
/// </param>
7190-
/// <param name="fileSystemName">Receives the name of the file system, for example, the FAT file system or the NTFS file system.</param>
7191-
/// <returns>
7192-
/// If all the requested information is retrieved, the return value is nonzero.
7193-
/// <para>If not all the requested information is retrieved, the return value is zero. To get extended error information, call GetLastError.</para>
7194-
/// </returns>
7195-
/// <remarks>
7196-
/// When a user attempts to get information about a floppy drive that does not have a floppy disk, or a CD-ROM drive that does not
7197-
/// have a compact disc, the system displays a message box for the user to insert a floppy disk or a compact disc, respectively. To
7198-
/// prevent the system from displaying this message box, call the SetErrorMode function with SEM_FAILCRITICALERRORS.
7199-
/// <para>
7200-
/// The FILE_VOL_IS_COMPRESSED flag is the only indicator of volume-based compression. The file system name is not altered to
7201-
/// indicate compression, for example, this flag is returned set on a DoubleSpace volume. When compression is volume-based, an entire
7202-
/// volume is compressed or not compressed.
7203-
/// </para>
7204-
/// <para>
7205-
/// The FILE_FILE_COMPRESSION flag indicates whether a file system supports file-based compression. When compression is file-based,
7206-
/// individual files can be compressed or not compressed.
7207-
/// </para>
7208-
/// <para>The FILE_FILE_COMPRESSION and FILE_VOL_IS_COMPRESSED flags are mutually exclusive. Both bits cannot be returned set.</para>
7209-
/// <para>
7210-
/// The maximum component length value that is stored in lpMaximumComponentLength is the only indicator that a volume supports
7211-
/// longer-than-normal FAT file system (or other file system) file names. The file system name is not altered to indicate support for
7212-
/// long file names.
7213-
/// </para>
7214-
/// <para>
7215-
/// The GetCompressedFileSize function obtains the compressed size of a file. The GetFileAttributes function can determine whether an
7216-
/// individual file is compressed.
7217-
/// </para>
7218-
/// <para>Symbolic link behavior�</para>
7219-
/// <para>If the path points to a symbolic link, the function returns volume information for the target.</para>
7220-
/// </remarks>
7221-
[PInvokeData("FileAPI.h", MSDNShortId = "aa364993")]
7222-
public static bool GetVolumeInformation([Optional] string? rootPathName, out string volumeName, out uint volumeSerialNumber,
7223-
out uint maximumComponentLength, out FileSystemFlags fileSystemFlags, out string fileSystemName)
7224-
{
7225-
StringBuilder sb1 = new(MAX_PATH + 1), sb2 = new(MAX_PATH + 1);
7226-
var ret = GetVolumeInformation(rootPathName, sb1, sb1.Capacity, out volumeSerialNumber, out maximumComponentLength, out fileSystemFlags, sb2, sb2.Capacity);
7227-
volumeName = sb1.ToString();
7228-
fileSystemName = sb2.ToString();
7229-
return ret;
7230-
}
7155+
[SizeDef(nameof(nFileSystemNameSize))] StringBuilder? lpFileSystemNameBuffer, [Range(0, MAX_PATH + 1)] int nFileSystemNameSize);
72317156

72327157
/// <summary>
72337158
/// <para>Retrieves information about the file system and volume associated with the specified file.</para>
@@ -7392,164 +7317,7 @@ public static bool GetVolumeInformation([Optional] string? rootPathName, out str
73927317
[return: MarshalAs(UnmanagedType.Bool)]
73937318
public static extern bool GetVolumeInformationByHandleW([In, AddAsMember] HFILE hFile, [SizeDef(nameof(nVolumeNameSize))] StringBuilder? lpVolumeNameBuffer,
73947319
[Range(0, MAX_PATH + 1)] uint nVolumeNameSize, out uint lpVolumeSerialNumber, out uint lpMaximumComponentLength, out FileSystemFlags lpFileSystemFlags,
7395-
[SizeDef(nameof(nVolumeNameSize))] StringBuilder? lpFileSystemNameBuffer, [Range(0, MAX_PATH + 1)] uint nFileSystemNameSize);
7396-
7397-
/// <summary>
7398-
/// <para>Retrieves information about the file system and volume associated with the specified file.</para>
7399-
/// <para>To retrieve the current compression state of a file or directory, use <c>FSCTL_GET_COMPRESSION</c>.</para>
7400-
/// </summary>
7401-
/// <param name="hFile">A handle to the file.</param>
7402-
/// <param name="lpVolumeNameBuffer">
7403-
/// A pointer to a buffer that receives the name of a specified volume. The maximum buffer size is .
7404-
/// </param>
7405-
/// <param name="lpVolumeSerialNumber">
7406-
/// <para>A pointer to a variable that receives the volume serial number.</para>
7407-
/// <para>
7408-
/// This function returns the volume serial number that the operating system assigns when a hard disk is formatted. To programmatically
7409-
/// obtain the hard disk's serial number that the manufacturer assigns, use the Windows Management Instrumentation (WMI)
7410-
/// <c>Win32_PhysicalMedia</c> property <c>SerialNumber</c>.
7411-
/// </para>
7412-
/// </param>
7413-
/// <param name="lpMaximumComponentLength">
7414-
/// <para>
7415-
/// A pointer to a variable that receives the maximum length, in <c>WCHAR</c> s, of a file name component that a specified file system supports.
7416-
/// </para>
7417-
/// <para>A file name component is the portion of a file name between backslashes.</para>
7418-
/// <para>
7419-
/// The value that is stored in the variable that *lpMaximumComponentLength points to is used to indicate that a specified file system
7420-
/// supports long names. For example, for a FAT file system that supports long names, the function stores the value 255, rather than the
7421-
/// previous 8.3 indicator. Long names can also be supported on systems that use the NTFS file system.
7422-
/// </para>
7423-
/// </param>
7424-
/// <param name="lpFileSystemFlags">
7425-
/// <para>A pointer to a variable that receives flags associated with the specified file system.</para>
7426-
/// <para>
7427-
/// This parameter can be one or more of the following flags. However, <c>FILE_FILE_COMPRESSION</c> and <c>FILE_VOL_IS_COMPRESSED</c> are
7428-
/// mutually exclusive.
7429-
/// </para>
7430-
/// <para>
7431-
/// <list type="table">
7432-
/// <listheader>
7433-
/// <term>Value</term>
7434-
/// <term>Meaning</term>
7435-
/// </listheader>
7436-
/// <item>
7437-
/// <term>FILE_CASE_PRESERVED_NAMES0x00000002</term>
7438-
/// <term>The specified volume supports preserved case of file names when it places a name on disk.</term>
7439-
/// </item>
7440-
/// <item>
7441-
/// <term>FILE_CASE_SENSITIVE_SEARCH0x00000001</term>
7442-
/// <term>The specified volume supports case-sensitive file names.</term>
7443-
/// </item>
7444-
/// <item>
7445-
/// <term>FILE_FILE_COMPRESSION0x00000010</term>
7446-
/// <term>The specified volume supports file-based compression.</term>
7447-
/// </item>
7448-
/// <item>
7449-
/// <term>FILE_NAMED_STREAMS0x00040000</term>
7450-
/// <term>The specified volume supports named streams.</term>
7451-
/// </item>
7452-
/// <item>
7453-
/// <term>FILE_PERSISTENT_ACLS0x00000008</term>
7454-
/// <term>
7455-
/// The specified volume preserves and enforces access control lists (ACL). For example, the NTFS file system preserves and enforces
7456-
/// ACLs, and the FAT file system does not.
7457-
/// </term>
7458-
/// </item>
7459-
/// <item>
7460-
/// <term>FILE_READ_ONLY_VOLUME0x00080000</term>
7461-
/// <term>The specified volume is read-only.</term>
7462-
/// </item>
7463-
/// <item>
7464-
/// <term>FILE_SEQUENTIAL_WRITE_ONCE0x00100000</term>
7465-
/// <term>The specified volume supports a single sequential write.</term>
7466-
/// </item>
7467-
/// <item>
7468-
/// <term>FILE_SUPPORTS_ENCRYPTION0x00020000</term>
7469-
/// <term>The specified volume supports the Encrypted File System (EFS). For more information, see File Encryption.</term>
7470-
/// </item>
7471-
/// <item>
7472-
/// <term>FILE_SUPPORTS_EXTENDED_ATTRIBUTES0x00800000</term>
7473-
/// <term>
7474-
/// The specified volume supports extended attributes. An extended attribute is a piece of application-specific metadata that an
7475-
/// application can associate with a file and is not part of the file's data.Windows Vista and Windows Server 2008: This value is not supported.
7476-
/// </term>
7477-
/// </item>
7478-
/// <item>
7479-
/// <term>FILE_SUPPORTS_HARD_LINKS0x00400000</term>
7480-
/// <term>
7481-
/// The specified volume supports hard links. For more information, see Hard Links and Junctions.Windows Vista and Windows Server
7482-
/// 2008: This value is not supported.
7483-
/// </term>
7484-
/// </item>
7485-
/// <item>
7486-
/// <term>FILE_SUPPORTS_OBJECT_IDS0x00010000</term>
7487-
/// <term>The specified volume supports object identifiers.</term>
7488-
/// </item>
7489-
/// <item>
7490-
/// <term>FILE_SUPPORTS_OPEN_BY_FILE_ID0x01000000</term>
7491-
/// <term>
7492-
/// The file system supports open by FileID. For more information, see FILE_ID_BOTH_DIR_INFO.Windows Vista and Windows Server 2008: This
7493-
/// value is not supported.
7494-
/// </term>
7495-
/// </item>
7496-
/// <item>
7497-
/// <term>FILE_SUPPORTS_REPARSE_POINTS0x00000080</term>
7498-
/// <term>The specified volume supports re-parse points.</term>
7499-
/// </item>
7500-
/// <item>
7501-
/// <term>FILE_SUPPORTS_SPARSE_FILES0x00000040</term>
7502-
/// <term>The specified volume supports sparse files.</term>
7503-
/// </item>
7504-
/// <item>
7505-
/// <term>FILE_SUPPORTS_TRANSACTIONS0x00200000</term>
7506-
/// <term>The specified volume supports transactions. For more information, see About KTM.</term>
7507-
/// </item>
7508-
/// <item>
7509-
/// <term>FILE_SUPPORTS_USN_JOURNAL0x02000000</term>
7510-
/// <term>
7511-
/// The specified volume supports update sequence number (USN) journals. For more information, see Change Journal Records.Windows Vista
7512-
/// and Windows Server 2008: This value is not supported.
7513-
/// </term>
7514-
/// </item>
7515-
/// <item>
7516-
/// <term>FILE_UNICODE_ON_DISK0x00000004</term>
7517-
/// <term>The specified volume supports Unicode in file names as they appear on disk.</term>
7518-
/// </item>
7519-
/// <item>
7520-
/// <term>FILE_VOLUME_IS_COMPRESSED0x00008000</term>
7521-
/// <term>The specified volume is a compressed volume.</term>
7522-
/// </item>
7523-
/// <item>
7524-
/// <term>FILE_VOLUME_QUOTAS0x00000020</term>
7525-
/// <term>The specified volume supports disk quotas.</term>
7526-
/// </item>
7527-
/// </list>
7528-
/// </para>
7529-
/// </param>
7530-
/// <param name="lpFileSystemNameBuffer">
7531-
/// A pointer to a buffer that receives the name of the file system, for example, the FAT file system or the NTFS file system. The buffer
7532-
/// size is specified by the nFileSystemNameSize parameter.
7533-
/// </param>
7534-
/// <returns>
7535-
/// <para>If all the requested information is retrieved, the return value is nonzero.</para>
7536-
/// <para>If not all the requested information is retrieved, the return value is zero. To get extended error information, call <c>GetLastError</c>.</para>
7537-
/// </returns>
7538-
// BOOL WINAPI GetVolumeInformationByHandleW( _In_ HANDLE hFile, _Out_opt_ LPWSTR lpVolumeNameBuffer, _In_ DWORD nVolumeNameSize,
7539-
// _Out_opt_ LPDWORD lpVolumeSerialNumber, _Out_opt_ LPDWORD lpMaximumComponentLength, _Out_opt_ LPDWORD lpFileSystemFlags, _Out_opt_
7540-
// LPWSTR lpFileSystemNameBuffer, _In_ DWORD nFileSystemNameSize);
7541-
[PInvokeData("FileAPI.h", MSDNShortId = "aa964920")]
7542-
[return: MarshalAs(UnmanagedType.Bool)]
7543-
public static bool GetVolumeInformationByHandleW([In, AddAsMember] HFILE hFile, out string lpVolumeNameBuffer, out uint lpVolumeSerialNumber,
7544-
out uint lpMaximumComponentLength, out FileSystemFlags lpFileSystemFlags, out string lpFileSystemNameBuffer)
7545-
{
7546-
StringBuilder volName = new(MAX_PATH + 1), fsName = new(MAX_PATH + 1);
7547-
var ret = GetVolumeInformationByHandleW(hFile, volName, (uint)volName.Capacity, out lpVolumeSerialNumber, out lpMaximumComponentLength,
7548-
out lpFileSystemFlags, fsName, (uint)fsName.Capacity);
7549-
lpVolumeNameBuffer = volName.ToString();
7550-
lpFileSystemNameBuffer = fsName.ToString();
7551-
return ret;
7552-
}
7320+
[SizeDef(nameof(nFileSystemNameSize))] StringBuilder? lpFileSystemNameBuffer, [Range(0, MAX_PATH + 1)] uint nFileSystemNameSize);
75537321

75547322
/// <summary>
75557323
/// <para>
@@ -7924,7 +7692,9 @@ public static IEnumerable<string> QueryDosDevice([Optional] string? deviceName)
79247692
mem.Size = bytes *= 4;
79257693
retLen = QueryDosDevice(deviceName, mem, mem.Size / Marshal.SystemDefaultCharSize);
79267694
} while (retLen == 0 && Win32Error.GetLastError() == Win32Error.ERROR_INSUFFICIENT_BUFFER);
7927-
if (retLen == 0) throw new Win32Exception();
7695+
if (deviceName is not null && retLen == 0 && Win32Error.GetLastError() == Win32Error.ERROR_FILE_NOT_FOUND)
7696+
return [];
7697+
Win32Error.ThrowLastErrorIfFalse(retLen != 0);
79287698
return [.. mem.ToStringEnum()];
79297699

79307700
[DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)]

PInvoke/Kernel32/LibLoaderApi.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,7 @@ public static IReadOnlyList<ResourceId> EnumResourceTypesEx([In, AddAsMember] HI
13221322
// DWORD WINAPI GetModuleFileName( _In_opt_ HMODULE hModule, _Out_ LPTSTR lpFilename, _In_ DWORD nSize); https://msdn.microsoft.com/en-us/library/windows/desktop/ms683197(v=vs.85).aspx
13231323
[DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)]
13241324
[PInvokeData("Winbase.h", MSDNShortId = "ms683197")]
1325-
public static extern uint GetModuleFileName(HINSTANCE hModule, [SizeDef(nameof(nSize), SizingMethod.Query | SizingMethod.CheckLastError)] StringBuilder? lpFilename, uint nSize);
1325+
public static extern uint GetModuleFileName(HINSTANCE hModule, [SizeDef(nameof(nSize), SizingMethod.Guess)] StringBuilder? lpFilename, uint nSize);
13261326

13271327
/// <summary>
13281328
/// Retrieves the fully qualified path for the file that contains the specified module. The module must have been loaded by the
@@ -1974,7 +1974,7 @@ public static string GetModuleFileName([In, AddAsMember] HINSTANCE hModule)
19741974
[DllImport(Lib.KernelBase, SetLastError = true, ExactSpelling = true)]
19751975
[PInvokeData("libloaderapi2.h", MSDNShortId = "43690689-4372-48ae-ac6d-230250f05f7c")]
19761976
[return: MarshalAs(UnmanagedType.Bool)]
1977-
public static extern bool QueryOptionalDelayLoadedAPI([In, AddAsMember] HINSTANCE hParentModule, [MarshalAs(UnmanagedType.LPStr)] string? lpDllName, [MarshalAs(UnmanagedType.LPStr)] string lpProcName, [Ignore] uint Reserved = 0);
1977+
public static extern bool QueryOptionalDelayLoadedAPI([In, AddAsMember] HINSTANCE hParentModule, [MarshalAs(UnmanagedType.LPStr)] string? lpDllName, [MarshalAs(UnmanagedType.LPStr)] string lpProcName, [Optional] uint Reserved);
19781978

19791979
/// <summary>Removes a directory that was added to the process DLL search path by using <c>AddDllDirectory</c>.</summary>
19801980
/// <param name="Cookie">The cookie returned by <c>AddDllDirectory</c> when the directory was added to the search path.</param>

0 commit comments

Comments
 (0)