Option ExplicitPrivate Const STD_OUTPUT_HANDLE = -11& Private Const INVALID_HANDLE_VALUE = -1& Private Declare Function AllocConsole Lib "kernel32" () As Long Private Declare Function FreeConsole Lib "kernel32" () As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Long) As Long Private Declare Function WriteConsole Lib "kernel32" Alias "WriteConsoleA" (ByVal hConsoleOutput As Long, lpBuffer As Any, ByVal nNumberOfCharsToWrite As Long, lpNumberOfCharsWritten As Long, lpReserved As Any) As Long Private hConsoleOut As LongPrivate Sub Command1_Click() Dim cWritten As Long Const sInput As String = "#########################"
If AllocConsole() Then hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE) If hConsoleOut = INVALID_HANDLE_VALUE Then MsgBox "Unable to get STDOUT" Exit Sub End If WriteConsole hConsoleOut, ByVal sInput, Len(sInput), cWritten, ByVal 0& Else MsgBox "Couldn't allocate console" End If End SubPrivate Sub Form_Unload(Cancel As Integer) 'Delete console CloseHandle hConsoleOut FreeConsole End Sub
Private Const INVALID_HANDLE_VALUE = -1&
Private Declare Function AllocConsole Lib "kernel32" () As Long
Private Declare Function FreeConsole Lib "kernel32" () As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Long) As Long
Private Declare Function WriteConsole Lib "kernel32" Alias "WriteConsoleA" (ByVal hConsoleOutput As Long, lpBuffer As Any, ByVal nNumberOfCharsToWrite As Long, lpNumberOfCharsWritten As Long, lpReserved As Any) As Long
Private hConsoleOut As LongPrivate Sub Command1_Click()
Dim cWritten As Long
Const sInput As String = "#########################"
If AllocConsole() Then
hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE)
If hConsoleOut = INVALID_HANDLE_VALUE Then
MsgBox "Unable to get STDOUT"
Exit Sub
End If
WriteConsole hConsoleOut, ByVal sInput, Len(sInput), cWritten, ByVal 0&
Else
MsgBox "Couldn't allocate console"
End If
End SubPrivate Sub Form_Unload(Cancel As Integer)
'Delete console
CloseHandle hConsoleOut
FreeConsole
End Sub