I have a VB6 application which can work in UI as well as in CMD mode. Now when I am running it in CMD mode I need to write few line into the console after completion of the program before quitting the application. The rest of the application is working perfectly fine but I am not able to write something into the console
I tried the following but it does not work
Option Explicit Declare Function AllocConsole Lib "kernel32" () As Long Declare Function FreeConsole Lib "kernel32" () As Long Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Long) As Long 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 Declare Function SetConsoleCtrlHandler Lib "kernel32" (ByVal HandlerRoutine As Long, ByVal Add As Long) As Long Public Const STD_OUTPUT_HANDLE = -11& Public hndl As Long Sub Main() Dim strWord As String Dim cWritten As Long Dim successStat As Boolean On Error GoTo Hndlr strWord = "Hello!" & vbCrLf hndl = GetStdHandle(STD_OUTPUT_HANDLE) successStat = WriteConsole(hndl, ByVal strWord, Len(strWord), cWritten, ByVal 0&) Hndlr: Debug.Print Err.Description Debug.Print Err.Number Resume Next End Sub
Kindly help. I need to write the output in the same console window from where the application is invoked, not in a new window that the application would open.