# Example template

The following is an example template to create a simple Symbian OS `EXE` project:

`<?xml version="1.0" encoding="ISO-8859-1"?>
<template type="ProjTempl" version="1.0" supplier="Symbian" revision="1.0" author="Bala Torati"
id="EXE" label="Simple EXE" description="A skeletal Symbian OS EXE project. Creates a folder for sources and another for include."
help="help.html">
<property-group id="basics" label="Basic Settings" description="Basic properties of a project" type="PAGES-ONLY" help="help.html">
<property id="uid2"
label="UID 2"
description="UID 2"
default="0x00000000"
type="input"
pattern="0x[0-9a-fA-F]{8}"
hidden="false"
mandatory="true"
persist="true"/>
<property id="uid3"
label="UID 3"
description="UID 3"
default="0x00000000"
type="input"
pattern="0x[0-9a-fA-F]{8}"
hidden="false"
mandatory="false"
persist="true"/>
<property id="vid"
label="Vendor ID"
description="Vendor ID"
default="0x00000000"
type="input"
pattern="0x[0-9a-fA-F]{8}"
hidden="false"
mandatory="true"
persist="true"/>
<property id="author"
label="Author"
description="Name of the author"
type="input"
pattern=".*"
default=""
hidden="false"
persist="true"/>
<property id="copyright"
label="Copyright notice"
description="Your copyright notice"
type="input"
pattern=".*"
default="Your copyright notice"
hidden="false"
persist="true"/>
<property id="targetType"
label="Target Type"
description="Select the target type"
type="select"
default="app"
hidden="false"
mandatory="true"
persist="true">
<item label="APP" value="app"/>
<item label="LIB" value="lib"/>
<item label="DLL" value="dll"/>
<item label="EXE" value="exe"/>
<item label="EXEDLL" value="exedll"/>
</property>
</property-group>
<property-group id="directories" label="Project Directories" description="Generated files will be copied to the specified directories under the project root directory" type="PAGES-ONLY" help="help.html">
<property id="incDir"
label="Include"
description="Directory for C++ header files"
type="input"
default="inc"
pattern="[a-zA-Z0-9]+"
mandatory="true"
persist="true"/>
<property id="sourceDir"
label="Source"
description="Directory for C++ source files"
type="input"
default="src"
pattern="[a-zA-Z0-9]+"
mandatory="true"
persist="true"/>
</property-group>
<process type="org.eclipse.cdt.managedbuilder.core.NewManagedProject">
<simple name="name" value="$(projectName)"/>
<simple name="targetType" value="$(targetType)"/>
<simple name="uid2" value="$(uid2)"/>
<simple name="uid3" value="$(uid3)"/>
<simple name="vid" value="$(vid)"/>
</process>
<process type="org.eclipse.cdt.core.CreateSourceFolder">
<simple name="projectName" value="$(projectName)"/>
<simple name="path" value="$(sourceDir)"/>
</process>
<process type="org.eclipse.cdt.managedbuilder.core.CreateIncludeFolder">
<simple name="projectName" value="$(projectName)"/>
<simple name="path" value="$(incDir)"/>
</process>
<process type="org.eclipse.cdt.core.AddFiles">
<simple name="projectName" value="$(projectName)"/>
<complex-array name="files">
<element>
<simple name="source" value="inc/Basename.h"/>
<simple name="target" value="$(incDir)/$(baseName).h"/>
<simple name="replaceable" value="true"/>
</element>
<element>
<simple name="source" value="src/Basename.cpp"/>
<simple name="target" value="$(sourceDir)/$(baseName).cpp"/>
<simple name="replaceable" value="true"/>
</element>
</complex-array>
</process>
<process type="org.eclipse.cdt.managedbuilder.core.AppendToMBSStringListOptionValues">
<simple name="projectName" value= "$(projectName)"/>
<complex-array name="resourcePaths">
<element>
<simple name="id" value=".*linker\.libraries\.libraries.*" />
<simple-array name="values">
<element value="euser.lib" />
</simple-array>
<simple name="path" value="" />
</element>
</complex-array>
</process>
</template>`

The above given template copies the following source (`.cpp`) and header (`.h`) files in the `src` and `inc` folders respectively. These files uses a set of macros to get the values specified by the developer for file name, author name, copyright etc.

`/*
============================================================================
Name : $(baseName).cpp
Author : $(author)
Version :
Copyright : $(copyright)
Description : Exe source file
============================================================================
*/
// Include Files
#include "$(baseName).h"
#include <e32base.h>
#include <e32std.h>
#include <e32cons.h> // Console
// Constants
_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(const TDesC& aArgs)
{
//
// add your program code here, example code below
//
console->Write(_L("Hello, world!\n"));
console->Printf(_L("Command line args: \"%S\"\n"), &aArgs);
}
LOCAL_C void DoStartL()
{
// Create active scheduler (to run active objects)
CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
CleanupStack::PushL(scheduler);
CActiveScheduler::Install(scheduler);
// Call main function with command line
TBuf<256> cmdLine;
RProcess().CommandLine(cmdLine);
MainL(cmdLine);
// 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;
}`

`/*
============================================================================
Name : $(baseName).h
Author : $(author)
Version :
Copyright : $(copyright)
Description : Exe header file
============================================================================
*/
#ifndef __$(baseName)_H__
#define __$(baseName)_H__
// Include Files
#include <e32base.h>
// Function Prototypes
GLDEF_C TInt E32Main();
#endif // __$(baseName)_H__`

When the developer chooses the above template in the New Project wizard, the following wizard pages are generated:

Basic Settings

Project Directories

The input fields listed in the above given pages are as per the definitions given in the template. In the template, the `property-group` element with the ID "basics" defines all the input fields required for the `Basic Settings` page. While the `property-group` element with the ID "directories" defines all the input fields required for the `Project Directories` page.

The template will create a Symbian OS `EXE` project in the Eclipse workspace with all the required resources.

The following `C/C++ Projects` view shows the resources created by the New Project wizard for the above given template:

Explorer view