×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Regular Contributor
    Join Date
    Jun 2006
    Posts
    177

    Exclamation <newbie> What are these methods doing?

    Hey

    Carbide.C++ 1.2
    Symbian SDK 2nd 2rd.

    I used the wizard in Carbide.C++ to create a console (.exe) symbian application. This is confusing me very much. I've read in the book "S60 Programming", that book contains a example console application (card game, it contais the code). What's confusing me is that Carbide.C++ added some methods which I don't see in the example in the book. E32Main(), DoStartL() isn't in the example in the book. The example in the book is object oriented:
    class CNoob : CBase
    {

    }
    And the code generated from Carbide.C++ don't denotes a class definition...

    I want to create a class inheriting from CBase, can I then just remove E32Main() and DoStartL(), then define a class in newbie.h and implement this class in newbie.cpp ? This is confusing me....

    Here is the newbie.h, newbie.cpp which Carbide.C++ generated for me


    newbie.h
    #ifndef __NEWBIE_H__
    #define __NEWBIE_H__

    #include <e32base.h>

    GLDEF_C TInt E32Main();

    #endif // __NEWBIE_H__


    newbie.cpp
    #include "newbie.h"
    #include <e32base.h>
    #include <e32std.h>
    #include <e32cons.h> // Console

    _LIT(KTextConsoleTitle, "Console");
    _LIT(KTextFailed, " failed, leave code = %d");
    _LIT(KTextPressAnyKey, " [press any key]\n");


    LOCAL_D CConsoleBase* console; // write all messages to this


    LOCAL_C void MainL()
    {
    console->Write(_L("Hello, world!\n"));
    }


    LOCAL_C void DoStartL()
    {
    // Create active scheduler (to run active objects)
    CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
    CleanupStack::PushL(scheduler);
    CActiveScheduler::Install(scheduler);

    MainL();

    // Delete active scheduler
    CleanupStack::PopAndDestroy(scheduler);
    }


    // Global Functions

    GLDEF_C TInt E32Main()
    {
    // Create cleanup stack
    __UHEAP_MARK;
    CTrapCleanup* cleanup = CTrapCleanup::New();

    // Create output console
    TRAPD(createError, console = Console::NewL(KTextConsoleTitle, TSize(KConsFullScreen,KConsFullScreen)));
    if (createError)
    return createError;

    // Run application code inside TRAP harness, wait keypress when terminated
    TRAPD(mainError, DoStartL());
    if (mainError)
    console->Printf(KTextFailed, mainError);
    console->Printf(KTextPressAnyKey);
    console->Getch();

    delete console;
    delete cleanup;
    __UHEAP_MARKEND;
    return KErrNone;
    }

  2. #2
    Super Contributor
    Join Date
    Nov 2005
    Location
    London
    Posts
    584

    Re: <newbie> What are these methods doing?

    Quote Originally Posted by doesitmatter
    can I then just remove E32Main() and DoStartL(), then define a class in newbie.h and implement this class in newbie.cpp ? This is confusing me....
    Don't remove DoStartL() and E32Main(), they contain important code to initialize your cleanup stack and active scheduler (which you'll need if you use active objects or the cleanup stack, or any classes which do so). E32Main() is the entrypoint for the exe - you need it.

    You can implement your class as you say, but instantiate it within DoStartL() or a method called by DoStartL().

  3. #3
    Regular Contributor
    Join Date
    Jun 2006
    Posts
    177

    Re: <newbie> What are these methods doing?

    Okay, but the example from the book S60 programming isn't using E32Main() and DoStartL()... Does what you say also mean that the example in the book should have E32Main() and DoStartL()???

    This is the header file of the example in book, it is this source I've based my newbie project on:
    #ifndef __CARDS_H__
    #define __CARDS_H__

    #include <e32base.h>
    #include "globals.h"

    class CCards : CBase
    {
    public:
    static CCards* NewL(TInt);
    static CCards* NewLC(TInt);
    ~CCards();
    TInt Deal();
    void Shuffle();
    TBuf<KCardNameLength> &CardName(TInt);
    private:
    CCards(TInt);
    void ConstructL();
    TInt* iDeck;
    TInt iNextCard;
    TInt iNumPacks;
    TBuf<KCardNameLength> iCardName;

    };

    #endif // __CARDS_H__
    By the way, The newbie project has no practical value, it is just a simple helloworld project. My goal is just is just that I want to develop my skills in symbian programming

  4. #4
    Super Contributor
    Join Date
    Nov 2005
    Location
    London
    Posts
    584

    Re: <newbie> What are these methods doing?

    The S60 book example probably omitted E32Main() for clarity, and just showed the c class because it's the part that's most relevant to that discussion. I don't have that book in my collection so can't tell for sure, but certainly the full implementation of any console based exe will need an E32Main and will also call a function with a 'L' suffix (e.g DoStartL(), ExampleL() or something similar) within a TRAP from within E32Main. As a beginner, you don't need to know why, but you do certainly need it.

    That book is probably a very helpful thing to have when you're learning. Check out some of the other learning resources too, such as this workbook http://www.forum.nokia.com/info/sw.n..._0_en.pdf.html

    And, of course, feel free to post questions here for help!

  5. #5
    Regular Contributor
    Join Date
    Jun 2006
    Posts
    177

    Re: <newbie> What are these methods doing?

    Thanks. Now I've recreated my newbie project containing E32Main(), DoStartL() and MainL():

    As you see from the code below I still get some errors. I think those errors are generated because my class definition below are not correctly embedded in E32Main(), DoStartL(), MainL(). But I don't know how to go about fix them because I don't know how this class shall be embedded with those methods (E32Main() etc)...

    Though this is just a helloworld example, but what I try to create is a simple console application which can hold a value. Then in another project the GUI will be created and then this newbie project will be imported into that project... From what I've read that is possible. If I'm wrong then please correct me. You can think of this newbie project as a helloworld engine and a later project will create the GUI.. Am I on the right track when developing such projects? I mean I choose Basic console application in the Carbide.C++ editor, maybe there is a better approach for creating such projects as I have in mind?

    And what about the errors below? Any suggestions on what may have caused them are welcome........

    BTW, Thanks for that great article you posted, I really like those tasks there, I'm reading that document

    newbie.cpp
    #include "newbie.h"
    #include <e32base.h>
    #include <e32std.h>
    #include <e32cons.h>

    _LIT(KTextConsoleTitle, "Console");
    _LIT(KTextFailed, " failed, leave code = %d");
    _LIT(KTextPressAnyKey, " [press any key]\n");

    // Global Variables

    LOCAL_D CConsoleBase* console; // write all messages to this


    // Local Functions

    LOCAL_C void MainL()
    {
    //
    // add your program code here, example code below
    //
    console->Write(_L("Hello, world!\n"));
    }

    LOCAL_C void DoStartL()
    {
    // Create active scheduler (to run active objects)
    CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
    CleanupStack::PushL(scheduler);
    CActiveScheduler::Install(scheduler);

    MainL();

    // Delete active scheduler
    CleanupStack::PopAndDestroy(scheduler);
    }

    // Global Functions

    GLDEF_C TInt E32Main()
    {
    // Create cleanup stack
    __UHEAP_MARK;
    CTrapCleanup* cleanup = CTrapCleanup::New();

    // Create output console
    TRAPD(createError, console = Console::NewL(KTextConsoleTitle, TSize(KConsFullScreen,KConsFullScreen)));
    if (createError)
    return createError;

    // Run application code inside TRAP harness, wait keypress when terminated
    TRAPD(mainError, DoStartL());
    if (mainError)
    console->Printf(KTextFailed, mainError);
    console->Printf(KTextPressAnyKey);
    console->Getch();

    delete console;
    delete cleanup;
    __UHEAP_MARKEND;
    return KErrNone;
    }


    CNewbie* CNewbie::NewL();
    {
    CNewbie* self = CNewbie::NewLC();
    CleanupStack::Pop(self);
    return (self);
    }

    CNewbie* CNewbie::NewLC();
    {
    CNewbie* me = new (ELeave) CNewbie();
    CleanupStack::PushL(me);
    me->ConstructL();
    return (me);
    }

    CNewbie::~CNewbie();
    {

    }

    CNewbie::CNewbie();
    {

    }

    void CNewbie::ConstructL()
    {

    }


    newbie.h

    #ifndef __NEWBIE_H__
    #define __NEWBIE_H__

    #include <e32base.h>

    // Function Prototypes

    GLDEF_C TInt E32Main();

    class CNewbie : CBase
    {
    public:
    static CNewbie* NewL();
    static CNewbie* NewLC();
    ~CNewbie();
    private:
    CNewbie();
    void ConstructL();
    };


    #endif // __NEWBIE_H__



    Errors:
    declaration syntax error newbie/src newbie.cpp line 83
    declaration syntax error newbie/src newbie.cpp line 90
    declaration syntax error newbie/src newbie.cpp line 99
    declaration syntax error newbie/src newbie.cpp line 101
    declaration syntax error newbie/src newbie.cpp line 104
    declaration syntax error newbie/src newbie.cpp line 106

  6. #6
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015

    Re: <newbie> What are these methods doing?

    Look at what the difference between these two is

    CNewbie::CNewbie();
    {

    }

    void CNewbie::ConstructL()
    {

    }
    Last edited by hotcheese; 2007-06-19 at 00:15.

  7. #7
    Regular Contributor
    Join Date
    Mar 2007
    Posts
    61

    Thumbs up Re: <newbie> What are these methods doing?

    remove ; symbol for these methods and run once we will check for error then after

    CNewbie* CNewbie::NewL();


    CNewbie* CNewbie::NewLC();

    CNewbie::~CNewbie();

    CNewbie::CNewbie();

Similar Threads

  1. HC evaluation methods for mobile applications
    By arachidyl in forum Symbian
    Replies: 0
    Last Post: 2006-03-21, 16:30
  2. Replies: 3
    Last Post: 2005-08-24, 19:18
  3. Replies: 0
    Last Post: 2005-08-17, 11:03
  4. obfuscating native methods
    By masterjuca in forum Mobile Java General
    Replies: 1
    Last Post: 2004-02-05, 20:41
  5. 7250 i DRM methods & contents protected
    By pituvaca in forum Digital Rights Management & Content Downloading
    Replies: 4
    Last Post: 2003-10-29, 13:46

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •