/// <summary> /// Create a new instance of the ConsoleScreenBuffer class by creating a new /// console screen buffer handle. /// </summary> public ConsoleScreenBuffer() { _handle = WinCon.CreateConsoleScreenBuffer( WinApi.GENERIC_READ | WinApi.GENERIC_WRITE, WinApi.FILE_SHARE_READ | WinApi.FILE_SHARE_WRITE, null, WinCon.CONSOLE_TEXTMODE_BUFFER, IntPtr.Zero); if (_handle.ToInt32() == WinApi.INVALID_HANDLE_VALUE) { throw new IOException("Unable to create screen buffer", Marshal.GetLastWin32Error()); } ownsHandle = true; }