Results 1 to 5 of 5

Thread: Add-in for compiling EXEs in Console mode in VB6

Threaded View

  1. #5
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Add-in for compiling EXEs in Console mode in VB6

    Indeed, you can just use a template for this. Just unzip the attachment and move the two files into:

    C:\Program Files\Microsoft Visual Studio\VB98\Template\Projects

    ... or the equivalent location on your machine.

    Warning: Check the folder first, you don't want to just replace any existing files with the same names!

    Then you get the option of "Console EXE" when you open a new project.

    Of course you might want to customize, adding more to the Module1.bas included. For example allocating/deallocating a console for IDE runs:

    Code:
    Option Explicit
    '
    'Reference to Microsoft Scripting Runtime.
    '
    
    Public SIn As Scripting.TextStream
    Public SOut As Scripting.TextStream
    
    '--- Only required for testing in IDE or Windows Subsystem ===
    Private Declare Function AllocConsole Lib "kernel32" () As Long
    Private Declare Function GetConsoleTitle Lib "kernel32" _
        Alias "GetConsoleTitleA" ( _
        ByVal lpConsoleTitle As String, _
        ByVal nSize As Long) As Long
    Private Declare Function FreeConsole Lib "kernel32" () As Long
    
    Private Allocated As Boolean
    
    Private Sub Setup()
        Dim Title As String
    
        Title = Space$(260)
        If GetConsoleTitle(Title, 260) = 0 Then
            AllocConsole
            Allocated = True
        End If
    End Sub
    
    Private Sub TearDown()
        If Allocated Then
            SOut.Write "Press enter to continue..."
            SIn.ReadLine
            FreeConsole
        End If
    End Sub
    '--- End testing ---------------------------------------------
    
    Private Sub Main()
        Setup 'Omit for Console Subsystem.
    
        With New Scripting.FileSystemObject
            Set SIn = .GetStandardStream(StdIn)
            Set SOut = .GetStandardStream(StdOut)
        End With
    
        SOut.WriteLine "Any output you want"
        SOut.WriteLine "Goes here"
    
        TearDown 'Omit for Console Subsystem.
    End Sub
    You could use an "IDE run test" to decide whether or not to invoke Setup/TearDown, though the GetConsoleTitle() call is usually good enough.
    Attached Files Attached Files
    Last edited by dilettante; Feb 22nd, 2016 at 07:05 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width