Skip to content

Kernel32.CreateHardLink() can't be called as documented #4

@olivierdagenais

Description

@olivierdagenais

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions