Move registry interop to shared CoreLib partition (#19886)
authorJan Kotas <jkotas@microsoft.com>
Tue, 11 Sep 2018 05:39:45 +0000 (22:39 -0700)
committerGitHub <noreply@github.com>
Tue, 11 Sep 2018 05:39:45 +0000 (22:39 -0700)
14 files changed:
src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegCreateKeyEx.cs [new file with mode: 0644]
src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegDeleteKeyEx.cs [new file with mode: 0644]
src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegDeleteValue.cs [new file with mode: 0644]
src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegEnumKeyEx.cs [new file with mode: 0644]
src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegEnumValue.cs [new file with mode: 0644]
src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegOpenKeyEx.cs [new file with mode: 0644]
src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegQueryInfoKey.cs [new file with mode: 0644]
src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegQueryValueEx.cs [new file with mode: 0644]
src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegSetValueEx.cs [new file with mode: 0644]
src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.RegistryView.cs [deleted file]
src/System.Private.CoreLib/shared/Microsoft/Win32/RegistryView.cs
src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems
src/System.Private.CoreLib/src/Microsoft/Win32/RegistryKey.cs
src/System.Private.CoreLib/src/Microsoft/Win32/Win32Native.cs

diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegCreateKeyEx.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegCreateKeyEx.cs
new file mode 100644 (file)
index 0000000..e521906
--- /dev/null
@@ -0,0 +1,27 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using Microsoft.Win32.SafeHandles;
+using System;
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+    internal partial class Advapi32
+    {
+        // Note: RegCreateKeyEx won't set the last error on failure - it returns
+        // an error code if it fails.
+        [DllImport(Libraries.Advapi32, 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 Interop.Kernel32.SECURITY_ATTRIBUTES secAttrs,
+            out SafeRegistryHandle hkResult,
+            out int lpdwDisposition);
+    }
+}
diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegDeleteKeyEx.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegDeleteKeyEx.cs
new file mode 100644 (file)
index 0000000..4429515
--- /dev/null
@@ -0,0 +1,16 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using Microsoft.Win32.SafeHandles;
+using System;
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+    internal partial class Advapi32
+    {
+        [DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegDeleteKeyExW")]
+        internal static extern int RegDeleteKeyEx(SafeRegistryHandle hKey, string lpSubKey, int samDesired, int Reserved);
+    }
+}
diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegDeleteValue.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegDeleteValue.cs
new file mode 100644 (file)
index 0000000..b8044bc
--- /dev/null
@@ -0,0 +1,16 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using Microsoft.Win32.SafeHandles;
+using System;
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+    internal partial class Advapi32
+    {
+        [DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegDeleteValueW")]
+        internal static extern int RegDeleteValue(SafeRegistryHandle hKey, string lpValueName);
+    }
+}
diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegEnumKeyEx.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegEnumKeyEx.cs
new file mode 100644 (file)
index 0000000..bedf282
--- /dev/null
@@ -0,0 +1,25 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using Microsoft.Win32.SafeHandles;
+using System;
+using System.Runtime.InteropServices;
+using System.Text;
+
+internal partial class Interop
+{
+    internal partial class Advapi32
+    {
+        [DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegEnumKeyExW")]
+        internal static extern unsafe int RegEnumKeyEx(
+            SafeRegistryHandle hKey,
+            int dwIndex,
+            char[] lpName,
+            ref int lpcbName,
+            int[] lpReserved,
+            [Out]StringBuilder lpClass,
+            int[] lpcbClass,
+            long[] lpftLastWriteTime);
+    }
+}
diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegEnumValue.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegEnumValue.cs
new file mode 100644 (file)
index 0000000..e02ba98
--- /dev/null
@@ -0,0 +1,24 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using Microsoft.Win32.SafeHandles;
+using System;
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+    internal partial class Advapi32
+    {
+        [DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegEnumValueW")]
+        internal static extern unsafe int RegEnumValue(
+            SafeRegistryHandle hKey,
+            int dwIndex,
+            char[] lpValueName,
+            ref int lpcbValueName,
+            IntPtr lpReserved_MustBeZero,
+            int[] lpType,
+            byte[] lpData,
+            int[] lpcbData);
+    }
+}
diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegOpenKeyEx.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegOpenKeyEx.cs
new file mode 100644 (file)
index 0000000..86b6bca
--- /dev/null
@@ -0,0 +1,30 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using Microsoft.Win32.SafeHandles;
+using System;
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+    internal partial class Advapi32
+    {
+        [DllImport(Libraries.Advapi32, 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.Advapi32, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegOpenKeyExW")]
+        internal static extern int RegOpenKeyEx(
+            IntPtr hKey,
+            string lpSubKey,
+            int ulOptions,
+            int samDesired,
+            out SafeRegistryHandle hkResult);
+    }
+}
diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegQueryInfoKey.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegQueryInfoKey.cs
new file mode 100644 (file)
index 0000000..2df2092
--- /dev/null
@@ -0,0 +1,29 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using Microsoft.Win32.SafeHandles;
+using System;
+using System.Runtime.InteropServices;
+using System.Text;
+
+internal partial class Interop
+{
+    internal partial class Advapi32
+    {
+        [DllImport(Libraries.Advapi32, 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);
+    }
+}
diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegQueryValueEx.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegQueryValueEx.cs
new file mode 100644 (file)
index 0000000..c6a8798
--- /dev/null
@@ -0,0 +1,59 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using Microsoft.Win32.SafeHandles;
+using System;
+using System.Runtime.InteropServices;
+using System.Text;
+
+internal partial class Interop
+{
+    internal partial class Advapi32
+    {
+        [DllImport(Libraries.Advapi32, 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.Advapi32, 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.Advapi32, 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.Advapi32, 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.Advapi32, 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);
+    }
+}
diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegSetValueEx.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegSetValueEx.cs
new file mode 100644 (file)
index 0000000..d46f848
--- /dev/null
@@ -0,0 +1,59 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using Microsoft.Win32;
+using Microsoft.Win32.SafeHandles;
+using System;
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+    internal partial class Advapi32
+    {
+        [DllImport(Libraries.Advapi32, 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.Advapi32, 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.Advapi32, 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.Advapi32, 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.Advapi32, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegSetValueExW")]
+        internal static extern int RegSetValueEx(
+            SafeRegistryHandle hKey,
+            string lpValueName,
+            int Reserved,
+            RegistryValueKind dwType,
+            string lpData,
+            int cbData);
+    }
+}
diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.RegistryView.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.RegistryView.cs
deleted file mode 100644 (file)
index 2e67868..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-internal partial class Interop
-{
-    internal partial class Kernel32
-    {
-        internal partial class RegistryView
-        {
-            internal const int KEY_WOW64_64KEY = 0x0100;
-            internal const int KEY_WOW64_32KEY = 0x0200;
-        }
-    }
-}
index 3cc4a78..0d6b303 100644 (file)
@@ -14,7 +14,7 @@ namespace Microsoft.Win32
     enum RegistryView
     {
         Default = 0, // 0x0000 operate on the default registry view
-        Registry64 = Interop.Kernel32.RegistryView.KEY_WOW64_64KEY, // 0x0100 operate on the 64-bit registry view
-        Registry32 = Interop.Kernel32.RegistryView.KEY_WOW64_32KEY, // 0x0200 operate on the 32-bit registry view
+        Registry64 = Interop.Advapi32.RegistryView.KEY_WOW64_64KEY, // 0x0100 operate on the 64-bit registry view
+        Registry32 = Interop.Advapi32.RegistryView.KEY_WOW64_32KEY, // 0x0200 operate on the 32-bit registry view
     };
 }
index b2db71d..eae7016 100644 (file)
   </ItemGroup>
   <ItemGroup Condition="$(TargetsWindows) and '$(EnableWinRT)' != 'true'">
     <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\NtDll\NtQueryInformationFile.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegCreateKeyEx.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegCloseKey.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegDeleteKeyEx.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegDeleteValue.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegEnumKeyEx.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegEnumValue.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegOpenKeyEx.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegQueryInfoKey.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegQueryValueEx.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegSetValueEx.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegistryConstants.cs" />
-    <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.RegistryView.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\IO\FileStream.Win32.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.Win32.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\Registry.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\SafeLibraryHandle.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\SafeRegistryHandle.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\SafeRegistryHandle.Windows.cs" />
-    <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegCloseKey.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.LoadLibraryEx.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.FreeLibrary.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.CreateFile.cs" />
index 25aa39b..52eeaae 100644 (file)
@@ -277,7 +277,7 @@ namespace Microsoft.Win32
         public void DeleteValue(string name, bool throwOnMissingValue)
         {
             EnsureWriteable();
-            int errorCode = Win32Native.RegDeleteValue(_hkey, name);
+            int errorCode = Interop.Advapi32.RegDeleteValue(_hkey, name);
 
             //
             // From windows 2003 server, if the name is too long we will get error code ERROR_FILENAME_EXCED_RANGE  
@@ -351,7 +351,7 @@ namespace Microsoft.Win32
             name = FixupName(name); // Fixup multiple slashes to a single slash
 
             SafeRegistryHandle result = null;
-            int ret = Win32Native.RegOpenKeyEx(_hkey,
+            int ret = Interop.Advapi32.RegOpenKeyEx(_hkey,
                 name,
                 0,
                 GetRegistryKeyAccess(writable) | (int)_regView,
@@ -403,7 +403,7 @@ namespace Microsoft.Win32
                 int result;
                 int nameLength = name.Length;
 
-                while ((result = Win32Native.RegEnumKeyEx(
+                while ((result = Interop.Advapi32.RegEnumKeyEx(
                     _hkey,
                     names.Count,
                     name,
@@ -457,7 +457,7 @@ namespace Microsoft.Win32
                 int result;
                 int nameLength = name.Length;
 
-                while ((result = Win32Native.RegEnumValue(
+                while ((result = Interop.Advapi32.RegEnumValue(
                     _hkey,
                     names.Count,
                     name,
@@ -567,7 +567,7 @@ namespace Microsoft.Win32
             int type = 0;
             int datasize = 0;
 
-            int ret = Win32Native.RegQueryValueEx(_hkey, name, null, ref type, (byte[])null, ref datasize);
+            int ret = Interop.Advapi32.RegQueryValueEx(_hkey, name, null, ref type, (byte[])null, ref datasize);
 
             if (ret != 0)
             {
@@ -578,7 +578,7 @@ namespace Microsoft.Win32
 
                     int r;
                     byte[] blob = new byte[size];
-                    while (Interop.Errors.ERROR_MORE_DATA == (r = Win32Native.RegQueryValueEx(_hkey, name, null, ref type, blob, ref sizeInput)))
+                    while (Interop.Errors.ERROR_MORE_DATA == (r = Interop.Advapi32.RegQueryValueEx(_hkey, name, null, ref type, blob, ref sizeInput)))
                     {
                         if (size == int.MaxValue)
                         {
@@ -621,47 +621,47 @@ namespace Microsoft.Win32
 
             switch (type)
             {
-                case Win32Native.REG_NONE:
-                case Win32Native.REG_DWORD_BIG_ENDIAN:
-                case Win32Native.REG_BINARY:
+                case Interop.Advapi32.RegistryValues.REG_NONE:
+                case Interop.Advapi32.RegistryValues.REG_DWORD_BIG_ENDIAN:
+                case Interop.Advapi32.RegistryValues.REG_BINARY:
                     {
                         byte[] blob = new byte[datasize];
-                        ret = Win32Native.RegQueryValueEx(_hkey, name, null, ref type, blob, ref datasize);
+                        ret = Interop.Advapi32.RegQueryValueEx(_hkey, name, null, ref type, blob, ref datasize);
                         data = blob;
                     }
                     break;
-                case Win32Native.REG_QWORD:
+                case Interop.Advapi32.RegistryValues.REG_QWORD:
                     {    // also REG_QWORD_LITTLE_ENDIAN
                         if (datasize > 8)
                         {
                             // prevent an AV in the edge case that datasize is larger than sizeof(long)
-                            goto case Win32Native.REG_BINARY;
+                            goto case Interop.Advapi32.RegistryValues.REG_BINARY;
                         }
                         long blob = 0;
                         Debug.Assert(datasize == 8, "datasize==8");
                         // Here, datasize must be 8 when calling this
-                        ret = Win32Native.RegQueryValueEx(_hkey, name, null, ref type, ref blob, ref datasize);
+                        ret = Interop.Advapi32.RegQueryValueEx(_hkey, name, null, ref type, ref blob, ref datasize);
 
                         data = blob;
                     }
                     break;
-                case Win32Native.REG_DWORD:
+                case Interop.Advapi32.RegistryValues.REG_DWORD:
                     {    // also REG_DWORD_LITTLE_ENDIAN
                         if (datasize > 4)
                         {
                             // prevent an AV in the edge case that datasize is larger than sizeof(int)
-                            goto case Win32Native.REG_QWORD;
+                            goto case Interop.Advapi32.RegistryValues.REG_QWORD;
                         }
                         int blob = 0;
                         Debug.Assert(datasize == 4, "datasize==4");
                         // Here, datasize must be four when calling this
-                        ret = Win32Native.RegQueryValueEx(_hkey, name, null, ref type, ref blob, ref datasize);
+                        ret = Interop.Advapi32.RegQueryValueEx(_hkey, name, null, ref type, ref blob, ref datasize);
 
                         data = blob;
                     }
                     break;
 
-                case Win32Native.REG_SZ:
+                case Interop.Advapi32.RegistryValues.REG_SZ:
                     {
                         if (datasize % 2 == 1)
                         {
@@ -677,7 +677,7 @@ namespace Microsoft.Win32
                         }
                         char[] blob = new char[datasize / 2];
 
-                        ret = Win32Native.RegQueryValueEx(_hkey, name, null, ref type, blob, ref datasize);
+                        ret = Interop.Advapi32.RegQueryValueEx(_hkey, name, null, ref type, blob, ref datasize);
                         if (blob.Length > 0 && blob[blob.Length - 1] == (char)0)
                         {
                             data = new string(blob, 0, blob.Length - 1);
@@ -691,7 +691,7 @@ namespace Microsoft.Win32
                     }
                     break;
 
-                case Win32Native.REG_EXPAND_SZ:
+                case Interop.Advapi32.RegistryValues.REG_EXPAND_SZ:
                     {
                         if (datasize % 2 == 1)
                         {
@@ -707,7 +707,7 @@ namespace Microsoft.Win32
                         }
                         char[] blob = new char[datasize / 2];
 
-                        ret = Win32Native.RegQueryValueEx(_hkey, name, null, ref type, blob, ref datasize);
+                        ret = Interop.Advapi32.RegQueryValueEx(_hkey, name, null, ref type, blob, ref datasize);
 
                         if (blob.Length > 0 && blob[blob.Length - 1] == (char)0)
                         {
@@ -724,7 +724,7 @@ namespace Microsoft.Win32
                             data = Environment.ExpandEnvironmentVariables((string)data);
                     }
                     break;
-                case Win32Native.REG_MULTI_SZ:
+                case Interop.Advapi32.RegistryValues.REG_MULTI_SZ:
                     {
                         if (datasize % 2 == 1)
                         {
@@ -740,7 +740,7 @@ namespace Microsoft.Win32
                         }
                         char[] blob = new char[datasize / 2];
 
-                        ret = Win32Native.RegQueryValueEx(_hkey, name, null, ref type, blob, ref datasize);
+                        ret = Interop.Advapi32.RegQueryValueEx(_hkey, name, null, ref type, blob, ref datasize);
 
                         // make sure the string is null terminated before processing the data
                         if (blob.Length > 0 && blob[blob.Length - 1] != (char)0)
@@ -801,7 +801,7 @@ namespace Microsoft.Win32
                         strings.CopyTo((string[])data, 0);
                     }
                     break;
-                case Win32Native.REG_LINK:
+                case Interop.Advapi32.RegistryValues.REG_LINK:
                 default:
                     break;
             }
@@ -851,7 +851,7 @@ namespace Microsoft.Win32
                     case RegistryValueKind.String:
                         {
                             string data = value.ToString();
-                            ret = Win32Native.RegSetValueEx(_hkey,
+                            ret = Interop.Advapi32.RegSetValueEx(_hkey,
                                 name,
                                 0,
                                 valueKind,
@@ -898,7 +898,7 @@ namespace Microsoft.Win32
                                 *(char*)(currentPtr.ToPointer()) = '\0';
                                 currentPtr = new IntPtr((long)currentPtr + 2);
 
-                                ret = Win32Native.RegSetValueEx(_hkey,
+                                ret = Interop.Advapi32.RegSetValueEx(_hkey,
                                     name,
                                     0,
                                     RegistryValueKind.MultiString,
@@ -911,10 +911,10 @@ namespace Microsoft.Win32
                     case RegistryValueKind.None:
                     case RegistryValueKind.Binary:
                         byte[] dataBytes = (byte[])value;
-                        ret = Win32Native.RegSetValueEx(_hkey,
+                        ret = Interop.Advapi32.RegSetValueEx(_hkey,
                             name,
                             0,
-                            (valueKind == RegistryValueKind.None ? Win32Native.REG_NONE : RegistryValueKind.Binary),
+                            (valueKind == RegistryValueKind.None ? Interop.Advapi32.RegistryValues.REG_NONE : RegistryValueKind.Binary),
                             dataBytes,
                             dataBytes.Length);
                         break;
@@ -925,7 +925,7 @@ namespace Microsoft.Win32
                             // unboxed and cast at the same time.  I.e. ((int)(object)(short) 5) will fail.
                             int data = Convert.ToInt32(value, System.Globalization.CultureInfo.InvariantCulture);
 
-                            ret = Win32Native.RegSetValueEx(_hkey,
+                            ret = Interop.Advapi32.RegSetValueEx(_hkey,
                                 name,
                                 0,
                                 RegistryValueKind.DWord,
@@ -938,7 +938,7 @@ namespace Microsoft.Win32
                         {
                             long data = Convert.ToInt64(value, System.Globalization.CultureInfo.InvariantCulture);
 
-                            ret = Win32Native.RegSetValueEx(_hkey,
+                            ret = Interop.Advapi32.RegSetValueEx(_hkey,
                                 name,
                                 0,
                                 RegistryValueKind.QWord,
@@ -1074,11 +1074,11 @@ namespace Microsoft.Win32
             int winAccess;
             if (!isWritable)
             {
-                winAccess = Win32Native.KEY_READ;
+                winAccess = Interop.Advapi32.RegistryOperations.KEY_READ;
             }
             else
             {
-                winAccess = Win32Native.KEY_READ | Win32Native.KEY_WRITE;
+                winAccess = Interop.Advapi32.RegistryOperations.KEY_READ | Interop.Advapi32.RegistryOperations.KEY_WRITE;
             }
 
             return winAccess;
index d1a92a3..45ce42a 100644 (file)
@@ -112,50 +112,6 @@ namespace Microsoft.Win32
 
     internal static class Win32Native
     {
-        internal const int KEY_QUERY_VALUE = 0x0001;
-        internal const int KEY_SET_VALUE = 0x0002;
-        internal const int KEY_CREATE_SUB_KEY = 0x0004;
-        internal const int KEY_ENUMERATE_SUB_KEYS = 0x0008;
-        internal const int KEY_NOTIFY = 0x0010;
-        internal const int KEY_CREATE_LINK = 0x0020;
-        internal const int KEY_READ = ((STANDARD_RIGHTS_READ |
-                                                           KEY_QUERY_VALUE |
-                                                           KEY_ENUMERATE_SUB_KEYS |
-                                                           KEY_NOTIFY)
-                                                          &
-                                                          (~SYNCHRONIZE));
-
-        internal const int KEY_WRITE = ((STANDARD_RIGHTS_WRITE |
-                                                           KEY_SET_VALUE |
-                                                           KEY_CREATE_SUB_KEY)
-                                                          &
-                                                          (~SYNCHRONIZE));
-        internal const int REG_OPTION_NON_VOLATILE = 0x0000;     // (default) keys are persisted beyond reboot/unload
-        internal const int REG_OPTION_VOLATILE = 0x0001;     // All keys created by the function are volatile
-        internal const int REG_OPTION_CREATE_LINK = 0x0002;     // They key is a symbolic link
-        internal const int REG_OPTION_BACKUP_RESTORE = 0x0004;  // Use SE_BACKUP_NAME process special privileges
-        internal const int REG_NONE = 0;     // No value type
-        internal const int REG_SZ = 1;     // Unicode nul terminated string
-        internal const int REG_EXPAND_SZ = 2;     // Unicode nul terminated string
-        // (with environment variable references)
-        internal const int REG_BINARY = 3;     // Free form binary
-        internal const int REG_DWORD = 4;     // 32-bit number
-        internal const int REG_DWORD_LITTLE_ENDIAN = 4;     // 32-bit number (same as REG_DWORD)
-        internal const int REG_DWORD_BIG_ENDIAN = 5;     // 32-bit number
-        internal const int REG_LINK = 6;     // Symbolic Link (unicode)
-        internal const int REG_MULTI_SZ = 7;     // Multiple Unicode strings
-        internal const int REG_RESOURCE_LIST = 8;     // Resource list in the resource map
-        internal const int REG_FULL_RESOURCE_DESCRIPTOR = 9;   // Resource list in the hardware description
-        internal const int REG_RESOURCE_REQUIREMENTS_LIST = 10;
-        internal const int REG_QWORD = 11;    // 64-bit number
-
-        // Win32 ACL-related constants:
-        internal const int READ_CONTROL = 0x00020000;
-        internal const int SYNCHRONIZE = 0x00100000;
-
-        internal const int STANDARD_RIGHTS_READ = READ_CONTROL;
-        internal const int STANDARD_RIGHTS_WRITE = READ_CONTROL;
-
         internal const int LMEM_FIXED = 0x0000;
         internal const int LMEM_ZEROINIT = 0x0040;
         internal const int LPTR = (LMEM_FIXED | LMEM_ZEROINIT);
@@ -184,15 +140,6 @@ namespace Microsoft.Win32
         }
 
         [StructLayout(LayoutKind.Sequential)]
-        internal class SECURITY_ATTRIBUTES
-        {
-            internal int nLength = 0;
-            // don't remove null, or this field will disappear in bcl.small
-            internal unsafe byte* pSecurityDescriptor = null;
-            internal int bInheritHandle = 0;
-        }
-
-        [StructLayout(LayoutKind.Sequential)]
         internal struct MEMORYSTATUSEX
         {
             // The length field must be set to the size of this data structure.
@@ -220,11 +167,6 @@ namespace Microsoft.Win32
         }
 
         internal const string ADVAPI32 = "advapi32.dll";
-        internal const string SHELL32 = "shell32.dll";
-        internal const string SHIM = "mscoree.dll";
-        internal const string CRYPT32 = "crypt32.dll";
-        internal const string SECUR32 = "secur32.dll";
-        internal const string MSCORWKS = "coreclr.dll";
 
         [DllImport(Interop.Libraries.Kernel32, EntryPoint = "LocalAlloc")]
         internal static extern IntPtr LocalAlloc_NoSafeHandle(int uFlags, UIntPtr sizetdwBytes);
@@ -332,64 +274,6 @@ namespace Microsoft.Win32
         [DllImport(Interop.Libraries.Ole32)]
         internal static extern IntPtr CoTaskMemRealloc(IntPtr pv, UIntPtr cb);
 
-#if FEATURE_WIN32_REGISTRY
-
-        [DllImport(ADVAPI32, CharSet = CharSet.Auto, BestFitMapping = false)]
-        internal static extern int RegDeleteValue(SafeRegistryHandle hKey, string lpValueName);
-
-        [DllImport(ADVAPI32, CharSet = CharSet.Auto, BestFitMapping = false)]
-        internal static extern unsafe int RegEnumKeyEx(SafeRegistryHandle hKey, int dwIndex,
-                    char[] lpName, ref int lpcbName, int[] lpReserved,
-                    [Out]StringBuilder lpClass, int[] lpcbClass,
-                    long[] lpftLastWriteTime);
-
-        [DllImport(ADVAPI32, CharSet = CharSet.Auto, BestFitMapping = false)]
-        internal static extern unsafe int RegEnumValue(SafeRegistryHandle hKey, int dwIndex,
-                    char[] lpValueName, ref int lpcbValueName,
-                    IntPtr lpReserved_MustBeZero, int[] lpType, byte[] lpData,
-                    int[] lpcbData);
-
-        [DllImport(ADVAPI32, CharSet = CharSet.Auto, BestFitMapping = false)]
-        internal static extern int RegOpenKeyEx(SafeRegistryHandle hKey, string lpSubKey,
-                    int ulOptions, int samDesired, out SafeRegistryHandle hkResult);
-
-        [DllImport(ADVAPI32, CharSet = CharSet.Auto, BestFitMapping = false)]
-        internal static extern int RegQueryValueEx(SafeRegistryHandle hKey, string lpValueName,
-                    int[] lpReserved, ref int lpType, [Out] byte[] lpData,
-                    ref int lpcbData);
-
-        [DllImport(ADVAPI32, CharSet = CharSet.Auto, BestFitMapping = false)]
-        internal static extern int RegQueryValueEx(SafeRegistryHandle hKey, string lpValueName,
-                    int[] lpReserved, ref int lpType, ref int lpData,
-                    ref int lpcbData);
-
-        [DllImport(ADVAPI32, CharSet = CharSet.Auto, BestFitMapping = false)]
-        internal static extern int RegQueryValueEx(SafeRegistryHandle hKey, string lpValueName,
-                    int[] lpReserved, ref int lpType, ref long lpData,
-                    ref int lpcbData);
-
-        [DllImport(ADVAPI32, CharSet = CharSet.Auto, BestFitMapping = false)]
-        internal static extern int RegQueryValueEx(SafeRegistryHandle hKey, string lpValueName,
-                     int[] lpReserved, ref int lpType, [Out] char[] lpData,
-                     ref int lpcbData);
-
-        [DllImport(ADVAPI32, CharSet = CharSet.Auto, BestFitMapping = false)]
-        internal static extern int RegSetValueEx(SafeRegistryHandle hKey, string lpValueName,
-                    int Reserved, RegistryValueKind dwType, byte[] lpData, int cbData);
-
-        [DllImport(ADVAPI32, CharSet = CharSet.Auto, BestFitMapping = false)]
-        internal static extern int RegSetValueEx(SafeRegistryHandle hKey, string lpValueName,
-                    int Reserved, RegistryValueKind dwType, ref int lpData, int cbData);
-
-        [DllImport(ADVAPI32, CharSet = CharSet.Auto, BestFitMapping = false)]
-        internal static extern int RegSetValueEx(SafeRegistryHandle hKey, string lpValueName,
-                    int Reserved, RegistryValueKind dwType, ref long lpData, int cbData);
-
-        [DllImport(ADVAPI32, CharSet = CharSet.Auto, BestFitMapping = false)]
-        internal static extern int RegSetValueEx(SafeRegistryHandle hKey, string lpValueName,
-                    int Reserved, RegistryValueKind dwType, string lpData, int cbData);
-#endif // FEATURE_WIN32_REGISTRY
-
         [DllImport(Interop.Libraries.Kernel32, CharSet = CharSet.Auto, SetLastError = true, BestFitMapping = false)]
         internal static extern int ExpandEnvironmentStrings(string lpSrc, [Out]StringBuilder lpDst, int nSize);