示例#1
0
 public static void EnsureConsoleOpen()
 {
     if (Environment.OSVersion.Platform.IsWindows())
     {
         if (NativeWindowsConsole.StdOutFileHandle == IntPtr.Zero)
         {
             if (NativeWindows.AllocConsole() == false)
             {
                 throw new InvalidOperationException(String.Format("Failed to create console (lasterror={0})", NativeWindows.GetLastError()));
             }
             NativeWindowsConsole.StdOutFileHandle = NativeWindows.GetStdHandle(NativeWindows.STD_OUTPUT_HANDLE);
             if (NativeWindowsConsole.StdOutFileHandle == NativeWindows.INVALID_HANDLE_VALUE)
             {
                 throw new InvalidOperationException(String.Format("GetStdHandle(STD_OUTPUT_HANDLE) failed (error={0})", NativeWindows.GetLastError()));
             }
             if (NativeWindowsConsole.StdOutFileHandle == IntPtr.Zero)
             {
                 throw new InvalidOperationException(String.Format("GetStdHandle(STD_OUTPUT_HANDLE) returned 0 but this doesn't make sense because we just called AllocConsole? (lasterror={0})", NativeWindows.GetLastError()));
             }
             NativeWindowsConsole.StdOutCodePage = NativeWindows.GetConsoleCP();
             StdOut = BufferedWindowsConsoleSink.Create(64, true);
         }
     }
     else
     {
         throw new PlatformNotSupportedException(String.Format("No console implemented for platform: {0}",
                                                               Environment.OSVersion.Platform));
     }
 }
示例#2
0
 static NativeWindowsConsole()
 {
     StdOutFileHandle = NativeWindows.GetStdHandle(NativeWindows.STD_OUTPUT_HANDLE);
     if (StdOutFileHandle == NativeWindows.INVALID_HANDLE_VALUE)
     {
         throw new InvalidOperationException(String.Format("GetStdHandle(STD_OUTPUT_HANDLE) failed (error={0})", NativeWindows.GetLastError()));
     }
     if (StdOutFileHandle != IntPtr.Zero)
     {
         NativeWindowsConsole.StdOutCodePage = NativeWindows.GetConsoleCP();
     }
 }