97 for (
int i = 0; i < 10 && leadByteRanges[i] != 0; i += 2)
99 leadByteRanges[i] = cPINFOEXW.LeadByte[i];
100 leadByteRanges[i + 1] = cPINFOEXW.LeadByte[i + 1];
108 internal static extern bool Beep(
int frequency,
int duration);
110 [DllImport(
"kernel32.dll", BestFitMapping =
true,
CharSet =
CharSet.Unicode, EntryPoint =
"FormatMessageW", ExactSpelling =
true,
SetLastError =
true)]
111 private unsafe
static extern int FormatMessage(
int dwFlags,
IntPtr lpSource, uint dwMessageId,
int dwLanguageId,
void* lpBuffer,
int nSize,
IntPtr arguments);
126 fixed (
char* lpBuffer = span)
150 return $
"Unknown error (0x{errorCode:x})";
156 while (num > 0 &&
buffer[num - 1] <=
' ')
160 return buffer.Slice(0, num).ToString();
178 [DllImport(
"kernel32.dll")]
196 [DllImport(
"kernel32.dll")]
205 [DllImport(
"kernel32.dll")]
206 [SuppressGCTransition]
209 [DllImport(
"kernel32.dll")]
210 internal unsafe
static extern int MultiByteToWideChar(uint CodePage, uint dwFlags,
byte* lpMultiByteStr,
int cbMultiByte,
char* lpWideCharStr,
int cchWideChar);
219 internal unsafe
static extern bool ReadConsole(
IntPtr hConsoleInput,
byte* lpBuffer,
int nNumberOfCharsToRead, out
int lpNumberOfCharsRead,
IntPtr pInputControl);
248 [DllImport(
"kernel32.dll")]
249 internal unsafe
static extern int WideCharToMultiByte(uint CodePage, uint dwFlags,
char* lpWideCharStr,
int cchWideChar,
byte* lpMultiByteStr,
int cbMultiByte,
IntPtr lpDefaultChar,
IntPtr lpUsedDefaultChar);
255 internal unsafe
static extern bool WriteConsole(
IntPtr hConsoleOutput,
byte* lpBuffer,
int nNumberOfCharsToWrite, out
int lpNumberOfCharsWritten,
IntPtr lpReservedMustBeNull);
269 [DllImport(
"user32.dll")]
static uint GetConsoleCP()
static bool SetConsoleOutputCP(int codePage)
static uint GetConsoleOutputCP()
static unsafe int ReadFile(IntPtr handle, byte *bytes, int numBytesToRead, out int numBytesRead, IntPtr mustBeZero)
static bool SetConsoleMode(IntPtr handle, int mode)
static unsafe bool ReadConsole(IntPtr hConsoleInput, byte *lpBuffer, int nNumberOfCharsToRead, out int lpNumberOfCharsRead, IntPtr pInputControl)
static IntPtr GetStdHandle(int nStdHandle)
static bool FillConsoleOutputAttribute(IntPtr hConsoleOutput, short wColorAttribute, int numCells, COORD startCoord, out int pNumBytesWritten)
static unsafe bool ReadConsoleOutput(IntPtr hConsoleOutput, CHAR_INFO *pBuffer, COORD bufferSize, COORD bufferCoord, ref SMALL_RECT readRegion)
static unsafe int WriteFile(IntPtr handle, byte *bytes, int numBytesToWrite, out int numBytesWritten, IntPtr mustBeZero)
static unsafe string GetMessage(int errorCode, IntPtr moduleHandle)
static bool SetConsoleTitle(string title)
static bool PeekConsoleInput(IntPtr hConsoleInput, out InputRecord buffer, int numInputRecords_UseOne, out int numEventsRead)
static void SetLastError(int errorCode)
static bool SetConsoleCP(int codePage)
static bool SetConsoleScreenBufferSize(IntPtr hConsoleOutput, COORD size)
static bool GetConsoleCursorInfo(IntPtr hConsoleOutput, out CONSOLE_CURSOR_INFO cci)
static unsafe bool WriteConsole(IntPtr hConsoleOutput, byte *lpBuffer, int nNumberOfCharsToWrite, out int lpNumberOfCharsWritten, IntPtr lpReservedMustBeNull)
static unsafe int WideCharToMultiByte(uint CodePage, uint dwFlags, char *lpWideCharStr, int cchWideChar, byte *lpMultiByteStr, int cbMultiByte, IntPtr lpDefaultChar, IntPtr lpUsedDefaultChar)
static unsafe int MultiByteToWideChar(uint CodePage, uint dwFlags, byte *lpMultiByteStr, int cbMultiByte, char *lpWideCharStr, int cchWideChar)
static bool IsGetConsoleModeCallSuccessful(IntPtr handle)
static bool SetConsoleCursorInfo(IntPtr hConsoleOutput, ref CONSOLE_CURSOR_INFO cci)
static bool GetConsoleMode(IntPtr handle, out int mode)
static string GetMessage(int errorCode)
static bool FillConsoleOutputCharacter(IntPtr hConsoleOutput, char character, int nLength, COORD dwWriteCoord, out int pNumCharsWritten)
static int SetConsoleTextAttribute(IntPtr hConsoleOutput, short wAttributes)
static bool Beep(int frequency, int duration)
static unsafe int GetLeadByteRanges(int codePage, byte[] leadByteRanges)
static COORD GetLargestConsoleWindowSize(IntPtr hConsoleOutput)
static unsafe int FormatMessage(int dwFlags, IntPtr lpSource, uint dwMessageId, int dwLanguageId, void *lpBuffer, int nSize, IntPtr arguments)
static unsafe BOOL GetCPInfoExW(uint CodePage, uint dwFlags, CPINFOEXW *lpCPInfoEx)
static bool SetConsoleCursorPosition(IntPtr hConsoleOutput, COORD cursorPosition)
static bool GetConsoleScreenBufferInfo(IntPtr hConsoleOutput, out CONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
static unsafe bool SetConsoleWindowInfo(IntPtr hConsoleOutput, bool absolute, SMALL_RECT *consoleWindow)
static unsafe bool WriteConsoleOutput(IntPtr hConsoleOutput, CHAR_INFO *buffer, COORD bufferSize, COORD bufferCoord, ref SMALL_RECT writeRegion)
static bool ReadConsoleInput(IntPtr hConsoleInput, out InputRecord buffer, int numInputRecords_UseOne, out int numEventsRead)
static uint GetFileType(IntPtr hFile)
static unsafe uint GetConsoleTitleW(char *title, uint nSize)
static string GetAndTrimString(Span< char > buffer)
static short GetKeyState(int virtualKeyCode)
static void FreeHGlobal(IntPtr hglobal)
static int GetLastWin32Error()
COORD dwMaximumWindowSize
unsafe fixed char CodePageName[260]
unsafe fixed byte LeadByte[12]
unsafe fixed byte DefaultChar[2]
static readonly IntPtr Zero
Span< T > Slice(int start)