Skip to content

Commit

Permalink
Merge pull request dotnet#1119 from pallavit/ConsolidateInteropCalls
Browse files Browse the repository at this point in the history
Consolidate interop calls for Microsoft.Win32.Registry
  • Loading branch information
pallavit committed Mar 12, 2015
2 parents 094eb33 + a84bc89 commit 802bac9
Show file tree
Hide file tree
Showing 25 changed files with 534 additions and 245 deletions.
4 changes: 3 additions & 1 deletion src/Common/src/Interop/Windows/Interop.Libraries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ internal static partial class Interop
private static class Libraries
{
internal const string Debug = "api-ms-win-core-debug-l1-1-0.dll";
internal const string Localization = "api-ms-win-core-localization-l1-2-0.dll";
internal const string Handle = "api-ms-win-core-handle-l1-1-0.dll";
internal const string Localization = "api-ms-win-core-localization-l1-2-0.dll";
internal const string Registry_L1 = "api-ms-win-core-registry-l1-1-0.dll";
internal const string Registry_L2 = "api-ms-win-core-registry-l2-1-0.dll";
internal const string User32 = "user32.dll";
}
}
20 changes: 20 additions & 0 deletions src/Common/src/Interop/Windows/mincore/Interop.Errors.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

internal partial class Interop
{
internal partial class mincore
{
internal partial class Errors
{
internal const int ERROR_SUCCESS = 0x0;
internal const int ERROR_FILE_NOT_FOUND = 0x2;
internal const int ERROR_ACCESS_DENIED = 0x5;
internal const int ERROR_INVALID_HANDLE = 0x6;
internal const int ERROR_FILENAME_EXCED_RANGE = 0xCE; // filename too long.
internal const int ERROR_MORE_DATA = 0xEA;
internal const int ERROR_DLL_INIT_FAILED = 0x45A;
internal const int ERROR_BAD_IMPERSONATION_LEVEL = 0x542;
}
}
}
12 changes: 9 additions & 3 deletions src/Common/src/Interop/Windows/mincore/Interop.FormatMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ internal partial class mincore

private const int ERROR_INSUFFICIENT_BUFFER = 0x7A;

[DllImport(Libraries.Localization, CharSet = CharSet.Unicode, EntryPoint="FormatMessageW", SetLastError = true, BestFitMapping = true)]
private static extern int FormatMessage(int dwFlags, IntPtr lpSource_mustBeNull, uint dwMessageId,
int dwLanguageId, StringBuilder lpBuffer, int nSize, IntPtr[] arguments);
[DllImport(Libraries.Localization, CharSet = CharSet.Unicode, EntryPoint = "FormatMessageW", SetLastError = true, BestFitMapping = true)]
private static extern int FormatMessage(
int dwFlags,
IntPtr lpSource_mustBeNull,
uint dwMessageId,
int dwLanguageId,
StringBuilder lpBuffer,
int nSize,
IntPtr[] arguments);

/// <summary>
/// Returns a string message for the specified Win32 error code.
Expand Down
15 changes: 15 additions & 0 deletions src/Common/src/Interop/Windows/mincore/Interop.RegCloseKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class mincore
{
[DllImport(Libraries.Registry_L1)]
internal extern static int RegCloseKey(IntPtr hKey);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class mincore
{
[DllImport(Libraries.Registry_L2, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegConnectRegistryW")]
internal static extern int RegConnectRegistry(String machineName, SafeRegistryHandle key, out SafeRegistryHandle result);
}
}
26 changes: 26 additions & 0 deletions src/Common/src/Interop/Windows/mincore/Interop.RegCreateKeyEx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class mincore
{
// Note: RegCreateKeyEx won't set the last error on failure - it returns
// an error code if it fails.
[DllImport(Libraries.Registry_L1, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegCreateKeyExW")]
internal static extern int RegCreateKeyEx(
SafeRegistryHandle hKey,
String lpSubKey,
int Reserved,
String lpClass,
int dwOptions,
int samDesired,
ref SECURITY_ATTRIBUTES secAttrs,
out SafeRegistryHandle hkResult,
out int lpdwDisposition);
}
}
15 changes: 15 additions & 0 deletions src/Common/src/Interop/Windows/mincore/Interop.RegDeleteKeyEx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class mincore
{
[DllImport(Libraries.Registry_L1, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegDeleteKeyExW")]
internal static extern int RegDeleteKeyEx(SafeRegistryHandle hKey, String lpSubKey, int samDesired, int Reserved);
}
}
15 changes: 15 additions & 0 deletions src/Common/src/Interop/Windows/mincore/Interop.RegDeleteValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class mincore
{
[DllImport(Libraries.Registry_L1, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegDeleteValueW")]
internal static extern int RegDeleteValue(SafeRegistryHandle hKey, String lpValueName);
}
}
24 changes: 24 additions & 0 deletions src/Common/src/Interop/Windows/mincore/Interop.RegEnumKeyEx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.InteropServices;
using System.Text;

internal partial class Interop
{
internal partial class mincore
{
[DllImport(Libraries.Registry_L1, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegEnumKeyExW")]
internal unsafe static extern int RegEnumKeyEx(
SafeRegistryHandle hKey,
int dwIndex,
char* lpName,
ref int lpcbName,
int[] lpReserved,
[Out]StringBuilder lpClass,
int[] lpcbClass,
long[] lpftLastWriteTime);
}
}
23 changes: 23 additions & 0 deletions src/Common/src/Interop/Windows/mincore/Interop.RegEnumValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class mincore
{
[DllImport(Libraries.Registry_L1, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegEnumValueW")]
internal unsafe static extern int RegEnumValue(
SafeRegistryHandle hKey,
int dwIndex,
char* lpValueName,
ref int lpcbValueName,
IntPtr lpReserved_MustBeZero,
int[] lpType,
byte[] lpData,
int[] lpcbData);
}
}
14 changes: 14 additions & 0 deletions src/Common/src/Interop/Windows/mincore/Interop.RegFlushKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Win32.SafeHandles;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class mincore
{
[DllImport(Libraries.Registry_L1)]
internal static extern int RegFlushKey(SafeRegistryHandle hKey);
}
}
29 changes: 29 additions & 0 deletions src/Common/src/Interop/Windows/mincore/Interop.RegOpenKeyEx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class mincore
{
[DllImport(Libraries.Registry_L1, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegOpenKeyExW")]
internal static extern int RegOpenKeyEx(
SafeRegistryHandle hKey,
string lpSubKey,
int ulOptions,
int samDesired,
out SafeRegistryHandle hkResult);


[DllImport(Libraries.Registry_L1, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegOpenKeyExW")]
internal static extern int RegOpenKeyEx(
IntPtr hKey,
string lpSubKey,
int ulOptions,
int samDesired,
out SafeRegistryHandle hkResult);
}
}
28 changes: 28 additions & 0 deletions src/Common/src/Interop/Windows/mincore/Interop.RegQueryInfoKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.InteropServices;
using System.Text;

internal partial class Interop
{
internal partial class mincore
{
[DllImport(Libraries.Registry_L1, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegQueryInfoKeyW")]
internal static extern int RegQueryInfoKey(
SafeRegistryHandle hKey,
[Out]StringBuilder lpClass,
int[] lpcbClass,
IntPtr lpReserved_MustBeZero,
ref int lpcSubKeys,
int[] lpcbMaxSubKeyLen,
int[] lpcbMaxClassLen,
ref int lpcValues,
int[] lpcbMaxValueNameLen,
int[] lpcbMaxValueLen,
int[] lpcbSecurityDescriptor,
int[] lpftLastWriteTime);
}
}
58 changes: 58 additions & 0 deletions src/Common/src/Interop/Windows/mincore/Interop.RegQueryValueEx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.InteropServices;
using System.Text;

internal partial class Interop
{
internal partial class mincore
{
[DllImport(Libraries.Registry_L1, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegQueryValueExW")]
internal static extern int RegQueryValueEx(
SafeRegistryHandle hKey,
string lpValueName,
int[] lpReserved,
ref int lpType,
[Out] byte[] lpData,
ref int lpcbData);

[DllImport(Libraries.Registry_L1, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegQueryValueExW")]
internal static extern int RegQueryValueEx(
SafeRegistryHandle hKey,
string lpValueName,
int[] lpReserved,
ref int lpType,
ref int lpData,
ref int lpcbData);

[DllImport(Libraries.Registry_L1, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegQueryValueExW")]
internal static extern int RegQueryValueEx(
SafeRegistryHandle hKey,
String lpValueName,
int[] lpReserved,
ref int lpType,
ref long lpData,
ref int lpcbData);

[DllImport(Libraries.Registry_L1, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegQueryValueExW")]
internal static extern int RegQueryValueEx(
SafeRegistryHandle hKey,
String lpValueName,
int[] lpReserved,
ref int lpType,
[Out] char[] lpData,
ref int lpcbData);

[DllImport(Libraries.Registry_L1, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegQueryValueExW")]
internal static extern int RegQueryValueEx(
SafeRegistryHandle hKey,
String lpValueName,
int[] lpReserved,
ref int lpType,
[Out]StringBuilder lpData,
ref int lpcbData);
}
}
58 changes: 58 additions & 0 deletions src/Common/src/Interop/Windows/mincore/Interop.RegSetValueEx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Win32;
using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.InteropServices;

internal partial class Interop
{
internal partial class mincore
{
[DllImport(Libraries.Registry_L1, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegSetValueExW")]
internal static extern int RegSetValueEx(
SafeRegistryHandle hKey,
String lpValueName,
int Reserved,
RegistryValueKind dwType,
byte[] lpData,
int cbData);

[DllImport(Libraries.Registry_L1, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegSetValueExW")]
internal static extern int RegSetValueEx(
SafeRegistryHandle hKey,
String lpValueName,
int Reserved,
RegistryValueKind dwType,
char[] lpData,
int cbData);

[DllImport(Libraries.Registry_L1, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegSetValueExW")]
internal static extern int RegSetValueEx(
SafeRegistryHandle hKey,
String lpValueName,
int Reserved,
RegistryValueKind dwType,
ref int lpData,
int cbData);

[DllImport(Libraries.Registry_L1, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegSetValueExW")]
internal static extern int RegSetValueEx(
SafeRegistryHandle hKey,
String lpValueName,
int Reserved,
RegistryValueKind dwType,
ref long lpData,
int cbData);

[DllImport(Libraries.Registry_L1, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegSetValueExW")]
internal static extern int RegSetValueEx(
SafeRegistryHandle hKey,
String lpValueName,
int Reserved,
RegistryValueKind dwType,
String lpData,
int cbData);
}
}
Loading

0 comments on commit 802bac9

Please sign in to comment.