mirror of
https://github.com/microsoft/terminal.git
synced 2026-05-09 21:00:19 -04:00
moved readconsoleinputstream to samples folder; added readme; updated root readme.
This commit is contained in:
31
samples/ReadConsoleInputStream/NativeMethods.cs
Normal file
31
samples/ReadConsoleInputStream/NativeMethods.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Samples.Terminal
|
||||
{
|
||||
internal static class NativeMethods
|
||||
{
|
||||
private static int MakeHRFromErrorCode(int errorCode)
|
||||
{
|
||||
// Don't convert it if it is already an HRESULT
|
||||
if ((0xFFFF0000 & errorCode) != 0)
|
||||
{
|
||||
Debug.Assert(false, "errorCode is already HRESULT");
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
return unchecked(((int)0x80070000) | errorCode);
|
||||
}
|
||||
|
||||
internal static Exception GetExceptionForWin32Error(int errorCode)
|
||||
{
|
||||
return Marshal.GetExceptionForHR(MakeHRFromErrorCode(errorCode));
|
||||
}
|
||||
|
||||
internal static Exception GetExceptionForLastWin32Error()
|
||||
{
|
||||
return GetExceptionForWin32Error(Marshal.GetLastWin32Error());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user