Win32Interop
Win32Interop copied to clipboard
Kernel32.CreateHardLink() can't be called as documented
The CreateHardLink function documentation reads:
lpSecurityAttributes Reserved; must be NULL.
...however the declaration [currently] reads:
[DllImport("kernel32.dll", EntryPoint = "CreateHardLink")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CreateHardLink(
[In] [MarshalAs(UnmanagedType.LPTStr)] string lpFileName, [In] [MarshalAs(UnmanagedType.LPTStr)] string lpExistingFileName,
ref SECURITY_ATTRIBUTES lpSecurityAttributes);
...which means I can not use IntPtr.Zero
as the last parameter. I also can't use null
, because SECURITY_ATTRIBUTES is a struct
and the compiler wants me to initialize a ref
parameter.
It would be better to declare it as:
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern bool CreateHardLink(string newFileName, string existingFileName, IntPtr securityAttributes);