HelloWorld united. Single code base for S60 2nd and 3rd editions

The 3rd edition of Nokia's S60 platform is all cool and new, but there are a lot of older devices you would still like to support.

The introduction of platform security in the 3rd edition changed the internals of the system a lot. However, from the point of view of the regular application programmer, changes are not that big and are mostly related to the configuration-like issues. We have to rewrite the MMP file, declare couple of things differently, use different type of icons, etc. - a lot of small things that you just have to carefully do once. As the end result of these small differences you'll have two projects with a bit different structure, a bit different set of files and minor changes in the application code.

Preprocessor magic

Fortunately, there is a known tool that can produce several different files basing on a single source and on a given configuration. We can use a bit of preprocessor magic to compile different application versions from the same source code and project files.

Unfortunately there is no specific define about the S60 version. However, there is the EKA2 define that is enabled for the new Symbian kernel architecture. Theoretically speaking there is a possibility, that Nokia could release S60 2nd edition with the EKA2 architecture, but in practice whenever EKA2 is defined, you are working on the S60 3rd edition.

Practical summary

You can use this HelloWorld united project for quick starting the development of a single application for two platforms: S60 2nd and 3rd edition. No need to have to separate projects anymore. Differences between the application versions are minimized and controlled by the preprocessor defines.

Screenshots:

From the MMP file:

// The same app UID is used in a lot of places
// We specify it in a single place in HelloWorldUids.hrh
#include "..\inc\HelloWorldUids.hrh"

// Strictly speaking EKA2 is not about the S60 3rd edition.
// Therefore we'll use own defines so, that you could seamlessly replace
// EKA2 with a better define if you manage to find one
#ifdef EKA2
// preprocessor macro for processing the MMP file, not for the cpp compilation
#define THIRD_EDITION_MMP
// preprocessor macro for the cpp compilation
MACRO THIRD_EDITION
#endif

#ifdef THIRD_EDITION_MMP
TARGET HelloWorld.exe
TARGETTYPE exe
UID 0x0 KHelloWorldUid

SECUREID KHelloWorldUid
EPOCSTACKSIZE 0x5000
#else
TARGET HelloWorld.app
TARGETTYPE app
UID 0x100039CE KHelloWorldUid
TARGETPATH \system\apps\HelloWorld

#endif
...

From the HelloWorldapplication.cpp:

#ifdef THIRD_EDITION
// -----------------------------------------------------------------------------
// CHelloWorldApplication::CreateDocumentL()
// Creates CApaDocument object
// -----------------------------------------------------------------------------
//
CApaDocument* CHelloWorldApplication::CreateDocumentL()
{
// Create an HelloWorld document, and return a pointer to it
return (static_cast
( CHelloWorldDocument::NewL( *this ) ) );
}

#else

// ---------------------------------------------------------
// CHelloWorldApp::CreateDocumentL()
// Creates CHelloWorldDocument object
// ---------------------------------------------------------
//
CApaDocument* CHelloWorldApplication::CreateDocumentL()
{
return CHelloWorldDocument::NewL( *this );
}
...





AttachmentSize
HelloWorld_2nd_and_3rd.zip20.7 KB