Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

Tagged as

Go to top

Attaching a Console to a WinForms application

, 25 Jan 2012
Rate this:
Please Sign up or sign in to vote.
VB version:Friend Declare Function AllocConsole Lib "kernel32.dll" () As BooleanFriend Declare Function FreeConsole Lib "kernel32.dll" () As BooleanSub main() Dim MainForm As New frmMain If Command = "" Then MsgBox1 = AddressOf MyMsgBox1 ' messagebox delegate sub call...
VB version:
Friend Declare Function AllocConsole Lib "kernel32.dll" () As Boolean
Friend Declare Function FreeConsole Lib "kernel32.dll" () As Boolean
 
Sub main()
    Dim MainForm As New frmMain
    If Command = "" Then
        MsgBox1 = AddressOf MyMsgBox1 ' messagebox delegate sub call a messagebox
        Application.Run(MainForm)
    Else
        AllocConsole()
        HadMessage = False
        Try
            MsgBox1 = AddressOf MyLog1 ' messagebox delegate sub log a message
            MainForm.Show()
            Application.DoEvents()
            MainForm.InjectParameters(Command)
            MainForm.llGo_LinkClicked(Nothing, Nothing)
            IO.File.AppendAllText("Out.txt", MainForm.tbResults.Text)
            MainForm.Close()
        Catch ex As Exception
            MyLog1(ex.ToString)
        End Try
        If HadMessage Then
            Console.Beep()
            Console.WriteLine("SLEEPING 20 SEC WHILE YOU READ THE MESSAGE")
            System.Threading.Thread.Sleep(20000)
        End If
        FreeConsole()
    End If
End Sub

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

fastal
Web Developer
United States United States
Alan Budelier is a happy Catholic working for IT in Major Fraternal Life Insurnance Company in Rock Island, IL, who, like Christ, would someday like to compile and run without any need for exception handling.

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 25 Jan 2012
Article Copyright 2012 by fastal
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid