Refactor interop usage in DirectoryServices (#51325)
authorMatt Thalman <mthalman@microsoft.com>
Mon, 19 Apr 2021 18:53:52 +0000 (13:53 -0500)
committerGitHub <noreply@github.com>
Mon, 19 Apr 2021 18:53:52 +0000 (13:53 -0500)
src/libraries/Common/src/Interop/Windows/Interop.Libraries.cs
src/libraries/System.DirectoryServices.AccountManagement/src/System.DirectoryServices.AccountManagement.csproj
src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/ExternDll.cs [deleted file]
src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/interopt.cs
src/libraries/System.DirectoryServices/src/Interop/SafeNativeMethods.cs
src/libraries/System.DirectoryServices/src/Interop/UnsafeNativeMethods.cs
src/libraries/System.DirectoryServices/src/System.DirectoryServices.csproj
src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/NativeMethods.cs
src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/UnsafeNativeMethods.cs
src/libraries/System.DirectoryServices/src/System/DirectoryServices/ExternDll.cs [deleted file]

index fbddd07..d3466d7 100644 (file)
@@ -5,16 +5,24 @@ internal static partial class Interop
 {
     internal static partial class Libraries
     {
+        internal const string Activeds = "activeds.dll";
         internal const string Advapi32 = "advapi32.dll";
+        internal const string Authz = "authz.dll";
         internal const string BCrypt = "BCrypt.dll";
+        internal const string Credui = "credui.dll";
         internal const string Crypt32 = "crypt32.dll";
         internal const string CryptUI = "cryptui.dll";
+        internal const string Dnsapi = "dnsapi.dll";
+        internal const string Dsrole = "dsrole.dll";
         internal const string Gdi32 = "gdi32.dll";
         internal const string HttpApi = "httpapi.dll";
         internal const string IpHlpApi = "iphlpapi.dll";
         internal const string Kernel32 = "kernel32.dll";
+        internal const string Logoncli = "logoncli.dll";
         internal const string Mswsock = "mswsock.dll";
         internal const string NCrypt = "ncrypt.dll";
+        internal const string Netapi32 = "netapi32.dll";
+        internal const string Netutils = "netutils.dll";
         internal const string NtDll = "ntdll.dll";
         internal const string Odbc32 = "odbc32.dll";
         internal const string Ole32 = "ole32.dll";
@@ -28,6 +36,7 @@ internal static partial class Interop
         internal const string WebSocket = "websocket.dll";
         internal const string WinHttp = "winhttp.dll";
         internal const string WinMM = "winmm.dll";
+        internal const string Wkscli = "wkscli.dll";
         internal const string Wldap32 = "wldap32.dll";
         internal const string Ws2_32 = "ws2_32.dll";
         internal const string Wtsapi32 = "wtsapi32.dll";
index 28f6167..32c3b65 100644 (file)
@@ -12,7 +12,6 @@
     <GeneratePlatformNotSupportedAssemblyMessage Condition="'$(TargetFramework)' == 'netstandard2.0'">SR.DirectoryServicesAccountManagement_PlatformNotSupported</GeneratePlatformNotSupportedAssemblyMessage>
   </PropertyGroup>
   <ItemGroup Condition="'$(TargetFramework)' != 'netstandard2.0'">
-    <Compile Include="System\DirectoryServices\AccountManagement\ExternDll.cs" />
     <Compile Include="System\DirectoryServices\AccountManagement\interopt.cs" />
     <Compile Include="System\DirectoryServices\AccountManagement\PrincipalSearcher.cs" />
     <Compile Include="System\DirectoryServices\AccountManagement\Utils.cs" />
diff --git a/src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/ExternDll.cs b/src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/ExternDll.cs
deleted file mode 100644 (file)
index df541f4..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-namespace System
-{
-    internal static class ExternDll
-    {
-        public const string Activeds = "activeds.dll";
-        public const string Advapi32 = "advapi32.dll";
-        public const string Comctl32 = "comctl32.dll";
-        public const string Comdlg32 = "comdlg32.dll";
-        public const string Gdi32 = "gdi32.dll";
-        public const string Gdiplus = "gdiplus.dll";
-        public const string Hhctrl = "hhctrl.ocx";
-        public const string Imm32 = "imm32.dll";
-        public const string Kernel32 = "kernel32.dll";
-        public const string Loadperf = "Loadperf.dll";
-        public const string Mscoree = "mscoree.dll";
-        public const string Clr = "clr.dll";
-        public const string Msi = "msi.dll";
-        public const string Mqrt = "mqrt.dll";
-        public const string Ntdll = "ntdll.dll";
-        public const string Ole32 = "ole32.dll";
-        public const string Oleacc = "oleacc.dll";
-        public const string Oleaut32 = "oleaut32.dll";
-        public const string Olepro32 = "olepro32.dll";
-        public const string PerfCounter = "perfcounter.dll";
-        public const string Powrprof = "Powrprof.dll";
-        public const string Psapi = "psapi.dll";
-        public const string Shell32 = "shell32.dll";
-        public const string User32 = "user32.dll";
-        public const string Uxtheme = "uxtheme.dll";
-        public const string WinMM = "winmm.dll";
-        public const string Winspool = "winspool.drv";
-        public const string Wtsapi32 = "wtsapi32.dll";
-        public const string Version = "version.dll";
-        public const string Vsassert = "vsassert.dll";
-        public const string Fxassert = "Fxassert.dll";
-        public const string Shlwapi = "shlwapi.dll";
-        public const string Crypt32 = "crypt32.dll";
-
-        // system.data specific
-        internal const string Odbc32 = "odbc32.dll";
-        internal const string SNI = "System.Data.dll";
-
-        // system.data.oracleclient specific
-        internal const string OciDll = "oci.dll";
-        internal const string OraMtsDll = "oramts.dll";
-    }
-}
index 583bb41..e8fbd22 100644 (file)
@@ -23,16 +23,16 @@ namespace System.DirectoryServices.AccountManagement
 
     internal static class SafeNativeMethods
     {
-        [DllImport("kernel32.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetCurrentThreadId", CharSet = CharSet.Unicode)]
+        [DllImport(Interop.Libraries.Kernel32, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetCurrentThreadId", CharSet = CharSet.Unicode)]
         public static extern int GetCurrentThreadId();
 
-        [DllImport("advapi32.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "LsaNtStatusToWinError", CharSet = CharSet.Unicode)]
+        [DllImport(Interop.Libraries.Advapi32, CallingConvention = CallingConvention.StdCall, EntryPoint = "LsaNtStatusToWinError", CharSet = CharSet.Unicode)]
         public static extern int LsaNtStatusToWinError(int ntStatus);
     }
 
     internal static class UnsafeNativeMethods
     {
-        [DllImport(ExternDll.Activeds, ExactSpelling = true, EntryPoint = "ADsOpenObject", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
+        [DllImport(Interop.Libraries.Activeds, ExactSpelling = true, EntryPoint = "ADsOpenObject", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
         private static extern int IntADsOpenObject(string path, string userName, string password, int flags, [In, Out] ref Guid iid, [Out, MarshalAs(UnmanagedType.Interface)] out object ppObject);
         public static int ADsOpenObject(string path, string userName, string password, int flags, [In, Out] ref Guid iid, [Out, MarshalAs(UnmanagedType.Interface)] out object ppObject)
         {
@@ -431,7 +431,7 @@ namespace System.DirectoryServices.AccountManagement
           PBYTE* Buffer
         ); */
 
-        [DllImport("dsrole.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "DsRoleGetPrimaryDomainInformation", CharSet = CharSet.Unicode)]
+        [DllImport(Interop.Libraries.Dsrole, CallingConvention = CallingConvention.StdCall, EntryPoint = "DsRoleGetPrimaryDomainInformation", CharSet = CharSet.Unicode)]
         public static extern int DsRoleGetPrimaryDomainInformation(
             [MarshalAs(UnmanagedType.LPTStr)] string lpServer,
             [In] DSROLE_PRIMARY_DOMAIN_INFO_LEVEL InfoLevel,
@@ -467,7 +467,7 @@ namespace System.DirectoryServices.AccountManagement
           PVOID Buffer
         );
         */
-        [DllImport("dsrole.dll")]
+        [DllImport(Interop.Libraries.Dsrole)]
         public static extern int DsRoleFreeMemory(
             [In] IntPtr buffer);
 
@@ -479,7 +479,7 @@ namespace System.DirectoryServices.AccountManagement
             ULONG Flags,
             PDOMAIN_CONTROLLER_INFO* DomainControllerInfo
         );*/
-        [DllImport("logoncli.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "DsGetDcNameW", CharSet = CharSet.Unicode)]
+        [DllImport(Interop.Libraries.Logoncli, CallingConvention = CallingConvention.StdCall, EntryPoint = "DsGetDcNameW", CharSet = CharSet.Unicode)]
         public static extern int DsGetDcName(
             [In] string computerName,
             [In] string domainName,
@@ -505,10 +505,10 @@ namespace System.DirectoryServices.AccountManagement
             public int wki100_ver_minor;
         };
 
-        [DllImport("wkscli.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "NetWkstaGetInfo", CharSet = CharSet.Unicode)]
+        [DllImport(Interop.Libraries.Wkscli, CallingConvention = CallingConvention.StdCall, EntryPoint = "NetWkstaGetInfo", CharSet = CharSet.Unicode)]
         public static extern int NetWkstaGetInfo(string server, int level, ref IntPtr buffer);
 
-        [DllImport("netutils.dll")]
+        [DllImport(Interop.Libraries.Netutils)]
         public static extern int NetApiBufferFree(
             [In] IntPtr buffer);
 
@@ -516,37 +516,37 @@ namespace System.DirectoryServices.AccountManagement
         // SID
         //
 
-        [DllImport("advapi32.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, EntryPoint = "ConvertSidToStringSidW", CharSet = CharSet.Unicode)]
+        [DllImport(Interop.Libraries.Advapi32, SetLastError = true, CallingConvention = CallingConvention.StdCall, EntryPoint = "ConvertSidToStringSidW", CharSet = CharSet.Unicode)]
         public static extern bool ConvertSidToStringSid(IntPtr sid, ref string stringSid);
 
-        [DllImport("advapi32.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "ConvertStringSidToSidW", CharSet = CharSet.Unicode)]
+        [DllImport(Interop.Libraries.Advapi32, CallingConvention = CallingConvention.StdCall, EntryPoint = "ConvertStringSidToSidW", CharSet = CharSet.Unicode)]
         public static extern bool ConvertStringSidToSid(string stringSid, ref IntPtr sid);
 
-        [DllImport("advapi32.dll")]
+        [DllImport(Interop.Libraries.Advapi32)]
         public static extern int GetLengthSid(IntPtr sid);
 
-        [DllImport("advapi32.dll", SetLastError = true)]
+        [DllImport(Interop.Libraries.Advapi32, SetLastError = true)]
         public static extern bool IsValidSid(IntPtr sid);
 
-        [DllImport("advapi32.dll")]
+        [DllImport(Interop.Libraries.Advapi32)]
         public static extern IntPtr GetSidIdentifierAuthority(IntPtr sid);
 
-        [DllImport("advapi32.dll")]
+        [DllImport(Interop.Libraries.Advapi32)]
         public static extern IntPtr GetSidSubAuthority(IntPtr sid, int index);
 
-        [DllImport("advapi32.dll")]
+        [DllImport(Interop.Libraries.Advapi32)]
         public static extern IntPtr GetSidSubAuthorityCount(IntPtr sid);
 
-        [DllImport("advapi32.dll")]
+        [DllImport(Interop.Libraries.Advapi32)]
         public static extern bool EqualDomainSid(IntPtr pSid1, IntPtr pSid2, ref bool equal);
 
-        [DllImport("advapi32.dll", SetLastError = true)]
+        [DllImport(Interop.Libraries.Advapi32, SetLastError = true)]
         public static extern bool CopySid(int destinationLength, IntPtr pSidDestination, IntPtr pSidSource);
 
-        [DllImport("kernel32.dll")]
+        [DllImport(Interop.Libraries.Kernel32)]
         public static extern IntPtr LocalFree(IntPtr ptr);
 
-        [DllImport("Credui.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, EntryPoint = "CredUIParseUserNameW", CharSet = CharSet.Unicode)]
+        [DllImport(Interop.Libraries.Credui, SetLastError = true, CallingConvention = CallingConvention.StdCall, EntryPoint = "CredUIParseUserNameW", CharSet = CharSet.Unicode)]
         public static extern unsafe int CredUIParseUserName(
             string pszUserName,
             char* pszUser,
@@ -570,7 +570,7 @@ namespace System.DirectoryServices.AccountManagement
             public static int AUTHZ_VALID_RM_INIT_FLAGS = (AUTHZ_RM_FLAG_NO_AUDIT | AUTHZ_RM_FLAG_INITIALIZE_UNDER_IMPERSONATION);
         }
 
-        [DllImport("authz.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, EntryPoint = "AuthzInitializeResourceManager", CharSet = CharSet.Unicode)]
+        [DllImport(Interop.Libraries.Authz, SetLastError = true, CallingConvention = CallingConvention.StdCall, EntryPoint = "AuthzInitializeResourceManager", CharSet = CharSet.Unicode)]
         public static extern bool AuthzInitializeResourceManager(
                                         int flags,
                                         IntPtr pfnAccessCheck,
@@ -591,7 +591,7 @@ namespace System.DirectoryServices.AccountManagement
             PAUTHZ_CLIENT_CONTEXT_HANDLE pAuthzClientContext
         );
         */
-        [DllImport("authz.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, EntryPoint = "AuthzInitializeContextFromSid", CharSet = CharSet.Unicode)]
+        [DllImport(Interop.Libraries.Authz, SetLastError = true, CallingConvention = CallingConvention.StdCall, EntryPoint = "AuthzInitializeContextFromSid", CharSet = CharSet.Unicode)]
         public static extern bool AuthzInitializeContextFromSid(
                                         int Flags,
                                         IntPtr UserSid,
@@ -603,7 +603,7 @@ namespace System.DirectoryServices.AccountManagement
                                         );
 
         /*
-                [DllImport("authz.dll", SetLastError=true, CallingConvention=CallingConvention.StdCall, EntryPoint="AuthzInitializeContextFromToken", CharSet=CharSet.Unicode)]
+                [DllImport(Interop.Libraries.Authz, SetLastError=true, CallingConvention=CallingConvention.StdCall, EntryPoint="AuthzInitializeContextFromToken", CharSet=CharSet.Unicode)]
                 static extern public bool AuthzInitializeContextFromToken(
                                                 int Flags,
                                                 IntPtr TokenHandle,
@@ -614,7 +614,7 @@ namespace System.DirectoryServices.AccountManagement
                                                 out IntPtr pAuthzClientContext
                                                 );
         */
-        [DllImport("authz.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, EntryPoint = "AuthzGetInformationFromContext", CharSet = CharSet.Unicode)]
+        [DllImport(Interop.Libraries.Authz, SetLastError = true, CallingConvention = CallingConvention.StdCall, EntryPoint = "AuthzGetInformationFromContext", CharSet = CharSet.Unicode)]
         public static extern bool AuthzGetInformationFromContext(
                                         IntPtr hAuthzClientContext,
                                         int InfoClass,
@@ -623,12 +623,12 @@ namespace System.DirectoryServices.AccountManagement
                                         IntPtr Buffer
                                         );
 
-        [DllImport("authz.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "AuthzFreeContext", CharSet = CharSet.Unicode)]
+        [DllImport(Interop.Libraries.Authz, CallingConvention = CallingConvention.StdCall, EntryPoint = "AuthzFreeContext", CharSet = CharSet.Unicode)]
         public static extern bool AuthzFreeContext(
                                         IntPtr AuthzClientContext
                                         );
 
-        [DllImport("authz.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "AuthzFreeResourceManager", CharSet = CharSet.Unicode)]
+        [DllImport(Interop.Libraries.Authz, CallingConvention = CallingConvention.StdCall, EntryPoint = "AuthzFreeResourceManager", CharSet = CharSet.Unicode)]
         public static extern bool AuthzFreeResourceManager(
                                         IntPtr rm
                                         );
@@ -734,7 +734,7 @@ namespace System.DirectoryServices.AccountManagement
             private readonly IntPtr _pSid = IntPtr.Zero;
         }
 
-        [DllImport("advapi32.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, EntryPoint = "OpenThreadToken", CharSet = CharSet.Unicode)]
+        [DllImport(Interop.Libraries.Advapi32, SetLastError = true, CallingConvention = CallingConvention.StdCall, EntryPoint = "OpenThreadToken", CharSet = CharSet.Unicode)]
         public static extern bool OpenThreadToken(
                                         IntPtr threadHandle,
                                         int desiredAccess,
@@ -742,23 +742,23 @@ namespace System.DirectoryServices.AccountManagement
                                         ref IntPtr tokenHandle
                                         );
 
-        [DllImport("advapi32.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, EntryPoint = "OpenProcessToken", CharSet = CharSet.Unicode)]
+        [DllImport(Interop.Libraries.Advapi32, SetLastError = true, CallingConvention = CallingConvention.StdCall, EntryPoint = "OpenProcessToken", CharSet = CharSet.Unicode)]
         public static extern bool OpenProcessToken(
                                         IntPtr processHandle,
                                         int desiredAccess,
                                         ref IntPtr tokenHandle
                                         );
 
-        [DllImport("kernel32.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "CloseHandle", CharSet = CharSet.Unicode)]
+        [DllImport(Interop.Libraries.Kernel32, CallingConvention = CallingConvention.StdCall, EntryPoint = "CloseHandle", CharSet = CharSet.Unicode)]
         public static extern bool CloseHandle(IntPtr handle);
 
-        [DllImport("kernel32.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetCurrentThread", CharSet = CharSet.Unicode)]
+        [DllImport(Interop.Libraries.Kernel32, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetCurrentThread", CharSet = CharSet.Unicode)]
         public static extern IntPtr GetCurrentThread();
 
-        [DllImport("kernel32.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetCurrentProcess", CharSet = CharSet.Unicode)]
+        [DllImport(Interop.Libraries.Kernel32, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetCurrentProcess", CharSet = CharSet.Unicode)]
         public static extern IntPtr GetCurrentProcess();
 
-        [DllImport("advapi32.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetTokenInformation", CharSet = CharSet.Unicode)]
+        [DllImport(Interop.Libraries.Advapi32, SetLastError = true, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetTokenInformation", CharSet = CharSet.Unicode)]
         public static extern bool GetTokenInformation(
                                         IntPtr tokenHandle,
                                         int tokenInformationClass,
@@ -767,21 +767,21 @@ namespace System.DirectoryServices.AccountManagement
                                         ref int returnLength
                                         );
 
-        [DllImport("advapi32.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "LsaOpenPolicy", CharSet = CharSet.Unicode)]
+        [DllImport(Interop.Libraries.Advapi32, CallingConvention = CallingConvention.StdCall, EntryPoint = "LsaOpenPolicy", CharSet = CharSet.Unicode)]
         public static extern int LsaOpenPolicy(
                                         IntPtr lsaUnicodeString,
                                         IntPtr lsaObjectAttributes,
                                         int desiredAccess,
                                         ref IntPtr policyHandle);
 
-        [DllImport("advapi32.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "LsaQueryInformationPolicy", CharSet = CharSet.Unicode)]
+        [DllImport(Interop.Libraries.Advapi32, CallingConvention = CallingConvention.StdCall, EntryPoint = "LsaQueryInformationPolicy", CharSet = CharSet.Unicode)]
         public static extern int LsaQueryInformationPolicy(
                                         IntPtr policyHandle,
                                         int policyInformationClass,
                                         ref IntPtr buffer
                                         );
 
-        [DllImport("advapi32.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "LsaLookupSids", CharSet = CharSet.Unicode)]
+        [DllImport(Interop.Libraries.Advapi32, CallingConvention = CallingConvention.StdCall, EntryPoint = "LsaLookupSids", CharSet = CharSet.Unicode)]
         public static extern int LsaLookupSids(
                                         IntPtr policyHandle,
                                         int count,
@@ -790,17 +790,17 @@ namespace System.DirectoryServices.AccountManagement
                                         out IntPtr names
                                         );
 
-        [DllImport("advapi32.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "LsaFreeMemory", CharSet = CharSet.Unicode)]
+        [DllImport(Interop.Libraries.Advapi32, CallingConvention = CallingConvention.StdCall, EntryPoint = "LsaFreeMemory", CharSet = CharSet.Unicode)]
         public static extern int LsaFreeMemory(IntPtr buffer);
 
-        [DllImport("advapi32.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "LsaClose", CharSet = CharSet.Unicode)]
+        [DllImport(Interop.Libraries.Advapi32, CallingConvention = CallingConvention.StdCall, EntryPoint = "LsaClose", CharSet = CharSet.Unicode)]
         public static extern int LsaClose(IntPtr policyHandle);
 
         //
         // Impersonation
         //
 
-        [DllImport("advapi32.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, EntryPoint = "LogonUserW", CharSet = CharSet.Unicode)]
+        [DllImport(Interop.Libraries.Advapi32, SetLastError = true, CallingConvention = CallingConvention.StdCall, EntryPoint = "LogonUserW", CharSet = CharSet.Unicode)]
         public static extern int LogonUser(
                                     string lpszUsername,
                                     string lpszDomain,
@@ -809,10 +809,10 @@ namespace System.DirectoryServices.AccountManagement
                                     int dwLogonProvider,
                                     ref IntPtr phToken);
 
-        [DllImport("advapi32.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, EntryPoint = "ImpersonateLoggedOnUser", CharSet = CharSet.Unicode)]
+        [DllImport(Interop.Libraries.Advapi32, SetLastError = true, CallingConvention = CallingConvention.StdCall, EntryPoint = "ImpersonateLoggedOnUser", CharSet = CharSet.Unicode)]
         public static extern int ImpersonateLoggedOnUser(IntPtr hToken);
 
-        [DllImport("Advapi32.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "RevertToSelf", CharSet = CharSet.Unicode)]
+        [DllImport(Interop.Libraries.Advapi32, CallingConvention = CallingConvention.StdCall, EntryPoint = "RevertToSelf", CharSet = CharSet.Unicode)]
         public static extern int RevertToSelf();
     }
 }
index f1ad83a..bbff66c 100644 (file)
@@ -9,13 +9,13 @@ namespace System.DirectoryServices.Interop
 {
     internal static class SafeNativeMethods
     {
-        [DllImport(ExternDll.Oleaut32, PreserveSig = false)]
+        [DllImport(global::Interop.Libraries.OleAut32, PreserveSig = false)]
         public static extern void VariantClear(IntPtr pObject);
 
-        [DllImport(ExternDll.Oleaut32)]
+        [DllImport(global::Interop.Libraries.OleAut32)]
         public static extern void VariantInit(IntPtr pObject);
 
-        [DllImport(ExternDll.Activeds)]
+        [DllImport(global::Interop.Libraries.Activeds)]
         public static extern bool FreeADsMem(IntPtr pVoid);
 
         public const int
@@ -25,10 +25,10 @@ namespace System.DirectoryServices.Interop
             ERROR_MORE_DATA = 234,
             ERROR_SUCCESS = 0;
 
-        [DllImport(ExternDll.Activeds, CharSet = CharSet.Unicode)]
+        [DllImport(global::Interop.Libraries.Activeds, CharSet = CharSet.Unicode)]
         public static extern unsafe int ADsGetLastError(out int error, char* errorBuffer, int errorBufferLength, char* nameBuffer, int nameBufferLength);
 
-        [DllImport(ExternDll.Activeds, CharSet = CharSet.Unicode)]
+        [DllImport(global::Interop.Libraries.Activeds, CharSet = CharSet.Unicode)]
         public static extern int ADsSetLastError(int error, string? errorString, string? provider);
 
         public class EnumVariant
index 168287d..bc8671e 100644 (file)
@@ -28,7 +28,7 @@ namespace System.DirectoryServices.Interop
 
     internal static class UnsafeNativeMethods
     {
-        [DllImport(ExternDll.Activeds, ExactSpelling = true, EntryPoint = "ADsOpenObject", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
+        [DllImport(global::Interop.Libraries.Activeds, ExactSpelling = true, EntryPoint = "ADsOpenObject", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
         private static extern int IntADsOpenObject(string path, string? userName, string? password, int flags, [In, Out] ref Guid iid, [Out, MarshalAs(UnmanagedType.Interface)] out object ppObject);
 
         public static int ADsOpenObject(string path, string? userName, string? password, int flags, [In, Out] ref Guid iid, [Out, MarshalAs(UnmanagedType.Interface)] out object ppObject)
index 085cba0..968303d 100644 (file)
@@ -11,7 +11,6 @@
     <GeneratePlatformNotSupportedAssemblyMessage Condition="'$(TargetFramework)' == 'netstandard2.0'">SR.DirectoryServices_PlatformNotSupported</GeneratePlatformNotSupportedAssemblyMessage>
   </PropertyGroup>
   <ItemGroup Condition="'$(TargetFramework)' != 'netstandard2.0'">
-    <Compile Include="System\DirectoryServices\ExternDll.cs" />
     <Compile Include="System\DirectoryServices\ActiveDirectorySecurity.cs" />
     <Compile Include="System\DirectoryServices\AdsVLV.cs" />
     <Compile Include="System\DirectoryServices\AuthenticationTypes.cs" />
     <Compile Include="Interop\NativeMethods.cs" />
     <Compile Include="Interop\SafeNativeMethods.cs" />
     <Compile Include="Interop\UnsafeNativeMethods.cs" />
+    <Compile Include="$(CommonPath)Interop\Windows\Interop.Libraries.cs"
+             Link="Common\Interop\Windows\Interop.Libraries.cs" />
     <Compile Include="$(CommonPath)System\Obsoletions.cs" Link="System\Obsoletions.cs" />
   </ItemGroup>
   <ItemGroup>
index d1d7578..eba0046 100644 (file)
@@ -320,7 +320,7 @@ namespace System.DirectoryServices.ActiveDirectory
                 ULONG Flags,
                 PDOMAIN_CONTROLLER_INFO* DomainControllerInfo
                 );*/
-        [DllImport("Netapi32.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "DsGetDcNameW", CharSet = CharSet.Unicode)]
+        [DllImport(global::Interop.Libraries.Netapi32, CallingConvention = CallingConvention.StdCall, EntryPoint = "DsGetDcNameW", CharSet = CharSet.Unicode)]
         internal static extern int DsGetDcName(
             [In] string? computerName,
             [In] string? domainName,
@@ -338,7 +338,7 @@ namespace System.DirectoryServices.ActiveDirectory
                          ULONG DcFlags,
                          PHANDLE RetGetDcContext
                          );*/
-        [DllImport("Netapi32.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "DsGetDcOpenW", CharSet = CharSet.Unicode)]
+        [DllImport(global::Interop.Libraries.Netapi32, CallingConvention = CallingConvention.StdCall, EntryPoint = "DsGetDcOpenW", CharSet = CharSet.Unicode)]
         internal static extern int DsGetDcOpen(
             [In] string? dnsName,
             [In] int optionFlags,
@@ -354,7 +354,7 @@ namespace System.DirectoryServices.ActiveDirectory
                         LPSOCKET_ADDRESS* SockAddresses,
                         LPTSTR* DnsHostName
                         );*/
-        [DllImport("Netapi32.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "DsGetDcNextW", CharSet = CharSet.Unicode)]
+        [DllImport(global::Interop.Libraries.Netapi32, CallingConvention = CallingConvention.StdCall, EntryPoint = "DsGetDcNextW", CharSet = CharSet.Unicode)]
         internal static extern int DsGetDcNext(
             [In] IntPtr getDcContextHandle,
             [In, Out] ref IntPtr sockAddressCount,
@@ -364,14 +364,14 @@ namespace System.DirectoryServices.ActiveDirectory
         /*void WINAPI DsGetDcClose(
                         HANDLE GetDcContextHandle
                         );*/
-        [DllImport("Netapi32.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "DsGetDcCloseW", CharSet = CharSet.Unicode)]
+        [DllImport(global::Interop.Libraries.Netapi32, CallingConvention = CallingConvention.StdCall, EntryPoint = "DsGetDcCloseW", CharSet = CharSet.Unicode)]
         internal static extern void DsGetDcClose(
             [In] IntPtr getDcContextHandle);
 
         /*NET_API_STATUS NetApiBufferFree(
                 LPVOID Buffer
                 );*/
-        [DllImport("Netapi32.dll")]
+        [DllImport(global::Interop.Libraries.Netapi32)]
         internal static extern int NetApiBufferFree(
             [In] IntPtr buffer);
 
@@ -458,7 +458,7 @@ namespace System.DirectoryServices.ActiveDirectory
             [Out] out IntPtr roles);
 
         /*DWORD GetLastError(VOID)*/
-        [DllImport("Kernel32.dll")]
+        [DllImport(global::Interop.Libraries.Kernel32)]
         internal static extern int GetLastError();
 
         internal const int DnsSrvData = 33;
@@ -472,7 +472,7 @@ namespace System.DirectoryServices.ActiveDirectory
             PDNS_RECORD *ppQueryResultsSet,
             PVOID *pReserved
             );*/
-        [DllImport("Dnsapi.dll", EntryPoint = "DnsQuery_W", CharSet = CharSet.Unicode)]
+        [DllImport(global::Interop.Libraries.Dnsapi, EntryPoint = "DnsQuery_W", CharSet = CharSet.Unicode)]
         internal static extern int DnsQuery(
             [In] string recordName,
             [In] short recordType,
@@ -485,7 +485,7 @@ namespace System.DirectoryServices.ActiveDirectory
             PDNS_RECORD pRecordList,
             DNS_FREE_TYPE FreeType
             );*/
-        [DllImport("Dnsapi.dll", CharSet = CharSet.Unicode)]
+        [DllImport(global::Interop.Libraries.Dnsapi, CharSet = CharSet.Unicode)]
         internal static extern void DnsRecordListFree(
             [In] IntPtr dnsResultList,
             [In] bool dnsFreeType);
@@ -493,7 +493,7 @@ namespace System.DirectoryServices.ActiveDirectory
         /*BOOL GetVersionEx(
               LPOSVERSIONINFO lpVersionInfo
             );*/
-        [DllImport("Kernel32.dll", EntryPoint = "GetVersionExW", CharSet = CharSet.Unicode, SetLastError = true)]
+        [DllImport(global::Interop.Libraries.Kernel32, EntryPoint = "GetVersionExW", CharSet = CharSet.Unicode, SetLastError = true)]
         internal static extern bool GetVersionEx(
                 [In, Out] OSVersionInfoEx ver);
 
@@ -518,7 +518,7 @@ namespace System.DirectoryServices.ActiveDirectory
         /*NTSTATUS LsaConnectUntrusted(
               PHANDLE LsaHandle
             );*/
-        [DllImport("Secur32.dll")]
+        [DllImport(global::Interop.Libraries.Secur32)]
         internal static extern int LsaConnectUntrusted(
              [Out] out LsaLogonProcessSafeHandle lsaHandle);
 
@@ -533,7 +533,7 @@ namespace System.DirectoryServices.ActiveDirectory
               PULONG ReturnBufferLength,
               PNTSTATUS ProtocolStatus
             );*/
-        [DllImport("Secur32.dll")]
+        [DllImport(global::Interop.Libraries.Secur32)]
         internal static extern int LsaCallAuthenticationPackage(
             [In] LsaLogonProcessSafeHandle lsaHandle,
             [In] int authenticationPackage,
@@ -546,14 +546,14 @@ namespace System.DirectoryServices.ActiveDirectory
         /*NTSTATUS LsaFreeReturnBuffer(
               PVOID Buffer
             );*/
-        [DllImport("Secur32.dll")]
+        [DllImport(global::Interop.Libraries.Secur32)]
         internal static extern uint LsaFreeReturnBuffer(
             [In] IntPtr buffer);
 
         /*NTSTATUS LsaDeregisterLogonProcess(
               HANDLE LsaHandle
             );*/
-        [DllImport("Secur32.dll")]
+        [DllImport(global::Interop.Libraries.Secur32)]
         internal static extern int LsaDeregisterLogonProcess(
             [In] IntPtr lsaHandle);
 
@@ -564,7 +564,7 @@ namespace System.DirectoryServices.ActiveDirectory
             DWORD lpString2,
             DWORD cchCount2
             );*/
-        [DllImport("Kernel32.dll", EntryPoint = "CompareStringW", CharSet = CharSet.Unicode, SetLastError = true)]
+        [DllImport(global::Interop.Libraries.Kernel32, EntryPoint = "CompareStringW", CharSet = CharSet.Unicode, SetLastError = true)]
         internal static extern int CompareString(
             [In] uint locale,
             [In] uint dwCmpFlags,
@@ -573,7 +573,7 @@ namespace System.DirectoryServices.ActiveDirectory
             [In] IntPtr lpString2,
             [In] int cchCount2);
 
-        [DllImport("advapi32.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "LsaNtStatusToWinError", CharSet = CharSet.Unicode)]
+        [DllImport(global::Interop.Libraries.Advapi32, CallingConvention = CallingConvention.StdCall, EntryPoint = "LsaNtStatusToWinError", CharSet = CharSet.Unicode)]
         internal static extern int LsaNtStatusToWinError(int ntStatus);
     }
 
index 9d08308..3596b1a 100644 (file)
@@ -639,107 +639,107 @@ namespace System.DirectoryServices.ActiveDirectory
 
         public delegate int DsReplicaSyncAllW(IntPtr handle, [MarshalAs(UnmanagedType.LPWStr)] string partition, int flags, SyncReplicaFromAllServersCallback callback, IntPtr data, ref IntPtr error);
 
-        [DllImport("kernel32.dll", EntryPoint = "LocalFree")]
+        [DllImport(global::Interop.Libraries.Kernel32, EntryPoint = "LocalFree")]
         public static extern int LocalFree(IntPtr mem);
 
-        [DllImport("activeds.dll", EntryPoint = "ADsEncodeBinaryData", CharSet = CharSet.Unicode)]
+        [DllImport(global::Interop.Libraries.Activeds, EntryPoint = "ADsEncodeBinaryData", CharSet = CharSet.Unicode)]
         public static extern int ADsEncodeBinaryData(byte[] data, int length, ref IntPtr result);
 
-        [DllImport("activeds.dll", EntryPoint = "FreeADsMem")]
+        [DllImport(global::Interop.Libraries.Activeds, EntryPoint = "FreeADsMem")]
         public static extern bool FreeADsMem(IntPtr pVoid);
 
-        [DllImport("netapi32.dll", EntryPoint = "DsGetSiteNameW", CharSet = CharSet.Unicode)]
+        [DllImport(global::Interop.Libraries.Netapi32, EntryPoint = "DsGetSiteNameW", CharSet = CharSet.Unicode)]
         public static extern int DsGetSiteName(string? dcName, ref IntPtr ptr);
 
         public delegate int DsListDomainsInSiteW(IntPtr handle, [MarshalAs(UnmanagedType.LPWStr)] string site, ref IntPtr info);
 
         public delegate void DsFreeNameResultW(IntPtr result);
 
-        [DllImport("Netapi32.dll", EntryPoint = "DsEnumerateDomainTrustsW", CharSet = CharSet.Unicode)]
+        [DllImport(global::Interop.Libraries.Netapi32, EntryPoint = "DsEnumerateDomainTrustsW", CharSet = CharSet.Unicode)]
         public static extern int DsEnumerateDomainTrustsW(string serverName, int flags, out IntPtr domains, out int count);
 
-        [DllImport("Netapi32.dll", EntryPoint = "NetApiBufferFree")]
+        [DllImport(global::Interop.Libraries.Netapi32, EntryPoint = "NetApiBufferFree")]
         public static extern int NetApiBufferFree(IntPtr buffer);
 
-        [DllImport("Advapi32.dll", EntryPoint = "LogonUserW", CharSet = CharSet.Unicode, SetLastError = true)]
+        [DllImport(global::Interop.Libraries.Advapi32, EntryPoint = "LogonUserW", CharSet = CharSet.Unicode, SetLastError = true)]
         public static extern int LogonUserW(string? lpszUsername, string? lpszDomain, string? lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);
 
-        [DllImport("Advapi32.dll", EntryPoint = "ImpersonateLoggedOnUser", SetLastError = true)]
+        [DllImport(global::Interop.Libraries.Advapi32, EntryPoint = "ImpersonateLoggedOnUser", SetLastError = true)]
         public static extern int ImpersonateLoggedOnUser(IntPtr hToken);
 
-        [DllImport("Advapi32.dll", EntryPoint = "RevertToSelf", SetLastError = true)]
+        [DllImport(global::Interop.Libraries.Advapi32, EntryPoint = "RevertToSelf", SetLastError = true)]
         public static extern int RevertToSelf();
 
-        [DllImport("Advapi32.dll", EntryPoint = "ConvertSidToStringSidW", CharSet = CharSet.Unicode, SetLastError = true)]
+        [DllImport(global::Interop.Libraries.Advapi32, EntryPoint = "ConvertSidToStringSidW", CharSet = CharSet.Unicode, SetLastError = true)]
         public static extern int ConvertSidToStringSidW(IntPtr pSid, ref IntPtr stringSid);
 
-        [DllImport("Advapi32.dll", EntryPoint = "ConvertStringSidToSidW", CharSet = CharSet.Unicode, SetLastError = true)]
+        [DllImport(global::Interop.Libraries.Advapi32, EntryPoint = "ConvertStringSidToSidW", CharSet = CharSet.Unicode, SetLastError = true)]
         public static extern int ConvertStringSidToSidW(IntPtr stringSid, ref IntPtr pSid);
 
-        [DllImport("Advapi32.dll", EntryPoint = "LsaSetForestTrustInformation")]
+        [DllImport(global::Interop.Libraries.Advapi32, EntryPoint = "LsaSetForestTrustInformation")]
         public static extern int LsaSetForestTrustInformation(PolicySafeHandle handle, LSA_UNICODE_STRING target, IntPtr forestTrustInfo, int checkOnly, out IntPtr collisionInfo);
 
-        [DllImport("Advapi32.dll", EntryPoint = "LsaOpenPolicy")]
+        [DllImport(global::Interop.Libraries.Advapi32, EntryPoint = "LsaOpenPolicy")]
         public static extern int LsaOpenPolicy(LSA_UNICODE_STRING target, LSA_OBJECT_ATTRIBUTES objectAttributes, int access, out IntPtr handle);
 
-        [DllImport("Advapi32.dll", EntryPoint = "LsaClose")]
+        [DllImport(global::Interop.Libraries.Advapi32, EntryPoint = "LsaClose")]
         public static extern int LsaClose(IntPtr handle);
 
-        [DllImport("Advapi32.dll", EntryPoint = "LsaQueryForestTrustInformation")]
+        [DllImport(global::Interop.Libraries.Advapi32, EntryPoint = "LsaQueryForestTrustInformation")]
         public static extern int LsaQueryForestTrustInformation(PolicySafeHandle handle, LSA_UNICODE_STRING target, ref IntPtr ForestTrustInfo);
 
-        [DllImport("Advapi32.dll", EntryPoint = "LsaQueryTrustedDomainInfoByName")]
+        [DllImport(global::Interop.Libraries.Advapi32, EntryPoint = "LsaQueryTrustedDomainInfoByName")]
         public static extern int LsaQueryTrustedDomainInfoByName(PolicySafeHandle handle, LSA_UNICODE_STRING trustedDomain, TRUSTED_INFORMATION_CLASS infoClass, ref IntPtr buffer);
 
-        [DllImport("Advapi32.dll", EntryPoint = "LsaNtStatusToWinError")]
+        [DllImport(global::Interop.Libraries.Advapi32, EntryPoint = "LsaNtStatusToWinError")]
         public static extern int LsaNtStatusToWinError(int status);
 
-        [DllImport("Advapi32.dll", EntryPoint = "LsaFreeMemory")]
+        [DllImport(global::Interop.Libraries.Advapi32, EntryPoint = "LsaFreeMemory")]
         public static extern int LsaFreeMemory(IntPtr ptr);
 
-        [DllImport("Advapi32.dll", EntryPoint = "LsaSetTrustedDomainInfoByName")]
+        [DllImport(global::Interop.Libraries.Advapi32, EntryPoint = "LsaSetTrustedDomainInfoByName")]
         public static extern int LsaSetTrustedDomainInfoByName(PolicySafeHandle handle, LSA_UNICODE_STRING trustedDomain, TRUSTED_INFORMATION_CLASS infoClass, IntPtr buffer);
 
-        [DllImport("Advapi32.dll", EntryPoint = "LsaOpenTrustedDomainByName")]
+        [DllImport(global::Interop.Libraries.Advapi32, EntryPoint = "LsaOpenTrustedDomainByName")]
         public static extern int LsaOpenTrustedDomainByName(PolicySafeHandle policyHandle, LSA_UNICODE_STRING trustedDomain, int access, ref IntPtr trustedDomainHandle);
 
-        [DllImport("Advapi32.dll", EntryPoint = "LsaDeleteTrustedDomain")]
+        [DllImport(global::Interop.Libraries.Advapi32, EntryPoint = "LsaDeleteTrustedDomain")]
         public static extern int LsaDeleteTrustedDomain(PolicySafeHandle handle, IntPtr pSid);
 
-        [DllImport("netapi32.dll", EntryPoint = "I_NetLogonControl2", CharSet = CharSet.Unicode)]
+        [DllImport(global::Interop.Libraries.Netapi32, EntryPoint = "I_NetLogonControl2", CharSet = CharSet.Unicode)]
         public static extern int I_NetLogonControl2(string serverName, int FunctionCode, int QueryLevel, IntPtr data, out IntPtr buffer);
 
-        [DllImport("Kernel32.dll", EntryPoint = "GetSystemTimeAsFileTime")]
+        [DllImport(global::Interop.Libraries.Kernel32, EntryPoint = "GetSystemTimeAsFileTime")]
         public static extern void GetSystemTimeAsFileTime(IntPtr fileTime);
 
-        [DllImport("Advapi32.dll", EntryPoint = "LsaQueryInformationPolicy")]
+        [DllImport(global::Interop.Libraries.Advapi32, EntryPoint = "LsaQueryInformationPolicy")]
         public static extern int LsaQueryInformationPolicy(PolicySafeHandle handle, int infoClass, out IntPtr buffer);
 
-        [DllImport("Advapi32.dll", EntryPoint = "LsaCreateTrustedDomainEx")]
+        [DllImport(global::Interop.Libraries.Advapi32, EntryPoint = "LsaCreateTrustedDomainEx")]
         public static extern int LsaCreateTrustedDomainEx(PolicySafeHandle handle, TRUSTED_DOMAIN_INFORMATION_EX domainEx, TRUSTED_DOMAIN_AUTH_INFORMATION authInfo, int classInfo, out IntPtr domainHandle);
 
-        [DllImport("Kernel32.dll", EntryPoint = "OpenThread", SetLastError = true)]
+        [DllImport(global::Interop.Libraries.Kernel32, EntryPoint = "OpenThread", SetLastError = true)]
         public static extern IntPtr OpenThread(uint desiredAccess, bool inheirted, int threadID);
 
-        [DllImport("Kernel32.dll", EntryPoint = "GetCurrentThreadId")]
+        [DllImport(global::Interop.Libraries.Kernel32, EntryPoint = "GetCurrentThreadId")]
         public static extern int GetCurrentThreadId();
 
-        [DllImport("Advapi32.dll", EntryPoint = "ImpersonateAnonymousToken", SetLastError = true)]
+        [DllImport(global::Interop.Libraries.Advapi32, EntryPoint = "ImpersonateAnonymousToken", SetLastError = true)]
         public static extern int ImpersonateAnonymousToken(IntPtr token);
 
-        [DllImport("Kernel32.dll", EntryPoint = "CloseHandle")]
+        [DllImport(global::Interop.Libraries.Kernel32, EntryPoint = "CloseHandle")]
         public static extern int CloseHandle(IntPtr handle);
 
-        [DllImport("ntdll.dll", EntryPoint = "RtlInitUnicodeString")]
+        [DllImport(global::Interop.Libraries.NtDll, EntryPoint = "RtlInitUnicodeString")]
         public static extern int RtlInitUnicodeString(LSA_UNICODE_STRING result, IntPtr s);
 
-        [DllImport("Kernel32.dll", EntryPoint = "LoadLibraryW", CharSet = CharSet.Unicode, SetLastError = true)]
+        [DllImport(global::Interop.Libraries.Kernel32, EntryPoint = "LoadLibraryW", CharSet = CharSet.Unicode, SetLastError = true)]
         public static extern IntPtr LoadLibrary(string name);
 
-        [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
+        [DllImport(global::Interop.Libraries.Kernel32, CharSet = CharSet.Unicode)]
         public static extern uint FreeLibrary(IntPtr libName);
 
-        [DllImport("kernel32.dll", EntryPoint = "GetProcAddress", SetLastError = true, BestFitMapping = false)]
+        [DllImport(global::Interop.Libraries.Kernel32, EntryPoint = "GetProcAddress", SetLastError = true, BestFitMapping = false)]
         public static extern IntPtr GetProcAddress(LoadLibrarySafeHandle hModule, string entryPoint);
 
         /*
@@ -749,40 +749,40 @@ namespace System.DirectoryServices.ActiveDirectory
           PBYTE* Buffer
         ); */
 
-        [DllImport("Netapi32.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "DsRoleGetPrimaryDomainInformation", CharSet = CharSet.Unicode)]
+        [DllImport(global::Interop.Libraries.Netapi32, CallingConvention = CallingConvention.StdCall, EntryPoint = "DsRoleGetPrimaryDomainInformation", CharSet = CharSet.Unicode)]
         public static extern int DsRoleGetPrimaryDomainInformation(
             [MarshalAs(UnmanagedType.LPTStr)] string lpServer,
             [In] DSROLE_PRIMARY_DOMAIN_INFO_LEVEL InfoLevel,
             out IntPtr Buffer);
 
-        [DllImport("Netapi32.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "DsRoleGetPrimaryDomainInformation", CharSet = CharSet.Unicode)]
+        [DllImport(global::Interop.Libraries.Netapi32, CallingConvention = CallingConvention.StdCall, EntryPoint = "DsRoleGetPrimaryDomainInformation", CharSet = CharSet.Unicode)]
         public static extern int DsRoleGetPrimaryDomainInformation(
             [In] IntPtr lpServer,
             [In] DSROLE_PRIMARY_DOMAIN_INFO_LEVEL InfoLevel,
             out IntPtr Buffer);
 
-        [DllImport("advapi32.dll")]
+        [DllImport(global::Interop.Libraries.Advapi32)]
         public static extern int GetLengthSid(IntPtr sid);
 
-        [DllImport("advapi32.dll", SetLastError = true)]
+        [DllImport(global::Interop.Libraries.Advapi32, SetLastError = true)]
         public static extern bool IsValidSid(IntPtr sid);
 
-        [DllImport("advapi32.dll")]
+        [DllImport(global::Interop.Libraries.Advapi32)]
         public static extern IntPtr GetSidIdentifierAuthority(IntPtr sid);
 
-        [DllImport("advapi32.dll")]
+        [DllImport(global::Interop.Libraries.Advapi32)]
         public static extern IntPtr GetSidSubAuthority(IntPtr sid, int index);
 
-        [DllImport("advapi32.dll")]
+        [DllImport(global::Interop.Libraries.Advapi32)]
         public static extern IntPtr GetSidSubAuthorityCount(IntPtr sid);
 
-        [DllImport("advapi32.dll")]
+        [DllImport(global::Interop.Libraries.Advapi32)]
         public static extern bool EqualDomainSid(IntPtr pSid1, IntPtr pSid2, ref bool equal);
 
-        [DllImport("advapi32.dll", SetLastError = true)]
+        [DllImport(global::Interop.Libraries.Advapi32, SetLastError = true)]
         public static extern bool CopySid(int destinationLength, IntPtr pSidDestination, IntPtr pSidSource);
 
-        [DllImport("advapi32.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, EntryPoint = "OpenThreadToken", CharSet = CharSet.Unicode)]
+        [DllImport(global::Interop.Libraries.Advapi32, SetLastError = true, CallingConvention = CallingConvention.StdCall, EntryPoint = "OpenThreadToken", CharSet = CharSet.Unicode)]
         public static extern bool OpenThreadToken(
                                         IntPtr threadHandle,
                                         int desiredAccess,
@@ -790,20 +790,20 @@ namespace System.DirectoryServices.ActiveDirectory
                                         ref IntPtr tokenHandle
                                         );
 
-        [DllImport("advapi32.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, EntryPoint = "OpenProcessToken", CharSet = CharSet.Unicode)]
+        [DllImport(global::Interop.Libraries.Advapi32, SetLastError = true, CallingConvention = CallingConvention.StdCall, EntryPoint = "OpenProcessToken", CharSet = CharSet.Unicode)]
         public static extern bool OpenProcessToken(
                                         IntPtr processHandle,
                                         int desiredAccess,
                                         ref IntPtr tokenHandle
                                         );
 
-        [DllImport("kernel32.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetCurrentThread", CharSet = CharSet.Unicode)]
+        [DllImport(global::Interop.Libraries.Kernel32, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetCurrentThread", CharSet = CharSet.Unicode)]
         public static extern IntPtr GetCurrentThread();
 
-        [DllImport("kernel32.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "GetCurrentProcess", CharSet = CharSet.Unicode)]
+        [DllImport(global::Interop.Libraries.Kernel32, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetCurrentProcess", CharSet = CharSet.Unicode)]
         public static extern IntPtr GetCurrentProcess();
 
-        [DllImport("advapi32.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetTokenInformation", CharSet = CharSet.Unicode)]
+        [DllImport(global::Interop.Libraries.Advapi32, SetLastError = true, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetTokenInformation", CharSet = CharSet.Unicode)]
         public static extern bool GetTokenInformation(
                                         IntPtr tokenHandle,
                                         int tokenInformationClass,
@@ -812,21 +812,21 @@ namespace System.DirectoryServices.ActiveDirectory
                                         ref int returnLength
                                         );
 
-        [DllImport("advapi32.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "LsaOpenPolicy", CharSet = CharSet.Unicode)]
+        [DllImport(global::Interop.Libraries.Advapi32, CallingConvention = CallingConvention.StdCall, EntryPoint = "LsaOpenPolicy", CharSet = CharSet.Unicode)]
         public static extern int LsaOpenPolicy(
                                         IntPtr lsaUnicodeString,
                                         IntPtr lsaObjectAttributes,
                                         int desiredAccess,
                                         ref IntPtr policyHandle);
 
-        [DllImport("advapi32.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "LsaQueryInformationPolicy", CharSet = CharSet.Unicode)]
+        [DllImport(global::Interop.Libraries.Advapi32, CallingConvention = CallingConvention.StdCall, EntryPoint = "LsaQueryInformationPolicy", CharSet = CharSet.Unicode)]
         public static extern int LsaQueryInformationPolicy(
                                         IntPtr policyHandle,
                                         int policyInformationClass,
                                         ref IntPtr buffer
                                         );
 
-        [DllImport("advapi32.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "LsaLookupSids", CharSet = CharSet.Unicode)]
+        [DllImport(global::Interop.Libraries.Advapi32, CallingConvention = CallingConvention.StdCall, EntryPoint = "LsaLookupSids", CharSet = CharSet.Unicode)]
         public static extern int LsaLookupSids(
                                         IntPtr policyHandle,
                                         int count,
@@ -840,7 +840,7 @@ namespace System.DirectoryServices.ActiveDirectory
           PVOID Buffer
         );
         */
-        [DllImport("Netapi32.dll")]
+        [DllImport(global::Interop.Libraries.Netapi32)]
         public static extern int DsRoleFreeMemory(
             [In] IntPtr buffer);
     }
diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ExternDll.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ExternDll.cs
deleted file mode 100644 (file)
index df541f4..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-namespace System
-{
-    internal static class ExternDll
-    {
-        public const string Activeds = "activeds.dll";
-        public const string Advapi32 = "advapi32.dll";
-        public const string Comctl32 = "comctl32.dll";
-        public const string Comdlg32 = "comdlg32.dll";
-        public const string Gdi32 = "gdi32.dll";
-        public const string Gdiplus = "gdiplus.dll";
-        public const string Hhctrl = "hhctrl.ocx";
-        public const string Imm32 = "imm32.dll";
-        public const string Kernel32 = "kernel32.dll";
-        public const string Loadperf = "Loadperf.dll";
-        public const string Mscoree = "mscoree.dll";
-        public const string Clr = "clr.dll";
-        public const string Msi = "msi.dll";
-        public const string Mqrt = "mqrt.dll";
-        public const string Ntdll = "ntdll.dll";
-        public const string Ole32 = "ole32.dll";
-        public const string Oleacc = "oleacc.dll";
-        public const string Oleaut32 = "oleaut32.dll";
-        public const string Olepro32 = "olepro32.dll";
-        public const string PerfCounter = "perfcounter.dll";
-        public const string Powrprof = "Powrprof.dll";
-        public const string Psapi = "psapi.dll";
-        public const string Shell32 = "shell32.dll";
-        public const string User32 = "user32.dll";
-        public const string Uxtheme = "uxtheme.dll";
-        public const string WinMM = "winmm.dll";
-        public const string Winspool = "winspool.drv";
-        public const string Wtsapi32 = "wtsapi32.dll";
-        public const string Version = "version.dll";
-        public const string Vsassert = "vsassert.dll";
-        public const string Fxassert = "Fxassert.dll";
-        public const string Shlwapi = "shlwapi.dll";
-        public const string Crypt32 = "crypt32.dll";
-
-        // system.data specific
-        internal const string Odbc32 = "odbc32.dll";
-        internal const string SNI = "System.Data.dll";
-
-        // system.data.oracleclient specific
-        internal const string OciDll = "oci.dll";
-        internal const string OraMtsDll = "oramts.dll";
-    }
-}