Polymorphic DLL in Symbian
We have learn basic of Symbian static DLL and now we try to make our polymorphic DLL by this tutorial. Main difference between static and polymorphic DLL is that code from static DLL are merged to the client during link time. On the other hand Polymorphic DLL are loaded during run time. If a static DLL is not present in the system then your client can't link against it and if a polymorphic DLL is not present in the system then the functionality can't be used during program execution.
Let's create a polymorphic DLL step by step, For polymorphic DLL we can compile/link the client first as compared to static linking DLL we can't compile/build the client before building the DLL. The reason is simple, we need to have the LIB file for linker to insert in our client code during link time. But for polymorphic DLL we use the DLL during run time. When we call methods from DLL then it must be present in the system (in \EPOC32\RELEASE\gcce\udeb folder)
- Create a folder like the following picture:
- Create a Symbian application folder structure in your derive (for this simple DLL group, inc and src folder will be enough)
- Create a file name UsingPolymorphicDLL.h and put it in the inc folder:
- Contents of the file
- Create a file name PolymorphicDLL1.h and put it in the inc folder:
- Contents of the file
- Create a file name PolymorphicDLL1.cpp and put it in the src folder:
- Contents of the file
- Create a file name PolymorphicDLL1.mmp and put it in the group folder:
- Contents of the file
- Create a file named BLD.inf and put it in the group folder:
- Contents of the file

We may not need to have exact folder structure like this. But this is just convention. From the folder structure we can see that there will be two DLL (PolymorphicDLL1 and PolymorphicDLL2) and a client (PolymorphicDLLClient), this client will use these DLLs polymorphically.
Let's start creating our Polymorphic DLL.
// UsingDLLs.h
// standard example header
#include <e32cons.h>
#ifndef __UsingDLLs_H
#define __UsingDLLs_H
// The UID for Messenger DLLs.
// The client imposes this on DLLs which are required
// to satisfy the protocol
const TInt KMessengerUidValue=0x10004262;
const TUid KMessengerUid={KMessengerUidValue};
class CMessenger : public CBase
{
public:
/*
This pure virtual function will be implemented by the Polymorphic DLL
*/
virtual void ConstructL(CConsoleBase* aConsole, const TDesC& aName)=0;// note =0
/*
This pure virtual function will be implemented by the Polymorphic DLL
*/
virtual void ShowMessage()=0;// note =0
protected:
CConsoleBase* iConsole;
HBufC* iName;
};
#endif
// PolymorphicDLL1.h
//
#ifndef __PolymorphicDLL1_H
#define __PolymorphicDLL1_H
// get definition of base class
#include "UsingPolymorphicDLL.h"
class CFrenchMessenger : public CMessenger
{
public:
/*
Note that ConstructL(...) was declared as pure virtual in the previous file.
We are redeclaring it same signature and return value, so this method can be called polymorphically.
*/
virtual void ConstructL(CConsoleBase* aConsole, const TDesC& aName);
// destructor
virtual ~CFrenchMessenger();
// useful functions
virtual void ShowMessage();
};
#endif
// PolymorphicDLL1.cpp
//
// Copyright (C) Symbian Software Ltd 2000-2005. All rights reserved.
/* This program creates a polymorphic interface DLL which to which an application can dynamically link to.
*/
#include "PolymorphicDLL1.h"
#include <e32def.h>
#include <e32uid.h>
// Function to construct a CMessenger object. Note that this function
// is exported at ordinal 1 and is not a member of any class.
EXPORT_C CMessenger* NewMessenger()
{
return new (ELeave) CFrenchMessenger;
}
// Class member functions
// second-phase constructor
void CFrenchMessenger::ConstructL(CConsoleBase* aConsole, const TDesC& aName)
{
iConsole=aConsole; // remember console
iName=aName.AllocL(); // copy given string into own descriptor
}
// destructor
CFrenchMessenger::~CFrenchMessenger()
{
delete iName;
}
// show message
void CFrenchMessenger::ShowMessage()
{
_LIT(KFormat1,"Bonjour, Je m'appelle %S \n");
iConsole->Printf(KNullDesC);
iConsole->Printf(KFormat1, iName);
}
// PolymorphicDLL1.mmp
//
// Copyright (C) Symbian Software Ltd 2000-2005. All rights reserved.
// using relative paths for source and user include directories
TARGET PolymorphicDLL1.dll //Note for static DLL it should be .lib
TARGETTYPE dll
UID 0x10004262 0xE8000016
CAPABILITY NONE
VENDORID 0x70000001
SOURCEPATH ..\src
SOURCE PolymorphicDLL1.cpp
USERINCLUDE ..\inc
SYSTEMINCLUDE \Epoc32\include
LIBRARY euser.lib
// BLD.INF
// Component description file
//
// Copyright (c) 2000 Symbian Ltd. All rights reserved.
PRJ_MMPFILES
PolymorphicDLL1.mmp
Now if you export the bld.inf file to your carbide tools then it will create a dll that can be used by client
