Skip to content
This repository has been archived by the owner on Jul 26, 2023. It is now read-only.

Add CreateFile overload that doesn't require a string object #535

Merged
merged 2 commits into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/DwmApi/DwmApi.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="MSBuild.Sdk.Extras">
<PropertyGroup>
<TargetFrameworks>$(PlatformAndPortableFrameworks);netstandard2.0</TargetFrameworks>
<TargetFrameworks>$(PlatformAndPortableFrameworks)</TargetFrameworks>
<StoreBanned>true</StoreBanned>
</PropertyGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Kernel32/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,7 @@ static extern PInvoke.Kernel32.CloseHandle(System.IntPtr hObject) -> bool
static extern PInvoke.Kernel32.ConnectNamedPipe(PInvoke.Kernel32.SafeObjectHandle hNamedPipe, PInvoke.Kernel32.OVERLAPPED* lpOverlapped) -> bool
static extern PInvoke.Kernel32.CopyMemory(void* Destination, void* Source, System.IntPtr Length) -> void
static extern PInvoke.Kernel32.CreateConsoleScreenBuffer(PInvoke.Kernel32.ACCESS_MASK dwDesiredAccess, PInvoke.Kernel32.FileShare dwShareMode, PInvoke.Kernel32.SECURITY_ATTRIBUTES* lpSecurityAttributes, PInvoke.Kernel32.ConsoleScreenBufferFlag dwFlags, void* lpScreenBufferData) -> System.IntPtr
static extern PInvoke.Kernel32.CreateFile(string filename, PInvoke.Kernel32.ACCESS_MASK access, PInvoke.Kernel32.FileShare share, PInvoke.Kernel32.SECURITY_ATTRIBUTES* securityAttributes, PInvoke.Kernel32.CreationDisposition creationDisposition, PInvoke.Kernel32.CreateFileFlags flagsAndAttributes, PInvoke.Kernel32.SafeObjectHandle templateFile) -> PInvoke.Kernel32.SafeObjectHandle
static PInvoke.Kernel32.CreateFile(string filename, PInvoke.Kernel32.ACCESS_MASK access, PInvoke.Kernel32.FileShare share, PInvoke.Kernel32.SECURITY_ATTRIBUTES* securityAttributes, PInvoke.Kernel32.CreationDisposition creationDisposition, PInvoke.Kernel32.CreateFileFlags flagsAndAttributes, PInvoke.Kernel32.SafeObjectHandle templateFile) -> PInvoke.Kernel32.SafeObjectHandle
static extern PInvoke.Kernel32.CreateJobObject(PInvoke.Kernel32.SECURITY_ATTRIBUTES* lpJobAttributes, string lpName) -> PInvoke.Kernel32.SafeObjectHandle
static extern PInvoke.Kernel32.CreateMutex(PInvoke.Kernel32.SECURITY_ATTRIBUTES* lpMutexAttributes, bool bInitialOwner, string lpName) -> PInvoke.Kernel32.SafeObjectHandle
static extern PInvoke.Kernel32.CreateNamedPipe(string lpName, PInvoke.Kernel32.PipeAccessMode dwOpenMode, PInvoke.Kernel32.PipeMode dwPipeMode, int nMaxInstances, int nOutBufferSize, int nInBufferSize, int nDefaultTimeOut, PInvoke.Kernel32.SECURITY_ATTRIBUTES* lpSecurityAttributes) -> PInvoke.Kernel32.SafeObjectHandle
Expand Down
4 changes: 4 additions & 0 deletions src/Kernel32/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ override PInvoke.Kernel32.SafePseudoConsoleHandle.IsInvalid.get -> bool
override PInvoke.Kernel32.SafePseudoConsoleHandle.ReleaseHandle() -> bool
static PInvoke.Kernel32.CONSOLE_READCONSOLE_CONTROL.Create() -> PInvoke.Kernel32.CONSOLE_READCONSOLE_CONTROL
static PInvoke.Kernel32.CancelIoEx(PInvoke.Kernel32.SafeObjectHandle hFile, System.Threading.NativeOverlapped* lpOverlapped) -> bool
static PInvoke.Kernel32.CreateFile(System.IntPtr filename, PInvoke.Kernel32.ACCESS_MASK access, PInvoke.Kernel32.FileShare share, System.IntPtr securityAttributes, PInvoke.Kernel32.CreationDisposition creationDisposition, PInvoke.Kernel32.CreateFileFlags flagsAndAttributes, PInvoke.Kernel32.SafeObjectHandle templateFile) -> PInvoke.Kernel32.SafeObjectHandle
static PInvoke.Kernel32.CreateFile(System.ReadOnlySpan<char> filename, PInvoke.Kernel32.ACCESS_MASK access, PInvoke.Kernel32.FileShare share, PInvoke.Kernel32.SECURITY_ATTRIBUTES? securityAttributes, PInvoke.Kernel32.CreationDisposition creationDisposition, PInvoke.Kernel32.CreateFileFlags flagsAndAttributes, PInvoke.Kernel32.SafeObjectHandle templateFile) -> PInvoke.Kernel32.SafeObjectHandle
static PInvoke.Kernel32.CreateFile(char[] filename, PInvoke.Kernel32.ACCESS_MASK access, PInvoke.Kernel32.FileShare share, PInvoke.Kernel32.SECURITY_ATTRIBUTES? securityAttributes, PInvoke.Kernel32.CreationDisposition creationDisposition, PInvoke.Kernel32.CreateFileFlags flagsAndAttributes, PInvoke.Kernel32.SafeObjectHandle templateFile) -> PInvoke.Kernel32.SafeObjectHandle
static PInvoke.Kernel32.CreateRemoteThread(System.IntPtr hProcess, PInvoke.Kernel32.SECURITY_ATTRIBUTES? lpThreadAttributes, System.UIntPtr dwStackSize, PInvoke.Kernel32.THREAD_START_ROUTINE lpStartAddress, System.IntPtr lpParameter, PInvoke.Kernel32.CreateThreadFlags dwCreationFlags, ref uint? lpThreadId) -> PInvoke.Kernel32.SafeObjectHandle
static PInvoke.Kernel32.CreateRemoteThread(System.IntPtr hProcess, PInvoke.Kernel32.SECURITY_ATTRIBUTES? lpThreadAttributes, System.UIntPtr dwStackSize, PInvoke.Kernel32.THREAD_START_ROUTINE lpStartAddress, void* lpParameter, PInvoke.Kernel32.CreateThreadFlags dwCreationFlags, ref uint? lpThreadId) -> PInvoke.Kernel32.SafeObjectHandle
static PInvoke.Kernel32.CreateRemoteThread(System.IntPtr hProcess, System.IntPtr lpThreadAttributes, System.UIntPtr dwStackSize, PInvoke.Kernel32.THREAD_START_ROUTINE lpStartAddress, System.IntPtr lpParameter, PInvoke.Kernel32.CreateThreadFlags dwCreationFlags, System.IntPtr lpThreadId) -> PInvoke.Kernel32.SafeObjectHandle
Expand Down Expand Up @@ -261,6 +264,7 @@ static PInvoke.Kernel32.SetFilePointer(PInvoke.Kernel32.SafeObjectHandle hFile,
static PInvoke.Kernel32.SetFilePointer(PInvoke.Kernel32.SafeObjectHandle hFile, int lDistanceToMove, ref int? lpDistanceToMoveHigh, System.IO.SeekOrigin dwMoveMethod) -> int
static PInvoke.Kernel32.SetProcessInformation(PInvoke.Kernel32.SafeObjectHandle hProcess, PInvoke.Kernel32.PROCESS_INFORMATION_CLASS ProcessInformationClass, System.IntPtr ProcessInformation, uint ProcessInformationSize) -> bool
static PInvoke.Kernel32.WriteFile(PInvoke.Kernel32.SafeObjectHandle hFile, void* lpBuffer, int nNumberOfBytesToWrite, int* lpNumberOfBytesWritten, System.Threading.NativeOverlapped* lpOverlapped) -> bool
static extern PInvoke.Kernel32.CreateFile(char* filename, PInvoke.Kernel32.ACCESS_MASK access, PInvoke.Kernel32.FileShare share, PInvoke.Kernel32.SECURITY_ATTRIBUTES* securityAttributes, PInvoke.Kernel32.CreationDisposition creationDisposition, PInvoke.Kernel32.CreateFileFlags flagsAndAttributes, PInvoke.Kernel32.SafeObjectHandle templateFile) -> PInvoke.Kernel32.SafeObjectHandle
static extern PInvoke.Kernel32.CreatePseudoConsole(PInvoke.COORD size, PInvoke.Kernel32.SafeObjectHandle hInput, PInvoke.Kernel32.SafeObjectHandle hOutput, PInvoke.Kernel32.CreatePseudoConsoleFlags dwFlags, out PInvoke.Kernel32.SafePseudoConsoleHandle phPC) -> PInvoke.HResult
static extern PInvoke.Kernel32.CreateRemoteThread(System.IntPtr hProcess, PInvoke.Kernel32.SECURITY_ATTRIBUTES* lpThreadAttributes, System.UIntPtr dwStackSize, PInvoke.Kernel32.THREAD_START_ROUTINE lpStartAddress, void* lpParameter, PInvoke.Kernel32.CreateThreadFlags dwCreationFlags, uint* lpThreadId) -> PInvoke.Kernel32.SafeObjectHandle
static extern PInvoke.Kernel32.CreateRemoteThreadEx(System.IntPtr hProcess, PInvoke.Kernel32.SECURITY_ATTRIBUTES* lpThreadAttributes, System.UIntPtr dwStackSize, PInvoke.Kernel32.THREAD_START_ROUTINE lpStartAddress, void* lpParameter, PInvoke.Kernel32.CreateThreadFlags dwCreationFlags, PInvoke.Kernel32.PROC_THREAD_ATTRIBUTE_LIST* lpAttributeList, uint* lpThreadId) -> PInvoke.Kernel32.SafeObjectHandle
Expand Down
19 changes: 19 additions & 0 deletions src/Kernel32/storebanned/Kernel32.Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,25 @@ namespace PInvoke
/// </content>
public static partial class Kernel32
{
/// <inheritdoc cref="CreateFile(char*, ACCESS_MASK, FileShare, SECURITY_ATTRIBUTES*, CreationDisposition, CreateFileFlags, SafeObjectHandle)"/>
/// <devremarks>
/// This should be removed as part of delivering <see href="https://github.com/dotnet/pinvoke/issues/286">the string-overload codegen feature</see>.
/// </devremarks>
public static unsafe SafeObjectHandle CreateFile(
string filename,
ACCESS_MASK access,
FileShare share,
[Friendly(FriendlyFlags.In | FriendlyFlags.Optional)] SECURITY_ATTRIBUTES* securityAttributes,
CreationDisposition creationDisposition,
CreateFileFlags flagsAndAttributes,
SafeObjectHandle templateFile)
{
fixed (char* pFileName = filename)
{
return CreateFile(pFileName, access, share, securityAttributes, creationDisposition, flagsAndAttributes, templateFile);
}
}

/// <summary>Retrieves information about the first process encountered in a system snapshot.</summary>
/// <param name="hSnapshot">
/// A handle to the snapshot returned from a previous call to the
Expand Down
4 changes: 2 additions & 2 deletions src/Kernel32/storebanned/Kernel32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ public static unsafe extern void DeleteProcThreadAttributeList(
/// To perform this operation as a transacted operation, which results in a handle that can be used for transacted I/O, use the CreateFileTransacted function.
/// </summary>
/// <param name="filename">
/// The name of the file or device to be created or opened. You may use either forward slashes (/) or backslashes (\) in this name.
/// The name of the file or device to be created or opened as a UTF-16, null-terminated array of characters. You may use either forward slashes (/) or backslashes (\) in this name.
/// In the ANSI version of this function, the name is limited to <see cref="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 Files, Paths, and Namespaces.
/// For information on special device names, see Defining an MS-DOS Device Name.
/// To create a file stream, specify the name of the file, a colon, and then the name of the stream.For more information, see File Streams.
Expand Down Expand Up @@ -747,7 +747,7 @@ public static unsafe extern void DeleteProcThreadAttributeList(
/// </returns>
[DllImport(api_ms_win_core_file_l1_2_0, CharSet = CharSet.Unicode, SetLastError = true)]
public static extern unsafe SafeObjectHandle CreateFile(
string filename,
[Friendly(FriendlyFlags.In | FriendlyFlags.Array)] char* filename,
ACCESS_MASK access,
FileShare share,
[Friendly(FriendlyFlags.In | FriendlyFlags.Optional)] SECURITY_ATTRIBUTES* securityAttributes,
Expand Down
2 changes: 1 addition & 1 deletion src/NCrypt/NCrypt.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="MSBuild.Sdk.Extras">
<PropertyGroup>
<TargetFrameworks>$(PlatformAndPortableFrameworks);netstandard2.0</TargetFrameworks>
<TargetFrameworks>$(PlatformAndPortableFrameworks)</TargetFrameworks>
<NoWarn>$(NoWarn);RS0026;RS0027</NoWarn>
</PropertyGroup>
<ItemGroup>
Expand Down