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

Commit b3af9c4

Browse files
authored
Merge pull request #591 from dotnet/patch-1
Fix ReadConsoleOutput
2 parents 7e6076b + 8383b5e commit b3af9c4

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/Kernel32/PublicAPI.Shipped.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,6 @@ static extern PInvoke.Kernel32.Process32Next(PInvoke.Kernel32.SafeObjectHandle h
13721372
static extern PInvoke.Kernel32.QueryFullProcessImageName(PInvoke.Kernel32.SafeObjectHandle hProcess, PInvoke.Kernel32.QueryFullProcessImageNameFlags dwFlags, System.Text.StringBuilder lpExeName, ref int lpdwSize) -> bool
13731373
static extern PInvoke.Kernel32.QueryFullProcessImageName(PInvoke.Kernel32.SafeObjectHandle hProcess, PInvoke.Kernel32.QueryFullProcessImageNameFlags dwFlags, char* lpExeName, ref int lpdwSize) -> bool
13741374
static extern PInvoke.Kernel32.ReadConsoleInput(System.IntPtr hConsoleInput, out PInvoke.Kernel32.INPUT_RECORD lpBuffer, int nLength, out int lpNumberOfEventsRead) -> bool
1375-
static extern PInvoke.Kernel32.ReadConsoleOutput(System.IntPtr hConsoleOutput, out PInvoke.Kernel32.CHAR_INFO lpBuffer, PInvoke.COORD dwBufferSize, PInvoke.COORD dwBufferCoord, ref PInvoke.SMALL_RECT lpReadRegion) -> bool
13761375
static extern PInvoke.Kernel32.ReadFile(PInvoke.Kernel32.SafeObjectHandle hFile, void* lpBuffer, int nNumberOfBytesToRead, int* lpNumberOfBytesRead, PInvoke.Kernel32.OVERLAPPED* lpOverlapped) -> bool
13771376
static extern PInvoke.Kernel32.ResumeThread(PInvoke.Kernel32.SafeObjectHandle hThread) -> int
13781377
static extern PInvoke.Kernel32.ScrollConsoleScreenBuffer(System.IntPtr hConsoleOutput, PInvoke.SMALL_RECT* lpScrollRectangle, PInvoke.SMALL_RECT* lpClipRectangle, PInvoke.COORD dwDestinationOrigin, PInvoke.Kernel32.CHAR_INFO* lpFill) -> bool

src/Kernel32/PublicAPI.Unshipped.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ static PInvoke.Kernel32.QueryFullProcessImageName(PInvoke.Kernel32.SafeObjectHan
263263
static PInvoke.Kernel32.ReadConsole(System.IntPtr hConsoleInput, System.IntPtr lpBuffer, int nNumberOfCharsToRead, out int lpNumberOfCharsRead, System.IntPtr pInputControl) -> bool
264264
static PInvoke.Kernel32.ReadConsole(System.IntPtr hConsoleInput, System.Span<char> lpBuffer, out int lpNumberOfCharsRead, PInvoke.Kernel32.CONSOLE_READCONSOLE_CONTROL? pInputControl) -> bool
265265
static PInvoke.Kernel32.ReadConsole(System.IntPtr hConsoleInput, char[] lpBuffer, int nNumberOfCharsToRead, out int lpNumberOfCharsRead, PInvoke.Kernel32.CONSOLE_READCONSOLE_CONTROL? pInputControl) -> bool
266+
static PInvoke.Kernel32.ReadConsoleOutput(System.IntPtr hConsoleOutput, PInvoke.Kernel32.CHAR_INFO[] lpBuffer, PInvoke.COORD dwBufferSize, PInvoke.COORD dwBufferCoord, ref PInvoke.SMALL_RECT lpReadRegion) -> bool
267+
static PInvoke.Kernel32.ReadConsoleOutput(System.IntPtr hConsoleOutput, System.IntPtr lpBuffer, PInvoke.COORD dwBufferSize, PInvoke.COORD dwBufferCoord, ref PInvoke.SMALL_RECT lpReadRegion) -> bool
268+
static PInvoke.Kernel32.ReadConsoleOutput(System.IntPtr hConsoleOutput, System.Span<PInvoke.Kernel32.CHAR_INFO> lpBuffer, PInvoke.COORD dwBufferSize, PInvoke.COORD dwBufferCoord, ref PInvoke.SMALL_RECT lpReadRegion) -> bool
266269
static PInvoke.Kernel32.ReadFile(PInvoke.Kernel32.SafeObjectHandle hFile, void* lpBuffer, int nNumberOfBytesToRead, int* lpNumberOfBytesRead, System.Threading.NativeOverlapped* lpOverlapped) -> bool
267270
static PInvoke.Kernel32.ReadProcessMemory(PInvoke.Kernel32.SafeObjectHandle hProcess, System.IntPtr lpBaseAddress, System.IntPtr lpBuffer, System.UIntPtr nSize, out System.UIntPtr lpNumberOfBytesRead) -> bool
268271
static PInvoke.Kernel32.SetFilePointer(PInvoke.Kernel32.SafeObjectHandle hFile, int lDistanceToMove, System.IntPtr lpDistanceToMoveHigh, System.IO.SeekOrigin dwMoveMethod) -> int
@@ -288,6 +291,7 @@ static extern PInvoke.Kernel32.GetProcessIdOfThread(PInvoke.Kernel32.SafeObjectH
288291
static extern PInvoke.Kernel32.GetProcessInformation(PInvoke.Kernel32.SafeObjectHandle hProcess, PInvoke.Kernel32.PROCESS_INFORMATION_CLASS ProcessInformationClass, void* ProcessInformation, uint ProcessInformationSize) -> bool
289292
static extern PInvoke.Kernel32.GetVolumeInformation(string lpRootPathName, char* lpVolumeNameBuffer, int nVolumeNameSize, out uint lpVolumeSerialNumber, out int lpMaximumComponentLength, out PInvoke.Kernel32.FileSystemFlags lpFileSystemFlags, char* lpFileSystemNameBuffer, int nFileSystemNameSize) -> bool
290293
static extern PInvoke.Kernel32.ReadConsole(System.IntPtr hConsoleInput, char* lpBuffer, int nNumberOfCharsToRead, out int lpNumberOfCharsRead, PInvoke.Kernel32.CONSOLE_READCONSOLE_CONTROL* pInputControl) -> bool
294+
static extern PInvoke.Kernel32.ReadConsoleOutput(System.IntPtr hConsoleOutput, PInvoke.Kernel32.CHAR_INFO* lpBuffer, PInvoke.COORD dwBufferSize, PInvoke.COORD dwBufferCoord, ref PInvoke.SMALL_RECT lpReadRegion) -> bool
291295
static extern PInvoke.Kernel32.ReadProcessMemory(PInvoke.Kernel32.SafeObjectHandle hProcess, void* lpBaseAddress, void* lpBuffer, System.UIntPtr nSize, out System.UIntPtr lpNumberOfBytesRead) -> bool
292296
static extern PInvoke.Kernel32.ResizePseudoConsole(PInvoke.Kernel32.SafePseudoConsoleHandle hPC, PInvoke.COORD size) -> PInvoke.HResult
293297
static extern PInvoke.Kernel32.SetFilePointer(PInvoke.Kernel32.SafeObjectHandle hFile, int lDistanceToMove, int* lpDistanceToMoveHigh, System.IO.SeekOrigin dwMoveMethod) -> int

src/Kernel32/storebanned/Kernel32.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2673,7 +2673,12 @@ public static extern unsafe int GetConsoleTitle(
26732673

26742674
[DllImport(nameof(Kernel32), CharSet = CharSet.Unicode, SetLastError = true)]
26752675
[return: MarshalAs(UnmanagedType.Bool)]
2676-
public static extern bool ReadConsoleOutput(IntPtr hConsoleOutput, out CHAR_INFO lpBuffer, COORD dwBufferSize, COORD dwBufferCoord, ref SMALL_RECT lpReadRegion);
2676+
public static extern unsafe bool ReadConsoleOutput(
2677+
IntPtr hConsoleOutput,
2678+
[Friendly(FriendlyFlags.Out | FriendlyFlags.Array)] CHAR_INFO* lpBuffer,
2679+
COORD dwBufferSize,
2680+
COORD dwBufferCoord,
2681+
ref SMALL_RECT lpReadRegion);
26772682

26782683
/// <summary>
26792684
/// Reads character input from the console input buffer and removes it from the buffer.

0 commit comments

Comments
 (0)