Click here to Skip to main content
15,880,854 members
Articles / Mobile Apps

Writing Polymorphic DLL on Symbian platform

Rate me:
Please Sign up or sign in to vote.
2.58/5 (9 votes)
12 Aug 2003CPOL2 min read 80.3K   20   9
This article demonstrates how to write polymorphic DLL on Symbian.

Prerequisites

  • Knowledge of C++ and COM.
  • Knowledge of Symbian Programming idioms

Introduction

Writing a polymorphic DLL involves the following steps:

  1. Design and write interfaces.
  2. Implement the interface.

Lets explore these in more detail:

Design and write interface consisting of method declarations.

An interface is essentially an abstract class. An example would clarify it:

class ICalculator {

public:
virtual TInt Sum(TInt, TInt) = 0;

};

Above snippet declares a class ICalculator with one method Sum which would take 2 TInt parameters and would return a TInt value. Take a look at the name given to the class. This is done to follow a convention i.e. an interface name should start with an 'I'. Now if one wishes to implement interface ICalculator, he/she has to implement the method Sum.

COM programmers would be wondering that how it can be an interface without a UUID or something like that. Yes! in Symbian too, an interface requires a UUID. While writing an interface this is how UUID is given to it.

static const TUid KCalculator_DLLUID = {0x100039CE};
static const TUid KCalculator_DLLUID_Ver1 = {0x0352D96B};
class ICalculator {

public:
virtual TInt Sum(TInt, TInt) = 0;

};

Your polymorphic interface is ready. You have to write it in a .h file so that it can be implemented in other .cpp files.

Implement the interface.

Writing a polymorphic DLL is half done when interface declaration is done. Now one would require to implement it. Implementing an interface is as simple as inheriting abstract classes. You have to inherit from an interface and implement pure virtual methods of the interface.

Again an example would help us understand this:

class CImpCalculator: public ICalculator {

public:

EXPORT_C CImpCalculator* NewImpClass();

//function would be exposed through Function table
TInt Sum(TInt num1,TInt num2);
};


GLDEF_C TInt E32Dll(TDllReason) {

return KErrNone;
}

EXPORT_C CImpCalculator* CImpCalculator::NewImpClass() {

return new (ELeave) CImpCalculator;
}

TInt CImpCalculator::Sum(TInt num1,TInt num2) {

return num1 + num2;

}

The example above does something more than just implementing the interface. The class CImpCalculator has a method of its own, NewImpClass. This method has a qualifier EXPORT_C. Clearly this is the method which is exposed from the implementation class. In Symbian it is not required to export or expose all the methods from an interface. Only method which needs to be exposed is which returns the object of the interface (or should I say the implementor class?). Rest of the methods can be accessed from function table. The NewImpClass method returns a pointer to the newly created object.

E32Dll method has to be written in every Polymorohic DLL as it is required by the Symbian run time. You would get linking errors in case you forget to write it. This method is responsible to allocate thread local store for the DLL instance.

Now you are ready to compile and build your own DLL. Build it and start using it.

Lastly these DLLs are called polymorphic because one can write many implementations of the same interface. Further all the Symbian GUI applications are Polymorphic DLLs. Check the GUI SDK examples, you will find E32Dll method implemented.

That's all you would require to write a DLL on Symbian!! Note that I have tested the code on NOKIA Series 60 emulator.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
India India
Amit Limaye has 5+ years experience in Symbian and Window CE programming for the Pocket PC and SmartPhone 2002 platform using eVC++ and ATL COM. Currently Working in the area of Motirola Power PC and QNX platform.

Comments and Discussions

 
GeneralMore Information. Pin
Prakash Nadar22-May-05 16:32
Prakash Nadar22-May-05 16:32 
General.prt for a new protocol Pin
Member 113345927-Apr-05 0:37
Member 113345927-Apr-05 0:37 
GeneralDma Test on Symbian 8.1b Platform Pin
apphia10-Feb-05 18:21
apphia10-Feb-05 18:21 
GeneralCrash Pin
joelparker17-May-04 11:21
joelparker17-May-04 11:21 
GeneralSymbian C++ for 7650 Pin
Rahul Kumar29-May-03 2:42
Rahul Kumar29-May-03 2:42 
GeneralRe: Symbian java for 6600 Pin
Anonymous16-Jan-05 23:25
Anonymous16-Jan-05 23:25 
Generalzip utility for the Symbian Pin
keen1-Jan-03 1:11
keen1-Jan-03 1:11 
hi
i m new to CE Programming, i want to make WinZip like utility for the Symbian and Pocket PC. i had worked with Vicual C and ATL/COM. Please help me from where i have to start.
thanx
keen
GeneralRe: zip utility for the Symbian Pin
Amit Arvind Limaye2-Jan-03 17:39
Amit Arvind Limaye2-Jan-03 17:39 
GeneralRe: zip utility for the Symbian Pin
keen3-Jan-03 0:46
keen3-Jan-03 0:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.