Skip to content
This repository was archived by the owner on Jul 26, 2023. It is now read-only.

Commit 2c7169b

Browse files
authored
Merge pull request #343 from AArnott/fix342
Fix ApiSets used for AdvApi32
2 parents 54be712 + 4d09bb6 commit 2c7169b

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

src/AdvApi32/AdvApi32.cs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,19 @@ public static partial class AdvApi32
3030
private const string api_ms_win_core_processthreads_l1_1_1 = ApiSets.api_ms_win_core_processthreads_l1_1_1;
3131
private const string api_ms_win_security_base_l1_2_0 = ApiSets.api_ms_win_security_base_l1_2_0;
3232
private const string api_ms_win_service_winsvc_l1_2_0 = ApiSets.api_ms_win_service_winsvc_l1_2_0;
33+
private const string api_ms_win_security_sddl_l1_1_0 = ApiSets.api_ms_win_security_sddl_l1_1_0;
34+
private const string api_ms_win_core_processthreads_l1_1_2 = ApiSets.api_ms_win_core_processthreads_l1_1_2;
35+
private const string api_ms_win_core_registry_l1_1_0 = ApiSets.api_ms_win_core_registry_l1_1_0;
3336
#else
3437
private const string api_ms_win_service_core_l1_1_1 = nameof(AdvApi32);
3538
private const string api_ms_win_service_management_l1_1_0 = nameof(AdvApi32);
3639
private const string api_ms_win_service_management_l2_1_0 = nameof(AdvApi32);
3740
private const string api_ms_win_core_processthreads_l1_1_1 = nameof(AdvApi32);
3841
private const string api_ms_win_security_base_l1_2_0 = nameof(AdvApi32);
3942
private const string api_ms_win_service_winsvc_l1_2_0 = nameof(AdvApi32);
43+
private const string api_ms_win_security_sddl_l1_1_0 = nameof(AdvApi32);
44+
private const string api_ms_win_core_processthreads_l1_1_2 = nameof(AdvApi32);
45+
private const string api_ms_win_core_registry_l1_1_0 = nameof(AdvApi32);
4046
#endif
4147
#pragma warning restore SA1303 // Const field names must begin with upper-case letter
4248

@@ -318,7 +324,7 @@ public static extern bool ChangeServiceConfig(
318324
/// If the function succeeds, the return value is nonzero.
319325
/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
320326
/// </returns>
321-
[DllImport(api_ms_win_service_management_l1_1_0, SetLastError = true)]
327+
[DllImport(api_ms_win_service_winsvc_l1_2_0, SetLastError = true)]
322328
[return: MarshalAs(UnmanagedType.Bool)]
323329
public static extern bool ControlService(SafeServiceHandle hService, ServiceControl dwControl, ref SERVICE_STATUS lpServiceStatus);
324330

@@ -419,7 +425,7 @@ public static extern bool ChangeServiceConfig(
419425
/// If the function succeeds, the return value is nonzero.
420426
/// If the function fails, the return value is zero.
421427
/// </returns>
422-
[DllImport(api_ms_win_service_management_l1_1_0, SetLastError = true)]
428+
[DllImport(nameof(AdvApi32), SetLastError = true)]
423429
[return: MarshalAs(UnmanagedType.Bool)]
424430
public static extern unsafe bool CryptGetProvParam(
425431
SafeHandle hProv,
@@ -447,7 +453,7 @@ public static extern unsafe bool CryptGetProvParam(
447453
/// If the function succeeds, the return value is nonzero.
448454
/// If the function fails, the return value is zero.
449455
/// </returns>
450-
[DllImport(api_ms_win_service_management_l1_1_0, SetLastError = true)]
456+
[DllImport(nameof(AdvApi32), SetLastError = true)]
451457
[return: MarshalAs(UnmanagedType.Bool)]
452458
public static extern unsafe bool CryptSetProvParam(
453459
SafeHandle hProv,
@@ -556,7 +562,7 @@ public static extern unsafe bool CryptSetProvParam(
556562
/// <see cref="GetLastError" />.
557563
/// </para>
558564
/// </returns>
559-
[DllImport(api_ms_win_core_processthreads_l1_1_1, SetLastError = true)]
565+
[DllImport(api_ms_win_core_processthreads_l1_1_2, SetLastError = true)]
560566
[return: MarshalAs(UnmanagedType.Bool)]
561567
public static extern bool OpenProcessToken(
562568
IntPtr processHandle,
@@ -887,7 +893,7 @@ public static unsafe extern bool EnumServicesStatus(
887893
/// If the function succeeds, the return value is <see cref="Win32ErrorCode.ERROR_SUCCESS" />. If the function
888894
/// fails the error code is returned.
889895
/// </returns>
890-
[DllImport(nameof(AdvApi32), CharSet = CharSet.Unicode)]
896+
[DllImport(api_ms_win_core_registry_l1_1_0, CharSet = CharSet.Unicode)]
891897
public static extern Win32ErrorCode RegOpenKeyEx(
892898
SafeRegistryHandle hKey,
893899
string lpSubKey,
@@ -914,7 +920,7 @@ public static extern Win32ErrorCode RegOpenKeyEx(
914920
/// If the function succeeds, the return value is <see cref="Win32ErrorCode.ERROR_SUCCESS" />. If the function
915921
/// fails the error code is returned.
916922
/// </returns>
917-
[DllImport(nameof(AdvApi32))]
923+
[DllImport(api_ms_win_core_registry_l1_1_0)]
918924
public static extern Win32ErrorCode RegFlushKey(SafeRegistryHandle hKey);
919925

920926
/// <summary>Notifies the caller about changes to the attributes or contents of a specified registry key.</summary>
@@ -959,7 +965,7 @@ public static extern Win32ErrorCode RegOpenKeyEx(
959965
/// If the function succeeds, the return value is <see cref="Win32ErrorCode.ERROR_SUCCESS" />. If the function
960966
/// fails the error code is returned.
961967
/// </returns>
962-
[DllImport(nameof(AdvApi32))]
968+
[DllImport(api_ms_win_core_registry_l1_1_0)]
963969
public static extern Win32ErrorCode RegNotifyChangeKeyValue(
964970
SafeRegistryHandle hKey,
965971
bool bWatchSubtree,
@@ -990,7 +996,7 @@ public static extern Win32ErrorCode RegNotifyChangeKeyValue(
990996
/// If the function succeeds, the return value is nonzero.
991997
/// If the function fails, the return value is zero. To get extended error information, call <see cref="GetLastError"/>.
992998
/// </returns>
993-
[DllImport(nameof(AdvApi32), SetLastError = true)]
999+
[DllImport(api_ms_win_service_management_l2_1_0, SetLastError = true)]
9941000
[return: MarshalAs(UnmanagedType.Bool)]
9951001
public static unsafe extern bool QueryServiceStatusEx(
9961002
SafeServiceHandle hService,
@@ -1012,7 +1018,7 @@ public static unsafe extern bool QueryServiceStatusEx(
10121018
/// This function has been superseded by the <see cref="RegisterServiceCtrlHandlerEx(string, LPHANDLER_FUNCTION_EX, void*)"/> function.
10131019
/// A service can use either function, but the new function supports user-defined context data, and the new handler function supports additional extended control codes.
10141020
/// </remarks>
1015-
[DllImport(nameof(AdvApi32), CharSet = CharSet.Unicode)]
1021+
[DllImport(api_ms_win_service_winsvc_l1_2_0, CharSet = CharSet.Unicode)]
10161022
[Obsolete("Use LPHANDLER_FUNCTION_EX with RegisterServiceCtrlHandlerEx instead")]
10171023
#pragma warning disable CS0618 // Type or member is obsolete
10181024
public static extern IntPtr RegisterServiceCtrlHandler(string lpServiceName, LPHANDLER_FUNCTION lpHandlerProc);
@@ -1031,7 +1037,7 @@ public static unsafe extern bool QueryServiceStatusEx(
10311037
/// This function has been superseded by the <see cref="RegisterServiceCtrlHandlerEx(string, LPHANDLER_FUNCTION_EX, void*)"/> function.
10321038
/// A service can use either function, but the new function supports user-defined context data, and the new handler function supports additional extended control codes.
10331039
/// </remarks>
1034-
[DllImport(nameof(AdvApi32), CharSet = CharSet.Unicode)]
1040+
[DllImport(api_ms_win_service_core_l1_1_1, CharSet = CharSet.Unicode)]
10351041
public static unsafe extern IntPtr RegisterServiceCtrlHandlerEx(
10361042
string lpServiceName,
10371043
LPHANDLER_FUNCTION_EX lpHandlerProc,
@@ -1173,7 +1179,7 @@ public static unsafe extern bool DuplicateTokenEx(
11731179
/// If the function succeeds, the return value is <see cref="Win32ErrorCode.ERROR_SUCCESS" />.
11741180
/// If the function fails, the return value is a nonzero error code defined in Winerror.h. You can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error.
11751181
/// </returns>
1176-
[DllImport(nameof(AdvApi32))]
1182+
[DllImport(api_ms_win_core_registry_l1_1_0)]
11771183
internal static extern Win32ErrorCode RegCloseKey(IntPtr hKey);
11781184

11791185
/// <summary>
@@ -1184,7 +1190,7 @@ public static unsafe extern bool DuplicateTokenEx(
11841190
/// <param name="sidString">A pointer to a variable that receives a pointer to a null-terminated SID string. To free the returned buffer, call the <see cref="LocalFree(void*)"/> function.</param>
11851191
/// <returns>If the function succeeds, the return value is true, otherwise the return value is false.</returns>
11861192
/// <remarks>The ConvertSidToStringSid function uses the standard S-R-I-S-S… format for SID strings.</remarks>
1187-
[DllImport(nameof(AdvApi32), CharSet = CharSet.Unicode, SetLastError = true)]
1193+
[DllImport(api_ms_win_security_sddl_l1_1_0, CharSet = CharSet.Unicode, SetLastError = true)]
11881194
[return: MarshalAs(UnmanagedType.Bool)]
11891195
private static unsafe extern bool ConvertSidToStringSid(
11901196
IntPtr sid,
@@ -1197,7 +1203,7 @@ private static unsafe extern bool ConvertSidToStringSid(
11971203
/// <param name="StringSid">The string-format SID to convert. The SID string can use either the standard S-R-I-S-S… format for SID strings, or the SID string constant format, such as "BA" for built-in administrators.</param>
11981204
/// <param name="sid">A pointer to a variable that receives a pointer to the converted SID. To free the returned buffer, call the <see cref="LocalFree(void*)"/> function.</param>
11991205
/// <returns>If the function succeeds, the return value is true, otherwise the return value is false.</returns>
1200-
[DllImport(nameof(AdvApi32), CharSet = CharSet.Unicode, SetLastError = true)]
1206+
[DllImport(api_ms_win_security_sddl_l1_1_0, CharSet = CharSet.Unicode, SetLastError = true)]
12011207
[return: MarshalAs(UnmanagedType.Bool)]
12021208
private static unsafe extern bool ConvertStringSidToSid(string StringSid, ref void* sid);
12031209

@@ -1228,7 +1234,7 @@ private static unsafe extern bool ConvertSidToStringSid(
12281234
/// If the function succeeds, the return value is nonzero.
12291235
/// If the function fails, the return value is zero.
12301236
/// </returns>
1231-
[DllImport(api_ms_win_service_management_l1_1_0, SetLastError = true)]
1237+
[DllImport(nameof(AdvApi32), SetLastError = true)]
12321238
[return: MarshalAs(UnmanagedType.Bool)]
12331239
private static extern bool CryptReleaseContext(IntPtr hProv, uint dwFlags);
12341240
}

src/Windows.Core/ApiSets.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,15 @@ public static class ApiSets
123123
/// The "api-ms-win-core-errorhandling-l1-1-1.dll" constant.
124124
/// </summary>
125125
public const string api_ms_win_core_errorhandling_l1_1_1 = "api-ms-win-core-errorhandling-l1-1-1.dll";
126+
127+
/// <summary>
128+
/// The "api-ms-win-security-sddl-l1-1-0.dll" constant.
129+
/// </summary>
130+
public const string api_ms_win_security_sddl_l1_1_0 = "api-ms-win-security-sddl-l1-1-0.dll";
131+
132+
/// <summary>
133+
/// The "api-ms-win-core-registry-l1-1-0.dll" constant.
134+
/// </summary>
135+
public const string api_ms_win_core_registry_l1_1_0 = "api-ms-win-core-registry-l1-1-0.dll";
126136
}
127137
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
const PInvoke.ApiSets.api_ms_win_core_errorhandling_l1_1_1 = "api-ms-win-core-errorhandling-l1-1-1.dll" -> string
1+
const PInvoke.ApiSets.api_ms_win_core_errorhandling_l1_1_1 = "api-ms-win-core-errorhandling-l1-1-1.dll" -> string
2+
const PInvoke.ApiSets.api_ms_win_security_sddl_l1_1_0 = "api-ms-win-security-sddl-l1-1-0.dll" -> string
3+
const PInvoke.ApiSets.api_ms_win_core_registry_l1_1_0 = "api-ms-win-core-registry-l1-1-0.dll" -> string

0 commit comments

Comments
 (0)