Use DLLIMPORTGENERATOR_ENABLED ifdefs for files shared with Microsoft.IO.Redist ...
authorElinor Fung <elfung@microsoft.com>
Thu, 10 Jun 2021 19:36:03 +0000 (12:36 -0700)
committerGitHub <noreply@github.com>
Thu, 10 Jun 2021 19:36:03 +0000 (12:36 -0700)
12 files changed:
src/libraries/Common/src/Interop/Windows/Advapi32/Interop.EncryptDecrypt.cs
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.CopyFileEx.cs
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.CreateFile_IntPtr.cs
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.DeleteFile.cs
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.DeleteVolumeMountPoint.cs
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetLogicalDrives.cs
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetVolumeInformation.cs
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.MoveFileEx.cs
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.RemoveDirectory.cs
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ReplaceFile.cs
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.SetFileAttributes.cs
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.SetFileInformationByHandle.cs

index 8d627e5..ace1122 100644 (file)
@@ -11,8 +11,13 @@ internal static partial class Interop
         /// <summary>
         /// WARNING: This method does not implicitly handle long paths. Use EncryptFile.
         /// </summary>
+#if DLLIMPORTGENERATOR_ENABLED
         [GeneratedDllImport(Libraries.Advapi32, EntryPoint = "EncryptFileW", SetLastError = true, CharSet = CharSet.Unicode)]
         private static partial bool EncryptFilePrivate(string lpFileName);
+#else
+        [DllImport(Libraries.Advapi32, EntryPoint = "EncryptFileW", SetLastError = true, CharSet = CharSet.Unicode)]
+        private static extern bool EncryptFilePrivate(string lpFileName);
+#endif
 
         internal static bool EncryptFile(string path)
         {
@@ -23,8 +28,15 @@ internal static partial class Interop
         /// <summary>
         /// WARNING: This method does not implicitly handle long paths. Use DecryptFile.
         /// </summary>
+#if DLLIMPORTGENERATOR_ENABLED
         [GeneratedDllImport(Libraries.Advapi32, EntryPoint = "DecryptFileW", SetLastError = true, CharSet = CharSet.Unicode)]
-        private static partial bool DecryptFileFilePrivate(string lpFileName, int dwReserved);
+        private static partial bool DecryptFileFilePrivate(
+#else
+        [DllImport(Libraries.Advapi32, EntryPoint = "DecryptFileW", SetLastError = true, CharSet = CharSet.Unicode)]
+        private static extern bool DecryptFileFilePrivate(
+#endif
+            string lpFileName,
+            int dwReserved);
 
         internal static bool DecryptFile(string path)
         {
index 176c010..c878ec9 100644 (file)
@@ -12,8 +12,13 @@ internal static partial class Interop
         /// <summary>
         /// WARNING: This method does not implicitly handle long paths. Use CopyFileEx.
         /// </summary>
+#if DLLIMPORTGENERATOR_ENABLED
         [GeneratedDllImport(Libraries.Kernel32, EntryPoint = "CopyFileExW", SetLastError = true, CharSet = CharSet.Unicode)]
         private static partial bool CopyFileExPrivate(
+#else
+        [DllImport(Libraries.Kernel32, EntryPoint = "CopyFileExW", SetLastError = true, CharSet = CharSet.Unicode)]
+        private static extern bool CopyFileExPrivate(
+#endif
             string src,
             string dst,
             IntPtr progressRoutine,
index fe47b09..cc3bee2 100644 (file)
@@ -12,8 +12,13 @@ internal static partial class Interop
         /// <summary>
         /// WARNING: This method does not implicitly handle long paths. Use CreateFile.
         /// </summary>
+#if DLLIMPORTGENERATOR_ENABLED
         [GeneratedDllImport(Libraries.Kernel32, EntryPoint = "CreateFileW", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true)]
         private static unsafe partial IntPtr CreateFilePrivate_IntPtr(
+#else
+        [DllImport(Libraries.Kernel32, EntryPoint = "CreateFileW", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true)]
+        private static unsafe extern IntPtr CreateFilePrivate_IntPtr(
+#endif
             string lpFileName,
             int dwDesiredAccess,
             FileShare dwShareMode,
index decf6d7..41f2e58 100644 (file)
@@ -12,8 +12,13 @@ internal static partial class Interop
         /// <summary>
         /// WARNING: This method does not implicitly handle long paths. Use DeleteFile.
         /// </summary>
+#if DLLIMPORTGENERATOR_ENABLED
         [GeneratedDllImport(Libraries.Kernel32, EntryPoint = "DeleteFileW", SetLastError = true, CharSet = CharSet.Unicode)]
         private static partial bool DeleteFilePrivate(string path);
+#else
+        [DllImport(Libraries.Kernel32, EntryPoint = "DeleteFileW", SetLastError = true, CharSet = CharSet.Unicode)]
+        private static extern bool DeleteFilePrivate(string path);
+#endif
 
         internal static bool DeleteFile(string path)
         {
index 7910be5..9461da8 100644 (file)
@@ -12,9 +12,13 @@ internal static partial class Interop
         /// <summary>
         /// WARNING: This method does not implicitly handle long paths. Use DeleteVolumeMountPoint.
         /// </summary>
+#if DLLIMPORTGENERATOR_ENABLED
         [GeneratedDllImport(Libraries.Kernel32, EntryPoint = "DeleteVolumeMountPointW", SetLastError = true, CharSet = CharSet.Unicode)]
         internal static partial bool DeleteVolumeMountPointPrivate(string mountPoint);
-
+#else
+        [DllImport(Libraries.Kernel32, EntryPoint = "DeleteVolumeMountPointW", SetLastError = true, CharSet = CharSet.Unicode)]
+        internal static extern bool DeleteVolumeMountPointPrivate(string mountPoint);
+#endif
 
         internal static bool DeleteVolumeMountPoint(string mountPoint)
         {
index f084be9..c756043 100644 (file)
@@ -7,7 +7,12 @@ internal static partial class Interop
 {
     internal static partial class Kernel32
     {
+#if DLLIMPORTGENERATOR_ENABLED
         [GeneratedDllImport(Libraries.Kernel32, SetLastError = true)]
         internal static partial int GetLogicalDrives();
+#else
+        [DllImport(Libraries.Kernel32, SetLastError = true)]
+        internal static extern int GetLogicalDrives();
+#endif
     }
 }
index 67b8dee..05a2b63 100644 (file)
@@ -8,8 +8,21 @@ internal static partial class Interop
 {
     internal static partial class Kernel32
     {
+#if DLLIMPORTGENERATOR_ENABLED
         [GeneratedDllImport(Libraries.Kernel32, EntryPoint = "GetVolumeInformationW", CharSet = CharSet.Unicode, SetLastError = true)]
-        internal static unsafe partial bool GetVolumeInformation(string drive, char* volumeName, int volumeNameBufLen, int* volSerialNumber, int* maxFileNameLen, out int fileSystemFlags, char* fileSystemName, int fileSystemNameBufLen);
+        internal static unsafe partial bool GetVolumeInformation(
+#else
+        [DllImport(Libraries.Kernel32, EntryPoint = "GetVolumeInformationW", CharSet = CharSet.Unicode, SetLastError = true)]
+        internal static unsafe extern bool GetVolumeInformation(
+#endif
+            string drive,
+            char* volumeName,
+            int volumeNameBufLen,
+            int* volSerialNumber,
+            int* maxFileNameLen,
+            out int fileSystemFlags,
+            char* fileSystemName,
+            int fileSystemNameBufLen);
 
         internal const uint FILE_SUPPORTS_ENCRYPTION = 0x00020000;
     }
index 389e7b9..a0b3a39 100644 (file)
@@ -15,8 +15,14 @@ internal static partial class Interop
         /// <summary>
         /// WARNING: This method does not implicitly handle long paths. Use MoveFile.
         /// </summary>
+#if DLLIMPORTGENERATOR_ENABLED
         [GeneratedDllImport(Libraries.Kernel32, EntryPoint = "MoveFileExW", SetLastError = true, CharSet = CharSet.Unicode)]
-        private static partial bool MoveFileExPrivate(string src, string dst, uint flags);
+        private static partial bool MoveFileExPrivate(
+#else
+        [DllImport(Libraries.Kernel32, EntryPoint = "MoveFileExW", SetLastError = true, CharSet = CharSet.Unicode)]
+        private static extern bool MoveFileExPrivate(
+#endif
+            string src, string dst, uint flags);
 
         /// <summary>
         /// Moves a file or directory, optionally overwriting existing destination file. NOTE: overwrite must be false for directories.
index 0588949..f1a6683 100644 (file)
@@ -12,8 +12,13 @@ internal static partial class Interop
         /// <summary>
         /// WARNING: This method does not implicitly handle long paths. Use RemoveDirectory.
         /// </summary>
+#if DLLIMPORTGENERATOR_ENABLED
         [GeneratedDllImport(Libraries.Kernel32, EntryPoint = "RemoveDirectoryW", SetLastError = true, CharSet = CharSet.Unicode)]
         private static partial bool RemoveDirectoryPrivate(string path);
+#else
+        [DllImport(Libraries.Kernel32, EntryPoint = "RemoveDirectoryW", SetLastError = true, CharSet = CharSet.Unicode)]
+        private static extern bool RemoveDirectoryPrivate(string path);
+#endif
 
         internal static bool RemoveDirectory(string path)
         {
index b29552d..051f6c6 100644 (file)
@@ -9,8 +9,13 @@ internal static partial class Interop
 {
     internal static partial class Kernel32
     {
+#if DLLIMPORTGENERATOR_ENABLED
         [GeneratedDllImport(Libraries.Kernel32, EntryPoint = "ReplaceFileW", SetLastError = true, CharSet = CharSet.Unicode)]
         private static partial bool ReplaceFilePrivate(
+#else
+        [DllImport(Libraries.Kernel32, EntryPoint = "ReplaceFileW", SetLastError = true, CharSet = CharSet.Unicode)]
+        private static extern bool ReplaceFilePrivate(
+#endif
             string replacedFileName, string replacementFileName, string? backupFileName,
             int dwReplaceFlags, IntPtr lpExclude, IntPtr lpReserved);
 
index 77a8bf7..03de746 100644 (file)
@@ -11,8 +11,15 @@ internal static partial class Interop
         /// <summary>
         /// WARNING: This method does not implicitly handle long paths. Use SetFileAttributes.
         /// </summary>
+#if DLLIMPORTGENERATOR_ENABLED
         [GeneratedDllImport(Libraries.Kernel32, EntryPoint = "SetFileAttributesW", SetLastError = true, CharSet = CharSet.Unicode)]
-        private static partial bool SetFileAttributesPrivate(string name, int attr);
+        private static partial bool SetFileAttributesPrivate(
+#else
+        [DllImport(Libraries.Kernel32, EntryPoint = "SetFileAttributesW", SetLastError = true, CharSet = CharSet.Unicode)]
+        private static extern bool SetFileAttributesPrivate(
+#endif
+            string name,
+            int attr);
 
         internal static bool SetFileAttributes(string name, int attr)
         {
index 18b6580..9987aec 100644 (file)
@@ -9,7 +9,16 @@ internal static partial class Interop
 {
     internal static partial class Kernel32
     {
+#if DLLIMPORTGENERATOR_ENABLED
         [GeneratedDllImport(Libraries.Kernel32, SetLastError = true, ExactSpelling = true)]
-        internal static unsafe partial bool SetFileInformationByHandle(SafeFileHandle hFile, int FileInformationClass, void* lpFileInformation, uint dwBufferSize);
+        internal static unsafe partial bool SetFileInformationByHandle(
+#else
+        [DllImport(Libraries.Kernel32, SetLastError = true, ExactSpelling = true)]
+        internal static unsafe extern bool SetFileInformationByHandle(
+#endif
+            SafeFileHandle hFile,
+            int FileInformationClass,
+            void* lpFileInformation,
+            uint dwBufferSize);
     }
 }