A simple text console
5 Feb 2003 - 00:00

Console is a very simple application that only creates a text console and displays « Hello World ! » .
console.png

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.
AttachmentSize
console.zip10.17 KB
Tutorial posted February 5th, 2003 by eric

Submitted by eric (not verified) on Fri, 2003-02-21 09:57.

To add support of a CleanupStack, you can replace E32Main() (in console.h) by the following code:

TInt E32Main()
{
//
// Mark Heap (to check memory leakage)
// and create a Cleanup Stack
//
__UHEAP_MARK;
CTrapCleanup* cleanup=CTrapCleanup::New();

//
// Create a full screen console
//
TRAPD(error,createConsoleL());

//
// Delete the CleanUp Stack
// "Unmark" the heap
//
delete cleanup;
__UHEAP_MARKEND;
return(0);
}

And then add the createConsole()function just above:
LOCAL_C void createConsoleL()
{
console=Console::NewL(_L("Console"),TSize(KConsFullScreen,KConsFullScreen));
CleanupStack::PushL(console);

//
// Do my console program,
// and trap any error that may occurs in it
//
TInt Err;
TRAP(Err,ConsoleMainL());
if(Err)
         console->Printf(_L("TRAP: Error(%d)\n"),Err);

//
// Wait the user to press any key before closing
//
console->Printf(_L("[Press any key]\n"));
console->Getch();
CleanupStack::PopAndDestroy();
}


Submitted by herogee (not verified) on Fri, 2003-03-14 12:39.

How can you trace the flow of execution of a Symbian program?

Submitted by matt (not verified) on Wed, 2003-05-14 20:55.

run the program in the emulator under visual studio debugger and stop the application at the desired loaction using a breakpoint, then view the the stack trace window or simply step through the program you will however not be able to step into any dlls etc

Submitted by laxmi kant (not verified) on Wed, 2003-05-21 12:12.

i think by using the run time debugger to trace the flow of program

Submitted by Elmer Andes (not verified) on Fri, 2003-07-18 03:27.

Hi,

Would you say that this Hello World application (console-based and thus, utilizes the full screen) is a good foundation for a game that has control over the whole screen? I'd like to hear your opinion because I saw a sample application in the Symbian site that uses the same Hello World application as basis for a game.

Why am I asking this? :) I'm trying to find out how to make apps (and games) that are full screen. Any thoughts?


Submitted by Anonymous on Thu, 2003-08-14 13:28.

Hi,

This program is OK, but How I can load it in a real targed after build the armi code?

thanks, L.A


Submitted by Eric (not verified) on Thu, 2003-08-14 18:22.

You can create a SIS file just like with standard APP file and install it on the phone the usual way.

Or you can send directly the EXE through irda/bluetooth.

In both case,you will need a file explorer application (ex: ) , go to the inbox directory (E:\system\mail on my 3650) and find your EXE in one of the subdirectories.

You can also read for more details.


Submitted by Ruchiak (not verified) on Tue, 2003-09-30 05:24.

How do i introduce a scroll bar in the console so as to enable display of more information. I tried using the class CConsoleScreen but it is giving me breakpoint error.Can u help me out woth this.

Submitted by Jer (not verified) on Tue, 2003-12-02 03:52.

What does "LOCAL_D CConsoleBase* gConsole;" does and definition?

Submitted by ozzoo (not verified) on Thu, 2004-03-04 04:54.

Hi

I am doing some test with console . actually it is httpexampleclient in UIQ example. I want to excute on P800.

plz tell me how I excute it on p800.


Submitted by ozzoo (not verified) on Thu, 2004-03-04 11:13.

thanx all

I found out the way.

I just change the ".exe" extantion of file to APP..

thanx


Submitted by HangaS (not verified) on Tue, 2004-03-16 14:18.

This console is very nice, Its a great help for debugging.

You can run the application normaly and send all the debug to the console window.

Before I used AlertWins but they are a bit anoying and sometime they change the events and focus of your controls.

This is evem cleaner and more practical then log file debuging.


Submitted by vikas (not verified) on Sat, 2004-10-02 15:25.

hello will u pls tell me where i get p800 emulator on net. thanks in advance. vikas...

Submitted by Rahul (not verified) on Thu, 2004-06-17 09:37.

Can anyone tell me why (LS) appears after the TITLE "Console" when the exe is run in the emulator?

Submitted by Anonymous on Tue, 2004-12-14 09:06.

may be the application name is console


copyright 2003-2009 NewLC SARL