TGP

TGP

  • NA
  • 14
  • 0

Can't start a console in a winforms app

Jun 5 2010 12:02 AM
Hi everyone. I'm trying to start a console from a winforms app, and right on the last line, it says An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll. Additional information: The handle is invalid. Here's the code:

 Imports Microsoft.DirectX

Public Class ConsoleWindow
Declare Function AllocConsole Lib "kernel32" () As Boolean
Declare Function FreeConsole Lib "kernel32" () As Integer
Dim readline As String
Dim stats As New ArrayList
Dim t As New Threading.Thread(AddressOf OpenWindow)

Sub Get3DInfo()
stats.Add("Texture Memory: ")
stats.Add(mdx9a.device.AvailableTextureMemory)
stats.Add("Number of lights: ")
stats.Add(mdx9a.device.Lights.Count + 1)
stats.Add("Light details :")
Dim i As Integer
For i = 0 To mdx9a.device.Lights.Count
stats.Add(vbNewLine & "Light #" & i + 1 & ":" & vbNewLine)
stats.Add(mdx9a.device.Lights(i).ToString)
Next
End Sub

Sub AddLine(ByVal line As String, Optional ByVal fgcolor As ConsoleColor = ConsoleColor.White)
Dim tempcol As ConsoleColor = Console.ForegroundColor
Console.ForegroundColor = fgcolor
Console.Write(line)
Console.ForegroundColor = tempcol
End Sub

Sub OpenWindow()
If AllocConsole() = True Then
Console.WindowLeft = 0

So how do I create a valid handle?

Answers (1)