Console is a very simple application that only creates a text console and displays Hello World ! .
As you may guess, the code to do that is quite simple : void ConsoleMainL()
{
console->Printf(_L("Hello World!\n"));
}
There is probably not much to say about this. Just note the use of _L( ) macro that shall be used to create build independant strings (that can use 8 or 16 bits text depending on the use of Unicode or not).
Actually, most of the work is done in the console framework located in console.h. This is a strange place to put some C++ code, and it has some drawbacks if you are a serious developer. However, it allows a very simple use of the framework by just including it. Here is the code to create the console :
CConsoleBase *console;
console=Console::NewL(_L("Console"),TSize(KConsFullScreen,KConsFullScreen));
TInt Err;
TRAP(Err,ConsoleMainL());
if(Err)
console->Printf(_L("TRAP: Error(%d)\n"),Err);
console->Printf(_L("\n[Press any key]"));
console->Getch();
delete console;
CConsoleBase and Console are not described in most Symbian documentation. A quick look at e32cons.h (in epoc/include directory) will give you clues about the available method for CConsoleBase :
Printf()
Getch
SetPos(X) and SetPos(X,Y)
WhereX() and WhereY()
Other functions are virtual and can only be used through CEikConsole class (which is not as straightforward to use due to the use of Eikon).
Console only adds to CConsoleBase the NewL() constructor and the ability to use the trap harness (the TRAP() primitive) : this construction is used to catch and report any potential errors that may occurs in the code called from ConsoleMainL.
This exemple can be reused for developping very small text application that will let you play and try some other Symbian concept without the burden of a GUI (and it should also work no matter of your graphical environment). But it is not a complete code, some important concept like the cleanup stack are missing and should be added for real development.
|