dcsimg
June 23, 2018
Hot Topics:

Writing Console-Mode Applications in Visual Basic

  • November 19, 2002
  • By Scott Lloyd
  • Send Email »
  • More Articles »

Visual Basic, as was mentioned earlier, has no built-in support for console work of any kind. This means that all of our interfacing with the console will be done through calls to the Win32 API. Our application has no attachment to the console box. It's not a resource of any kind, it's a process that we request the operating system to allocate for us. This is done by a call to the API function AllocConsole, whose prototype is as follows:

Private Declare Function _
AllocConsole Lib "kernel32" () As Long

This will create a console window in which we can print and receive input. This console window - this is important to remember - is a process controlled by the operating system. Think of all operations that we perform on it as "requests" (and these requests can be denied). Since it is a process, it must always be destroyed when we are done with it, or before the application terminates. We destroy the console process with the FreeConsole function.

Private Declare Function _
FreeConsole Lib "kernel32" () As Long

With this done, one can already write a program that brings up a console box and closes it:

Private Declare Function _
AllocConsole Lib "kernel32" () As Long

Private Declare Function _
FreeConsole Lib "kernel32" () As Long

Private Sub Main()
AllocConsole
FreeConsole
End Sub




Page 2 of 7



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.

Sitemap

×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date