Writing a DLL (used in Symbian OS)

原创 2004年12月28日 19:02:00

A DLL (Dynamic Link Library) is a piece of code (a library) that is linked to a program at runtime rather than during the build process. The code inside a DLL can be shared by several clients at the same time without being duplicated in the mobile memory.

Static Interface vs Polymorphic Interface

Symbian OS supports two types of DLLs :
-  Static Interface DLL
-  Polymorphic Interface DLL

A static interface DLL is automatically loaded in the mobile RAM memory when a program that use it is started (except if it is in ROM where it is executed in place). It is also automatically unloaded when nobody needs it anymore. The static interface DLL provides a unique set of function within the system (i.e. two DLLs with the same exported function could not coexist in the system). Static interface DLLs have .dll file extension and are commonly used to implements application engines (i.e. UI independent code) in Symbian OS.

A polymorphic interface DLL is loaded explicitly by calling RLibrary::Load() and shall be unloaded using RLibrary::Close(). Several polymorphic DLLs can expose the same interface to their clients. So this kind of DLLs is generally used by a framework to provide plug-ins facility. Polymorphic Interface DLLs can have several different file extensions in Symbian OS. The most known one being .app (applications), .ldd (logical device drivers, .tsy and .csy (telephony and communication server modules),...

We will only focus on static interface DLLs which is the most common type of DLLs you (and I!) have to write. We will use the generic DLL term in the rest of the article.

A Static Interface DLL

From a client point of view, a DLL is made of three files:
-  a header file, which as .h file extension and which is #included by the client and needed at compilation time.
-  a import library file (.lib file extension) which the client links againts. This file contains the interface provided by the DLL.
-  the DLL itself (.dll file extension) which contain the implementation of all functions of the DLL and an export table so that the link can be completed at execution time.

From the provider point a view, the DLL can be seen as a complete Symbian project. It shall have:
-  its own MMP file (listed in a bld.inf file)
-  a header file that specifies the interface
-  source code file(s) that contain the implementation.

The header file

A DLL header file is very similar to other classes header files. The important thing to remember is to use the IMPORT_C macro in the declarations of all functions to be exported:

class CMyEngine : public CBase
   // These functions are visible by the
   // clients of the DLL and needs to have
   // the IMPORT_C tag
   IMPORT_C static CMyEngine* NewL();
   IMPORT_C static CMyEngine* NewLC();

   IMPORT_C void MyPublicMethod();
   IMPORT_C void AnotherPublicMethod();
   // These functions are not visible by the
   // clients of the DLL and then do not need
   // the IMPORT_C tag
   void ConstructL();
   void SomePrivateMethod();

The implementation file

Writing a DLL has not many impact on code in itself. But there are two important points to respect:
-  an implementation for the E32Dll() function shall be provided (see code below).
-  another specific macro, EXPORT_C, should be added in front of each exported function implementation. :

// This function is mandatory for all DLLs
EXPORT_C TInt E32Dll(TDllReason)
        return KErrNone;

// This function is exported: The EXPORT_C tag shall be used.
EXPORT_C void MyPublicMethod()

// This one is not: The EXPORT_C tag shall not be used.
void SomePrivateMethod()
  // Do Something

The MMP file

The MMP file for the DLL should:
-  define the project’s target type as dll
-  use the appropriate UID2 value (0x1000008d)

During development phasesn, you should also tell the build environment that DLL interface is not finalised by using the EXPORTUNFROZEN primitive:

TARGET        MyEngine.dll
UID           0x1000008d <myUID3>

Freezing the DLL interface

Once you have finished your development, and before releasing versions of your DLL, you should freeze the interface, so as to ensure the backward compatibility of future releases of a library.

To do this, remove the exportunfrozen keyword from your MMP file and build the project in the normal way: a warning will be generated to the effect that the frozen .def file does not yet exist. Once the project has been built you can freeze by using:

abld freeze

Note that all ARM platforms share a common .def file, but that WINS/WINSCW has a different .def file.

Once the project is frozen, regenerate the makefiles so that the import library will be created directly from the frozen .def file.

Writing Your Own Toy OS [writed by Krishnakumar R. , Raghu and Chitkala ]

Writing Your Own Toy OS (Part I)By Krishnakumar R. This article is a hands-on tutorial for building ...
  • liumangxiong
  • liumangxiong
  • 2006年05月07日 18:51
  • 2059

最简洁搭建Symbian os C++移动开发环境

Symbian支持的语言很多,WEB,Flash,python,java ,P.I.P.S,Symbian C++综合而言,C++开发出来的程序功能最强,性能最好,最接近底层,很灵活。如果你选择J2M...
  • holymoonshine
  • holymoonshine
  • 2010年01月23日 16:59
  • 386

Symbian OS 源码获得方式(本站原创)

 --由www.j2megame.com原创。在www.Symbian.org网上逛了下,发现只有1个链接 http://tiny.symbian.org/open 指向开源下载,但是该页面不知为何原...
  • dymx101
  • dymx101
  • 2010年03月17日 14:57
  • 504

Symbian OS应用开发-SMS的故事(二)

摘要:上节我们了解了Symbian OS中对SMS的主要操作,比如新建、修改以及删除等等,这篇文章我们主要认识一下有关SMS的发送。发送SMS也许我们大多数人都操作过,简单说来就是编辑一段文本,然后选...
  • welcome_ck
  • welcome_ck
  • 2005年01月28日 17:31
  • 5338

symbian dll常见问题

今天本来想把我以前碰到的cs问题写上的,但是看到诺基亚论坛中有人在问dll相关的问题,所以今天就先说说我对symbian dll的理解吧,若有不对之处,欢迎拍砖!symbian中的dll有两种,静态d...
  • syh718185190
  • syh718185190
  • 2010年12月15日 17:39
  • 337

Symbian OS 源码下载方式

本文由 www.J2meGame.com 撰写,转载请说明。Symbian OS 源码下载方式,导航:近日Symbian OS开源,肯定有很多移动开发爱好者去下载Symbian系统代码。但是笔者发现S...
  • wag2765
  • wag2765
  • 2016年01月25日 16:41
  • 592

The hesitation of writing a OS!

很久以前就打算写一个操作系统,虽然这个想法在windows 和 linux称霸的世界看起来很可笑,而且在我们这些非计算机专业的人看来很疯狂。记得让我有这种冲动的只是一个小小的引导扇区(不知道为什么让我...
  • xiangmumufu
  • xiangmumufu
  • 2010年02月25日 18:23
  • 46

Whitesides' Group: Writing a Paper(译)

原文地址:Whitesides’ Group: Writing a Paper译文:论文写作1、一篇科学的论文是什么样的?论文是一种关于假设、数据和结论的有组织的描述,旨在指导读者。论文是研究的核心部...
  • dingding_12345
  • dingding_12345
  • 2015年09月16日 20:34
  • 1855


需求一台电脑,相当快的处理器(大于1.5GHz),512M甚至更大的内存,最少有2G大小可用空间的硬盘存储,操作系统是Windows 2000,XP 或者Vista。开发软件来编译程序,编写程序。即I...
  • mmchsusan
  • mmchsusan
  • 2007年07月24日 23:20
  • 599


1.内核版本不支持 “*** This OS is not supported:" 'uname -a';
  • my_computer
  • my_computer
  • 2014年07月17日 13:11
  • 1916
您举报文章:Writing a DLL (used in Symbian OS)