@@ -7150,7 +7150,7 @@ internal static bool WinPathIsNetworkPath(string path)
7150
7150
return NativeMethods . PathIsNetworkPath ( path ) ; // call the native method
7151
7151
}
7152
7152
7153
- private static class NativeMethods
7153
+ private static partial class NativeMethods
7154
7154
{
7155
7155
/// <summary>
7156
7156
/// WNetAddConnection2 API makes a connection to a network resource
@@ -7196,8 +7196,8 @@ private static class NativeMethods
7196
7196
/// else the error code describing the type of failure that occurred while
7197
7197
/// trying to remove the connection is returned.
7198
7198
/// </returns>
7199
- [ DllImport ( "mpr.dll" , CharSet = CharSet . Unicode ) ]
7200
- internal static extern int WNetCancelConnection2 ( string driveName , int flags , bool force ) ;
7199
+ [ LibraryImport ( "mpr.dll" , EntryPoint = "WNetCancelConnection2W" , StringMarshalling = StringMarshalling . Utf16 ) ]
7200
+ internal static partial int WNetCancelConnection2 ( string driveName , int flags , [ MarshalAs ( UnmanagedType . Bool ) ] bool force ) ;
7201
7201
7202
7202
/// <summary>
7203
7203
/// WNetGetConnection function retrieves the name of the network resource associated with a local device.
@@ -7223,8 +7223,8 @@ private static class NativeMethods
7223
7223
/// Path of the file being executed
7224
7224
/// </param>
7225
7225
/// <returns>Returns 0 through 25 (corresponding to 'A' through 'Z') if the path has a drive letter, or -1 otherwise.</returns>
7226
- [ DllImport ( "api-ms-win-core-shlwapi-legacy-l1-1-0.dll" , CharSet = CharSet . Unicode ) ]
7227
- internal static extern int PathGetDriveNumber ( string path ) ;
7226
+ [ LibraryImport ( "api-ms-win-core-shlwapi-legacy-l1-1-0.dll" , EntryPoint = "PathGetDriveNumberW" , StringMarshalling = StringMarshalling . Utf16 ) ]
7227
+ internal static partial int PathGetDriveNumber ( string path ) ;
7228
7228
7229
7229
private static bool _WNetApiAvailable = true ;
7230
7230
@@ -7288,9 +7288,9 @@ internal static bool PathIsNetworkPath(string path)
7288
7288
/// Path of the file being executed.
7289
7289
/// </param>
7290
7290
/// <returns>True if the path is a network path or else returns false.</returns>
7291
- [ DllImport ( "shlwapi.dll" , CharSet = CharSet . Unicode ) ]
7291
+ [ LibraryImport ( "shlwapi.dll" , EntryPoint = "PathIsNetworkPathW" , StringMarshalling = StringMarshalling . Utf16 ) ]
7292
7292
[ return : MarshalAs ( UnmanagedType . Bool ) ]
7293
- internal static extern bool PathIsNetworkPath ( string path ) ;
7293
+ internal static partial bool PathIsNetworkPath ( string path ) ;
7294
7294
#endif
7295
7295
7296
7296
/// <summary>
@@ -7320,9 +7320,9 @@ internal static bool PathIsNetworkPath(string path)
7320
7320
/// <param name="destination">Path of the target of the symbolic link.</param>
7321
7321
/// <param name="symbolicLinkFlags">Flag values from SymbolicLinkFlags enum.</param>
7322
7322
/// <returns>1 on successful creation.</returns>
7323
- [ DllImport ( PinvokeDllNames . CreateSymbolicLinkDllName , CharSet = CharSet . Unicode , SetLastError = true ) ]
7323
+ [ LibraryImport ( PinvokeDllNames . CreateSymbolicLinkDllName , EntryPoint = "CreateSymbolicLinkW" , StringMarshalling = StringMarshalling . Utf16 ) ]
7324
7324
[ return : MarshalAs ( UnmanagedType . I1 ) ]
7325
- internal static extern bool CreateSymbolicLink ( string name , string destination , SymbolicLinkFlags symbolicLinkFlags ) ;
7325
+ internal static partial bool CreateSymbolicLink ( string name , string destination , SymbolicLinkFlags symbolicLinkFlags ) ;
7326
7326
7327
7327
/// <summary>
7328
7328
/// Flags used when creating a symbolic link.
@@ -7353,26 +7353,26 @@ internal enum SymbolicLinkFlags
7353
7353
/// <param name="existingFileName">Path to the target of the hard link.</param>
7354
7354
/// <param name="SecurityAttributes"></param>
7355
7355
/// <returns></returns>
7356
- [ DllImport ( PinvokeDllNames . CreateHardLinkDllName , CharSet = CharSet . Unicode , SetLastError = true ) ]
7356
+ [ LibraryImport ( PinvokeDllNames . CreateHardLinkDllName , EntryPoint = "CreateHardLinkW" , StringMarshalling = StringMarshalling . Utf16 ) ]
7357
7357
[ return : MarshalAs ( UnmanagedType . Bool ) ]
7358
- internal static extern bool CreateHardLink ( string name , string existingFileName , IntPtr SecurityAttributes ) ;
7358
+ internal static partial bool CreateHardLink ( string name , string existingFileName , IntPtr SecurityAttributes ) ;
7359
7359
7360
7360
// OneDrive placeholder support
7361
7361
#if ! UNIX
7362
7362
/// <summary>
7363
7363
/// Returns the placeholder compatibility mode for the current process.
7364
7364
/// </summary>
7365
7365
/// <returns>The process's placeholder compatibily mode (PHCM_xxx), or a negative value on error (PCHM_ERROR_xxx).</returns>
7366
- [ DllImport ( "ntdll.dll" ) ]
7367
- internal static extern sbyte RtlQueryProcessPlaceholderCompatibilityMode ( ) ;
7366
+ [ LibraryImport ( "ntdll.dll" ) ]
7367
+ internal static partial sbyte RtlQueryProcessPlaceholderCompatibilityMode ( ) ;
7368
7368
7369
7369
/// <summary>
7370
7370
/// Sets the placeholder compatibility mode for the current process.
7371
7371
/// </summary>
7372
7372
/// <param name="pcm">The placeholder compatibility mode to set.</param>
7373
7373
/// <returns>The process's previous placeholder compatibily mode (PHCM_xxx), or a negative value on error (PCHM_ERROR_xxx).</returns>
7374
- [ DllImport ( "ntdll.dll" ) ]
7375
- internal static extern sbyte RtlSetProcessPlaceholderCompatibilityMode ( sbyte pcm ) ;
7374
+ [ LibraryImport ( "ntdll.dll" ) ]
7375
+ internal static partial sbyte RtlSetProcessPlaceholderCompatibilityMode ( sbyte pcm ) ;
7376
7376
7377
7377
internal const sbyte PHCM_APPLICATION_DEFAULT = 0 ;
7378
7378
internal const sbyte PHCM_DISGUISE_PLACEHOLDER = 1 ;
@@ -7870,7 +7870,7 @@ public class FileSystemProviderRemoveItemDynamicParameters
7870
7870
/// <summary>
7871
7871
/// Class to find the symbolic link target.
7872
7872
/// </summary>
7873
- public static class InternalSymbolicLinkLinkCodeMethods
7873
+ public static partial class InternalSymbolicLinkLinkCodeMethods
7874
7874
{
7875
7875
// This size comes from measuring the size of the header of REPARSE_GUID_DATA_BUFFER
7876
7876
private const int REPARSE_GUID_DATA_BUFFER_HEADER_SIZE = 24 ;
@@ -7984,9 +7984,9 @@ private struct REPARSE_DATA_BUFFER_MOUNTPOINT
7984
7984
private struct BY_HANDLE_FILE_INFORMATION
7985
7985
{
7986
7986
public uint FileAttributes ;
7987
- public System . Runtime . InteropServices . ComTypes . FILETIME CreationTime ;
7988
- public System . Runtime . InteropServices . ComTypes . FILETIME LastAccessTime ;
7989
- public System . Runtime . InteropServices . ComTypes . FILETIME LastWriteTime ;
7987
+ public FILE_TIME CreationTime ;
7988
+ public FILE_TIME LastAccessTime ;
7989
+ public FILE_TIME LastWriteTime ;
7990
7990
public uint VolumeSerialNumber ;
7991
7991
public uint FileSizeHigh ;
7992
7992
public uint FileSizeLow ;
@@ -7995,6 +7995,12 @@ private struct BY_HANDLE_FILE_INFORMATION
7995
7995
public uint FileIndexLow ;
7996
7996
}
7997
7997
7998
+ internal struct FILE_TIME
7999
+ {
8000
+ public uint dwLowDateTime ;
8001
+ public uint dwHighDateTime ;
8002
+ }
8003
+
7998
8004
[ StructLayout ( LayoutKind . Sequential ) ]
7999
8005
private struct GUID
8000
8006
{
@@ -8018,20 +8024,21 @@ private struct REPARSE_GUID_DATA_BUFFER
8018
8024
public char [ ] DataBuffer ;
8019
8025
}
8020
8026
8021
- [ DllImport ( PinvokeDllNames . DeviceIoControlDllName , CharSet = CharSet . Unicode , ExactSpelling = true , SetLastError = true ) ]
8022
- private static extern bool DeviceIoControl ( IntPtr hDevice , uint dwIoControlCode ,
8027
+ [ LibraryImport ( PinvokeDllNames . DeviceIoControlDllName , StringMarshalling = StringMarshalling . Utf16 , SetLastError = true ) ]
8028
+ [ return : MarshalAs ( UnmanagedType . Bool ) ]
8029
+ private static partial bool DeviceIoControl ( IntPtr hDevice , uint dwIoControlCode ,
8023
8030
IntPtr InBuffer , int nInBufferSize ,
8024
8031
IntPtr OutBuffer , int nOutBufferSize ,
8025
8032
out int pBytesReturned , IntPtr lpOverlapped ) ;
8026
8033
8027
- [ DllImport ( PinvokeDllNames . GetFileInformationByHandleDllName , SetLastError = true , CharSet = CharSet . Unicode ) ]
8034
+ [ LibraryImport ( PinvokeDllNames . GetFileInformationByHandleDllName ) ]
8028
8035
[ return : MarshalAs ( UnmanagedType . Bool ) ]
8029
- private static extern bool GetFileInformationByHandle (
8036
+ private static partial bool GetFileInformationByHandle (
8030
8037
IntPtr hFile ,
8031
8038
out BY_HANDLE_FILE_INFORMATION lpFileInformation ) ;
8032
8039
8033
- [ DllImport ( PinvokeDllNames . CreateFileDllName , SetLastError = true , CharSet = CharSet . Unicode ) ]
8034
- internal static extern IntPtr CreateFile (
8040
+ [ LibraryImport ( PinvokeDllNames . CreateFileDllName , EntryPoint = "CreateFileW" , SetLastError = true , StringMarshalling = StringMarshalling . Utf16 ) ]
8041
+ internal static partial IntPtr CreateFile (
8035
8042
string lpFileName ,
8036
8043
FileDesiredAccess dwDesiredAccess ,
8037
8044
FileShareMode dwShareMode ,
@@ -8040,7 +8047,7 @@ internal static extern IntPtr CreateFile(
8040
8047
FileAttributes dwFlagsAndAttributes ,
8041
8048
IntPtr hTemplateFile ) ;
8042
8049
8043
- internal sealed class SafeFindHandle : SafeHandleZeroOrMinusOneIsInvalid
8050
+ internal sealed partial class SafeFindHandle : SafeHandleZeroOrMinusOneIsInvalid
8044
8051
{
8045
8052
private SafeFindHandle ( ) : base ( true ) { }
8046
8053
@@ -8049,23 +8056,23 @@ protected override bool ReleaseHandle()
8049
8056
return FindClose ( this . handle ) ;
8050
8057
}
8051
8058
8052
- [ DllImport ( PinvokeDllNames . FindCloseDllName ) ]
8059
+ [ LibraryImport ( PinvokeDllNames . FindCloseDllName ) ]
8053
8060
[ return : MarshalAs ( UnmanagedType . Bool ) ]
8054
- private static extern bool FindClose ( IntPtr handle ) ;
8061
+ private static partial bool FindClose ( IntPtr handle ) ;
8055
8062
}
8056
8063
8057
8064
// We use 'FindFirstFileW' instead of 'FindFirstFileExW' because the latter doesn't work correctly with Unicode file names on FAT32.
8058
8065
// See https://github.com/PowerShell/PowerShell/issues/16804
8059
- [ DllImport ( PinvokeDllNames . FindFirstFileDllName , EntryPoint = "FindFirstFileW" , SetLastError = true , CharSet = CharSet . Unicode ) ]
8060
- private static extern SafeFindHandle FindFirstFile ( string lpFileName , ref WIN32_FIND_DATA lpFindFileData ) ;
8066
+ [ LibraryImport ( PinvokeDllNames . FindFirstFileDllName , EntryPoint = "FindFirstFileW" , SetLastError = true , StringMarshalling = StringMarshalling . Utf16 ) ]
8067
+ private static partial SafeFindHandle FindFirstFile ( string lpFileName , ref WIN32_FIND_DATA lpFindFileData ) ;
8061
8068
8062
8069
[ StructLayout ( LayoutKind . Sequential , CharSet = CharSet . Unicode ) ]
8063
8070
internal unsafe struct WIN32_FIND_DATA
8064
8071
{
8065
8072
internal uint dwFileAttributes ;
8066
- internal System . Runtime . InteropServices . ComTypes . FILETIME ftCreationTime ;
8067
- internal System . Runtime . InteropServices . ComTypes . FILETIME ftLastAccessTime ;
8068
- internal System . Runtime . InteropServices . ComTypes . FILETIME ftLastWriteTime ;
8073
+ internal FILE_TIME ftCreationTime ;
8074
+ internal FILE_TIME ftLastAccessTime ;
8075
+ internal FILE_TIME ftLastWriteTime ;
8069
8076
internal uint nFileSizeHigh ;
8070
8077
internal uint nFileSizeLow ;
8071
8078
internal uint dwReserved0 ;
@@ -8539,7 +8546,7 @@ public class AlternateStreamData
8539
8546
/// </summary>
8540
8547
[ System . Diagnostics . CodeAnalysis . SuppressMessage ( "Microsoft.MSInternal" , "CA903:InternalNamespaceShouldNotContainPublicTypes" ,
8541
8548
Justification = "Needed by both the FileSystem provider and Unblock-File cmdlet." ) ]
8542
- public static class AlternateDataStreamUtilities
8549
+ public static partial class AlternateDataStreamUtilities
8543
8550
{
8544
8551
/// <summary>
8545
8552
/// List all of the streams on a file.
@@ -8704,15 +8711,15 @@ internal static void SetZoneOfOrigin(string path, SecurityZone securityZone)
8704
8711
// the code above seems cleaner and more robust than the IAttachmentExecute approach
8705
8712
}
8706
8713
8707
- internal static class NativeMethods
8714
+ internal static partial class NativeMethods
8708
8715
{
8709
8716
internal const int ERROR_HANDLE_EOF = 38 ;
8710
8717
internal const int ERROR_INVALID_PARAMETER = 87 ;
8711
8718
8712
8719
internal enum StreamInfoLevels { FindStreamInfoStandard = 0 }
8713
8720
8714
- [ DllImport ( PinvokeDllNames . CreateFileDllName , CharSet = CharSet . Unicode , SetLastError = true ) ]
8715
- internal static extern SafeFileHandle CreateFile ( string lpFileName ,
8721
+ [ LibraryImport ( PinvokeDllNames . CreateFileDllName , EntryPoint = "CreateFileW" , SetLastError = true , StringMarshalling = StringMarshalling . Utf16 ) ]
8722
+ internal static partial SafeFileHandle CreateFile ( string lpFileName ,
8716
8723
FileAccess dwDesiredAccess , FileShare dwShareMode ,
8717
8724
IntPtr lpSecurityAttributes , FileMode dwCreationDisposition ,
8718
8725
int dwFlagsAndAttributes , IntPtr hTemplateFile ) ;
@@ -8733,7 +8740,7 @@ internal static extern bool FindNextStreamW(
8733
8740
AlternateStreamNativeData lpFindStreamData ) ;
8734
8741
}
8735
8742
8736
- internal sealed class SafeFindHandle : SafeHandleZeroOrMinusOneIsInvalid
8743
+ internal sealed partial class SafeFindHandle : SafeHandleZeroOrMinusOneIsInvalid
8737
8744
{
8738
8745
private SafeFindHandle ( ) : base ( true ) { }
8739
8746
@@ -8742,9 +8749,9 @@ protected override bool ReleaseHandle()
8742
8749
return FindClose ( this . handle ) ;
8743
8750
}
8744
8751
8745
- [ DllImport ( PinvokeDllNames . FindCloseDllName ) ]
8752
+ [ LibraryImport ( PinvokeDllNames . FindCloseDllName ) ]
8746
8753
[ return : MarshalAs ( UnmanagedType . Bool ) ]
8747
- private static extern bool FindClose ( IntPtr handle ) ;
8754
+ private static partial bool FindClose ( IntPtr handle ) ;
8748
8755
}
8749
8756
8750
8757
/// <summary>
0 commit comments