From def1172b2552d31c7b79b6c66493e18c422a5fd5 Mon Sep 17 00:00:00 2001 From: dahall Date: Thu, 21 Jan 2021 09:54:15 -0700 Subject: [PATCH] Added more SetupAPI functions --- PInvoke/SetupAPI/SetupAPI.Funcs.cs | 266 +++++++++++++++++++++++++++-- 1 file changed, 255 insertions(+), 11 deletions(-) diff --git a/PInvoke/SetupAPI/SetupAPI.Funcs.cs b/PInvoke/SetupAPI/SetupAPI.Funcs.cs index 4d6a8190f..276603dba 100644 --- a/PInvoke/SetupAPI/SetupAPI.Funcs.cs +++ b/PInvoke/SetupAPI/SetupAPI.Funcs.cs @@ -1070,6 +1070,50 @@ public static extern uint SetupDecompressOrCopyFile([MarshalAs(UnmanagedType.LPT [PInvokeData("setupapi.h", MSDNShortId = "NF:setupapi.SetupDefaultQueueCallbackA")] public static extern FILEOP_RESULT SetupDefaultQueueCallback([In] IntPtr Context, SPFILENOTIFY Notification, [In] IntPtr Param1, [In] IntPtr Param2); + /// + /// + /// [This function is available for use in the operating systems indicated in the Requirements section. It may be altered or + /// unavailable in subsequent versions. SetupAPI should no longer be used for installing applications. Instead, use the Windows + /// Installer for developing application installers. SetupAPI continues to be used for installing device drivers.] + /// + /// The SetupDeleteError function generates a dialog box that informs the user of a delete error. + /// + /// Handle to the parent window for this dialog box. + /// + /// Optional pointer to a null-terminated string specifying the error dialog box title. If this parameter is NULL, the + /// default title of "Delete Error" (localized) is used. + /// + /// + /// Pointer to a null-terminated string specifying the full path of the file on which the delete operation failed. + /// + /// The system error code encountered during the file operation. + /// + /// Flags that control display formatting and behavior of the dialog box. This parameter can be one of the following flags. + /// IDF_NOBEEP + /// Prevent the dialog box from beeping to get the user's attention when it first appears. + /// IDF_NOFOREGROUND + /// Prevent the dialog box from becoming the foreground window. + /// + /// + /// This function returns one of the following values. + /// To get extended error information, call GetLastError. + /// + /// + /// Note + /// + /// The setupapi.h header defines SetupDeleteError as an alias which automatically selects the ANSI or Unicode version of this + /// function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that + /// not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions + /// for Function Prototypes. + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/setupapi/nf-setupapi-setupdeleteerrora WINSETUPAPI UINT SetupDeleteErrorA( + // HWND hwndParent, PCSTR DialogTitle, PCSTR File, UINT Win32ErrorCode, DWORD Style ); + [DllImport(Lib_SetupAPI, SetLastError = true, CharSet = CharSet.Auto)] + [PInvokeData("setupapi.h", MSDNShortId = "NF:setupapi.SetupDeleteErrorA")] + public static extern uint SetupDeleteError(HWND hwndParent, [Optional, MarshalAs(UnmanagedType.LPTStr)] string DialogTitle, + [MarshalAs(UnmanagedType.LPTStr)] string File, Win32Error Win32ErrorCode, IDF Style); + /// /// /// [This function is available for use in the operating systems indicated in the Requirements section. It may be altered or @@ -1090,6 +1134,217 @@ public static extern uint SetupDecompressOrCopyFile([MarshalAs(UnmanagedType.LPT [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetupDestroyDiskSpaceList(HDSKSPC DiskSpace); + /// + /// + /// [This function is available for use in the operating systems indicated in the Requirements section. It may be altered or + /// unavailable in subsequent versions. SetupAPI should no longer be used for installing applications. Instead, use the Windows + /// Installer for developing application installers. SetupAPI continues to be used for installing device drivers.] + /// + /// The SetupDuplicateDiskSpaceList function duplicates a disk-space list as a new independent disk-space list. + /// + /// Handle to the disk-space list to be duplicated. + /// Unused, must be zero. + /// Unused, must be zero. + /// Unused, must be zero. + /// + /// If the function succeeds, it returns a handle to the new disk-space list. + /// If the function fails, it returns null. To get extended error information, call GetLastError. + /// + /// + /// Note + /// + /// The setupapi.h header defines SetupDuplicateDiskSpaceList as an alias which automatically selects the ANSI or Unicode version of + /// this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code + /// that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see + /// Conventions for Function Prototypes. + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/setupapi/nf-setupapi-setupduplicatediskspacelista WINSETUPAPI HDSKSPC + // SetupDuplicateDiskSpaceListA( HDSKSPC DiskSpace, PVOID Reserved1, DWORD Reserved2, UINT Flags ); + [DllImport(Lib_SetupAPI, SetLastError = true, CharSet = CharSet.Auto)] + [PInvokeData("setupapi.h", MSDNShortId = "NF:setupapi.SetupDuplicateDiskSpaceListA")] + public static extern SafeHDSKSPC SetupDuplicateDiskSpaceList(HDSKSPC DiskSpace, IntPtr Reserved1 = default, uint Reserved2 = default, uint Flags = default); + + /// + /// + /// [This function is available for use in the operating systems indicated in the Requirements section. It may be altered or + /// unavailable in subsequent versions. SetupAPI should no longer be used for installing applications. Instead, use the Windows + /// Installer for developing application installers. SetupAPI continues to be used for installing device drivers.] + /// + /// The SetupEnumInfSections function retrieves section names from an INF file. + /// + /// Handle to the INF file that is to be queried. + /// + /// The zero-based index of the section name to retrieve. This index may not correspond to the order of sections as they appear in + /// the INF file. + /// + /// + /// Pointer to a buffer that receives the section name. You can call the function once to get the required buffer size, allocate the + /// necessary memory, and then call the function a second time to retrieve the name. Using this technique, you can avoid errors + /// caused by an insufficient buffer size. This parameter is optional. For more information, see the Remarks section. + /// + /// + /// Size of the buffer pointed to by ReturnBuffer in characters. This number includes the terminating NULL character. + /// + /// + /// Pointer to a location that receives the required size of the buffer pointed to by ReturnBuffer. The size is specified as the + /// number of characters required to store the section name, including the terminating NULL character. + /// + /// + /// If the function succeeds, the return value is TRUE. + /// If the function fails, the return value is FALSE. To get extended error information, call GetLastError. + /// + /// GetLastError returns ERROR_NO_MORE_ITEMS if the value of EnumerationIndex is greater than or equal to the number + /// of sections names in the INF file. + /// + /// + /// + /// + /// This function can enumerate all unique section names in the INF file. If a section name appears more than once in an INF file, + /// the function returns the name only once using a single enumeration index. To return all section names in the INF file, call the + /// function beginning with an enumeration index of zero and then make repeated calls to the function while incrementing the index + /// until the function returns FALSE and GetLastError returns ERROR_NO_MORE_ITEMS. Your application should not rely on + /// the section names being returned in any order based on the enumeration index. + /// + /// + /// Note + /// + /// The setupapi.h header defines SetupEnumInfSections as an alias which automatically selects the ANSI or Unicode version of this + /// function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that + /// not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions + /// for Function Prototypes. + /// + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/setupapi/nf-setupapi-setupenuminfsectionsa WINSETUPAPI BOOL + // SetupEnumInfSectionsA( HINF InfHandle, UINT Index, PSTR Buffer, UINT Size, UINT *SizeNeeded ); + [DllImport(Lib_SetupAPI, SetLastError = true, CharSet = CharSet.Auto)] + [PInvokeData("setupapi.h", MSDNShortId = "NF:setupapi.SetupEnumInfSectionsA")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool SetupEnumInfSections(HINF InfHandle, uint Index, [Out, MarshalAs(UnmanagedType.LPTStr)] StringBuilder Buffer, uint Size, out uint SizeNeeded); + + /// + /// + /// [This function is available for use in the operating systems indicated in the Requirements section. It may be altered or + /// unavailable in subsequent versions. SetupAPI should no longer be used for installing applications. Instead, use the Windows + /// Installer for developing application installers. SetupAPI continues to be used for installing device drivers.] + /// + /// + /// The SetupFindFirstLine function locates a line in the specified section of an INF file. If the Key parameter is + /// NULL, SetupFindFirstLine returns the first line of the section. + /// + /// + /// Handle to the INF file to query. + /// Pointer to a null-terminated string specifying the section of the INF files to search in. + /// + /// Optional pointer to a null-terminated string specifying the key to search for within the section. The + /// null-terminated string should not exceed the size of the destination buffer. This parameter can be NULL. If Key is + /// NULL, the first line in the section is returned. + /// + /// + /// Pointer to a structure that receives the context information used internally by the INF handle. Applications must not overwrite + /// values in this structure. + /// + /// If the function could not find a line, the return value is zero. To get extended error information, call GetLastError. + /// + /// + /// If the InfHandle parameter references multiple INF files that have been appended together using SetupOpenAppendInfFile, the + /// SetupFindFirstLine function searches across the specified section in all of the files referenced by the specified HINF. + /// + /// + /// Note + /// + /// The setupapi.h header defines SetupFindFirstLine as an alias which automatically selects the ANSI or Unicode version of this + /// function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that + /// not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions + /// for Function Prototypes. + /// + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/setupapi/nf-setupapi-setupfindfirstlinea WINSETUPAPI BOOL SetupFindFirstLineA( + // HINF InfHandle, PCSTR Section, PCSTR Key, PINFCONTEXT Context ); + [DllImport(Lib_SetupAPI, SetLastError = true, CharSet = CharSet.Auto)] + [PInvokeData("setupapi.h", MSDNShortId = "NF:setupapi.SetupFindFirstLineA")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool SetupFindFirstLine(HINF InfHandle, [MarshalAs(UnmanagedType.LPTStr)] string Section, + [Optional, MarshalAs(UnmanagedType.LPTStr)] string Key, out INFCONTEXT Context); + + /// + /// + /// [This function is available for use in the operating systems indicated in the Requirements section. It may be altered or + /// unavailable in subsequent versions. SetupAPI should no longer be used for installing applications. Instead, use the Windows + /// Installer for developing application installers. SetupAPI continues to be used for installing device drivers.] + /// + /// The SetupFindNextLine returns the location of the next line in an INF file section relative to ContextIn.Line. + /// + /// Pointer to the INF file context retrieved by a call to the SetupFindFirstLine function. + /// + /// Pointer to a variable in which this function returns the context of the found line. ContextOut can point to ContextIn if the + /// caller wishes. + /// + /// + /// If this function finds the next line, the return value is a nonzero value. Otherwise, the return value is zero. To get extended + /// error information, call GetLastError. + /// + /// + /// If ContextIn.Line references multiple INF files that have been appended together using SetupOpenAppendInfFile, this function + /// searches across the specified section in all files referenced by the HINF to locate the next line. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/setupapi/nf-setupapi-setupfindnextline WINSETUPAPI BOOL SetupFindNextLine( + // PINFCONTEXT ContextIn, PINFCONTEXT ContextOut ); + [DllImport(Lib_SetupAPI, SetLastError = true, ExactSpelling = true)] + [PInvokeData("setupapi.h", MSDNShortId = "NF:setupapi.SetupFindNextLine")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool SetupFindNextLine(in INFCONTEXT ContextIn, out INFCONTEXT ContextOut); + + /// + /// + /// [This function is available for use in the operating systems indicated in the Requirements section. It may be altered or + /// unavailable in subsequent versions. SetupAPI should no longer be used for installing applications. Instead, use the Windows + /// Installer for developing application installers. SetupAPI continues to be used for installing device drivers.] + /// + /// + /// The SetupFindNextMatchLine function returns the location of the next line in an INF file relative to ContextIn.Line that + /// matches a specified key. + /// + /// + /// Pointer to an INF file context, as retrieved by a call to the SetupFindFirstLine function. + /// + /// If this optional parameter is specified, it supplies a key to match. This parameter should be a null-terminated string. This + /// parameter can be Null. If Key is not specified, the SetupFindNextMatchLine function is equivalent to the + /// SetupFindNextLine function. + /// + /// + /// Pointer to a variable in which this function returns the context of the found line. ContextOut can point to ContextIn if the + /// caller wishes. + /// + /// + /// The function returns a nonzero value if it finds a matching line. Otherwise, the return value is zero. To get extended error + /// information, call GetLastError. + /// + /// + /// + /// If ContextIn.Inf references multiple INF files that have been appended together using SetupOpenAppendInfFile, the + /// SetupFindNextMatchLine function searches across the specified section in all files referenced by the HINF to locate the + /// next matching line. + /// + /// + /// Note + /// + /// The setupapi.h header defines SetupFindNextMatchLine as an alias which automatically selects the ANSI or Unicode version of this + /// function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that + /// not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions + /// for Function Prototypes. + /// + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/setupapi/nf-setupapi-setupfindnextmatchlinea WINSETUPAPI BOOL + // SetupFindNextMatchLineA( PINFCONTEXT ContextIn, PCSTR Key, PINFCONTEXT ContextOut ); + [DllImport(Lib_SetupAPI, SetLastError = true, CharSet = CharSet.Auto)] + [PInvokeData("setupapi.h", MSDNShortId = "NF:setupapi.SetupFindNextMatchLineA")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool SetupFindNextMatchLine(in INFCONTEXT ContextIn, [Optional, MarshalAs(UnmanagedType.LPTStr)] string Key, out INFCONTEXT ContextOut); + /// /// /// [This function is available for use in the operating systems indicated in the Requirements section. It may be altered or @@ -1276,17 +1531,6 @@ private SafeHINF() : base() { } } /* - SetupDeleteErrorA - SetupDeleteErrorW - SetupDuplicateDiskSpaceListA - SetupDuplicateDiskSpaceListW - SetupEnumInfSectionsA - SetupEnumInfSectionsW - SetupFindFirstLineA - SetupFindFirstLineW - SetupFindNextLine - SetupFindNextMatchLineA - SetupFindNextMatchLineW SetupFreeSourceListA SetupFreeSourceListW SetupGetBinaryField