Last active
April 13, 2022 18:31
-
-
Save matzefriedrich/e49ec7220f76563e9e4f6cdd161e839e to your computer and use it in GitHub Desktop.
Write to stdout from VB6 console app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Option Explicit | |
| Private Declare Function AttachConsole Lib "Kernel32" ( _ | |
| ByVal dwProcessId As Long) As Long | |
| Private Declare Function FreeConsole Lib "Kernel32" () As Long | |
| Private Declare Function GetStdHandle Lib "Kernel32" ( _ | |
| ByVal nStdHandle As Long) As Long | |
| Private Declare Function WriteFile Lib "Kernel32" ( _ | |
| ByVal hFile As Long, _ | |
| ByVal lpBuffer As String, _ | |
| ByVal nNumberOfBytesToWrite As Long, _ | |
| ByRef lpNumberOfBytesWritten As Long, _ | |
| ByVal lpOverlapped As Any) As Long | |
| Private Declare Sub ExitProcess Lib "Kernel32" ( _ | |
| ByVal uExitCode As Long) | |
| Private Const ATTACH_PARENT_PROCESS As Long = -1 | |
| Private Const STD_OUTPUT_HANDLE As Long = -11& | |
| Sub Main() | |
| Dim handle As Long | |
| AttachConsole (ATTACH_PARENT_PROCESS) | |
| handle = GetStdHandle(STD_OUTPUT_HANDLE) | |
| Dim s As String | |
| Dim numberOfBytesWritten As Long | |
| s = "Hello World." | |
| WriteFile handle, s, Len(s), numberOfBytesWritten, ByVal 0& | |
| FreeConsole | |
| ExitProcess 0 | |
| End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment