GetConsoleWindow

C# Signature:

[DllImport("kernel32.dll")]
static extern IntPtr GetConsoleWindow();

Sample Code:

if(GetConsoleWindow() != IntPtr.Zero)
{
    TextWriterTraceListener ConsoleListener = new TextWriterTraceListener(System.Console.Out);
    Trace.Listeners.Add(ConsoleListener);
}

VB .NET Signature:

<DllImport("kernel32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Function GetConsoleWindow() As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Function ShowWindow(ByVal hwnd As IntPtr, ByVal nCmdShow As ShowWindowCommands) As Boolean
End Function

Sample Code:

Última actualización