Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadConsoleW does not have SetLastError=true #753

Closed
alexrp opened this issue Nov 21, 2021 · 1 comment
Closed

ReadConsoleW does not have SetLastError=true #753

alexrp opened this issue Nov 21, 2021 · 1 comment
Assignees
Labels
broken api An API is inaccurate and could lead to runtime failure

Comments

@alexrp
Copy link

alexrp commented Nov 21, 2021

Actual behavior

[DllImport("Kernel32", ExactSpelling = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
internal static extern unsafe win32.Foundation.BOOL ReadConsoleW(win32.Foundation.HANDLE hConsoleInput, void* lpBuffer, uint nNumberOfCharsToRead, uint* lpNumberOfCharsRead, [Optional] win32.System.Console.CONSOLE_READCONSOLE_CONTROL* pInputControl);

Expected behavior

[DllImport("Kernel32", ExactSpelling = true, SetLastError = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
internal static extern unsafe win32.Foundation.BOOL ReadConsoleW(win32.Foundation.HANDLE hConsoleInput, void* lpBuffer, uint nNumberOfCharsToRead, uint* lpNumberOfCharsRead, [Optional] win32.System.Console.CONSOLE_READCONSOLE_CONTROL* pInputControl);

Repro steps

  1. NativeMethods.txt content:
ReadConsoleW
  1. NativeMethods.json content (if present):
{
  "$schema": "https://raw.githubusercontent.com/microsoft/CsWin32/main/src/Microsoft.Windows.CsWin32/settings.schema.json",
  "wideCharOnly": false,
  "emitSingleFile": true
}

Context

  • CsWin32 version: 0.1.588-beta
  • Win32Metadata version (if explicitly set by project): 15.0.2-preview
  • Target Framework: net6.0
  • LangVersion (if explicitly set by project): preview
@alexrp
Copy link
Author

alexrp commented Nov 21, 2021

It's probably not helpful to open a new issue for every related API, so I'll note here that the following functions have the same issue:

  • FlushConsoleInputBuffer
  • GetConsoleMode
  • GetConsoleScreenBufferInfo
  • SetConsoleMode
  • SetConsoleCP
  • SetConsoleOutputCP

It seems like it might be a pervasive issue with console-related APIs.

(I'm working around it by using Marshal.GetLastSystemError for now.)

@AArnott AArnott transferred this issue from microsoft/CsWin32 Nov 22, 2021
@mikebattista mikebattista self-assigned this Nov 29, 2021
@mikebattista mikebattista added the broken api An API is inaccurate and could lead to runtime failure label Nov 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
broken api An API is inaccurate and could lead to runtime failure
Projects
None yet
Development

No branches or pull requests

2 participants