Click here to Skip to main content
Click here to Skip to main content

Writing Polymorphic DLL on Symbian platform

, 12 Aug 2003
Rate this:
Please Sign up or sign in to vote.
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)

About the Author

Amit Arvind Limaye
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. PinmemberMr.Prakash22-May-05 16:32 

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 13 Aug 2003
Article Copyright 2002 by Amit Arvind Limaye
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid