Click here to Skip to main content
15,879,535 members
Articles / Desktop Programming / MFC
Article

Console Application Framework

Rate me:
Please Sign up or sign in to vote.
3.83/5 (17 votes)
12 Jul 2005CPOL3 min read 54K   1.4K   31   4
A framework for rapidly creating a console application.

Sample Image

Introduction

Chances are big that anyone in the business of writing software once encounters the situation in which the use of a console application is appropriate. These ‘consoles’ are often used to test the real application code or to quickly set up some kind of test. Most of the time these applications are not long life assigned and that's exactly why you don't want to spend too much time on implementation. In addition one can say that a lot of functionality such as timers or logging utility functions are needed in most console applications.

Wouldn’t it be helpful to have some sort of ‘empty’ console application offering a lot of basic functionality to which you just have to add your own specific code? If not, please stop reading.

The APP002 application framework offers an empty console application mimicking the well-known DOS interface and as such allowing self-defined commands to be entered on the command line. By default, only the ‘quit’, ‘?’ and some example commands are supported.

Framework overview

  1. Console application framework for C and C++ users.
  2. Although the included project file is a Visual Studio .NET file, the source is IDE independent.
  3. You can add as many commands as you like. Each command is allowed multiple parameters.
  4. Ghost commands can be defined (commands not visible to the user).
  5. Command line parameters are allowed to contain blank characters.
  6. Framework based applications can be called from within a script or DOS box.
  7. You can use up- and down arrows on your keyboard to roam the command history.
  8. Basic logging functionality is available.
  9. Timing functionality with micro resolution is available.
  10. Automatic versioning supported by means of a Perl script.

Framework details

The framework contains three main parts: the Engine, the Command Table and the Utilities. The next paragraphs discuss them briefly. Much more detailed information together with some example code is available inside the user's manual that goes with the source code you can download.

1. The Engine

The Engine is the piece of code that takes care of two things: providing the user interface and executing the commands you enter on the command line. There is not much to say about the user interface: there is a default header and a command prompt (see look.h). Both can be changed by the framework user.

The Engine supports two ways of executing commands. First, you can start the console application, enter a command on the command line, and hit Enter. The result is displayed inside the console window. However, you can also call the console application from within a script or a batch file.

2. The Command Table

The Command Table (see commandTable.h) is where you add the new commands you want to enter on the command line. Adding an entry to the table is easy: copy/paste an existing CMD_ENTRY and update its individual fields. Each entry has four fields:

  1. Command name: the name you have to type on the command line in order to execute the command.
  2. Parameters: (TRUE/FALSE) indication whether the command takes parameters or not.
  3. Function address: the reference to the function that will be called to execute the command.
  4. Comment: some explanation which is displayed when the '?' command is executed.
START_COMMAND_TABLE

    CMD_ENTRY("q", FALSE, NULL, "Quit command")
    CMD_ENTRY("?", FALSE, NULL, "Help me please")
    CMD_ENTRY("cls", FALSE, clsCmd, "Clear screen")

    // PUT HERE YOUR OWN COMMAND ENTRIES
    // ALWAYS LEAVE FIRST TWO COMMANDS IN PLACE !!

END_COMMAND_TABLE

The function inside the third field is implemented by the framework user. You can use the commands.h and the commands.cpp files to accomplish this.

3. The Utilities

While implementing your own commands, you will often find yourself implementing the same functionality over and over gain. Therefore, the framework provides a set of common utility functions. Currently there are three main groups: timing functions, logging functions and parsing functions. The use of timing and logging functions speak for themselves. The parsing functions are very useful when it comes to analyzing the command parameters you enter on the command line. More information is provided inside the user's manual.

History

  • 8 July 2005, Version 2.0.0, Initial CodeProject release.

License

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


Written By
Software Developer
Belgium Belgium
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Generalbug, sort of Pin
Roger6515-Jul-05 6:47
Roger6515-Jul-05 6:47 
GeneralSolved 'File not found plus others' problem Pin
Dominique Bijnens12-Jul-05 4:24
Dominique Bijnens12-Jul-05 4:24 
GeneralFile not found, plus others. Pin
WREY11-Jul-05 9:39
WREY11-Jul-05 9:39 
GeneralRe: File not found, plus others. Pin
Dominique Bijnens11-Jul-05 21:09
Dominique Bijnens11-Jul-05 21:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.