using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.ConstrainedExecution; using System.Runtime.InteropServices; using System.Security; using System.Text; using Vanara.Extensions; using Vanara.InteropServices; using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME; namespace Vanara.PInvoke { public static partial class Kernel32 { /// Flags used in the function. [PInvokeData("WinBase.h")] public enum SymbolicLinkType : uint { /// The link target is a file. SYMBOLIC_LINK_FLAG_FILE = 0x0, /// The link target is a directory. SYMBOLIC_LINK_FLAG_DIRECTORY = 0x1 } /// /// Creates a symbolic link. /// /// The symbolic link to be created. /// This parameter may include the path. In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming a File. /// Tip Starting with Windows 10, version 1607, for the Unicode version of this function (CreateSymbolicLinkW), you can opt-in to remove the MAX_PATH limitation without prepending "\\?\". See the "Maximum Path Length Limitation" section of Naming Files, Paths, and Namespaces for details. /// The name of the target for the symbolic link to be created. /// If lpTargetFileName has a device name associated with it, the link is treated as an absolute link; otherwise, the link is treated as a relative link. /// This parameter may include the path. In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming a File. /// Tip Starting with Windows 10, version 1607, for the Unicode version of this function (CreateSymbolicLinkW), you can opt-in to remove the MAX_PATH limitation without prepending "\\?\". See the "Maximum Path Length Limitation" section of Naming Files, Paths, and Namespaces for details. /// Indicates whether the link target, lpTargetFileName, is a directory. /// f the function succeeds, the return value is nonzero. If the function fails, the return value is zero.To get extended error information, call GetLastError. [DllImport(Lib.Kernel32, CharSet = CharSet.Auto, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] [PInvokeData("WinBase.h", MSDNShortId = "aa363866")] public static extern bool CreateSymbolicLink(string lpSymlinkFileName, string lpTargetFileName, SymbolicLinkType dwFlags); /// /// Establishes a hard link between an existing file and a new file. This function is only supported on the NTFS file system, and only for files, not directories. /// /// The name of the new file. /// This parameter may include the path but cannot specify the name of a directory. /// In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming a File. /// Tip Starting with Windows 10, version 1607, for the Unicode version of this function (CreateHardLinkW), you can opt-in to remove the MAX_PATH limitation without prepending "\\?\". See the "Maximum Path Length Limitation" section of Naming Files, Paths, and Namespaces for details. /// The name of the existing file. /// This parameter may include the path but cannot specify the name of a directory. /// In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming a File. /// Tip Starting with Windows 10, version 1607, for the Unicode version of this function (CreateHardLinkW), you can opt-in to remove the MAX_PATH limitation without prepending "\\?\". See the "Maximum Path Length Limitation" section of Naming Files, Paths, and Namespaces for details. /// Reserved; must be NULL. /// [DllImport(Lib.Kernel32, CharSet = CharSet.Auto, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] [PInvokeData("WinBase.h", MSDNShortId = "aa363860")] public static extern bool CreateHardLink(string lpFileName, string lpExistingFileName, [Optional] IntPtr lpSecurityAttributes); /// /// Retrieves the actual number of bytes of disk storage used to store a specified file. If the file is located on a volume that supports compression and /// the file is compressed, the value obtained is the compressed size of the specified file. If the file is located on a volume that supports sparse /// files and the file is a sparse file, the value obtained is the sparse size of the specified file. /// /// /// The name of the file. /// Do not specify the name of a file on a nonseeking device, such as a pipe or a communications device, as its file size has no meaning. /// /// This parameter may include the path. In the ANSI version of this function, the name is limited to characters. To extend this /// limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming a File. /// /// /// Tip Starting with Windows 10, version 1607, for the Unicode version of this function ( GetCompressedFileSizeW), you can opt-in to /// remove the limitation without prepending "\\?\". See the "Maximum Path Length Limitation" section of Naming Files, Paths, and Namespaces for details. /// /// /// /// The high-order DWORD of the compressed file size. The function's return value is the low-order DWORD of the compressed file size. /// /// This parameter can be NULL if the high-order DWORD of the compressed file size is not needed.Files less than 4 gigabytes in size do not need the /// high-order DWORD. /// /// /// /// If the function succeeds, the return value is the low-order DWORD of the actual number of bytes of disk storage used to store the specified file, and /// if is non-NULL, the function puts the high-order DWORD of that actual value into the DWORD pointed to by that /// parameter. This is the compressed file size for compressed files, the actual file size for noncompressed files. /// /// If the function fails, and is NULL, the return value is INVALID_FILE_SIZE. To get extended error information, call GetLastError. /// /// /// If the return value is INVALID_FILE_SIZE and is non-NULL, an application must call GetLastError to determine /// whether the function has succeeded (value is NO_ERROR) or failed (value is other than NO_ERROR). /// /// /// /// An application can determine whether a volume is compressed by calling , /// then checking the status of the FS_VOL_IS_COMPRESSED flag in the DWORD value pointed to by that function's lpFileSystemFlags parameter. /// /// If the file is not located on a volume that supports compression or sparse files, or if the file is not compressed or a sparse file, the value /// obtained is the actual file size, the same as the value returned by a call to GetFileSize. /// /// Symbolic link behavior—If the path points to a symbolic link, the function returns the file size of the target. /// [DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("WinBase.h", MSDNShortId = "aa364930")] public static extern uint GetCompressedFileSize(string lpFileName, ref uint lpFileSizeHigh); } }