Writing a DLL (Used in Symbian OS)

xiaoxiao2021-03-06  41

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 InterfaceSymbian 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 (ie 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 (ie 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 articles.

A Static Interface DLLFROM 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 compiration time.a

Import Library File

.lib file extension) Which The Client Links Againts. This File Contains The interface provides provided by the dll.

THE

DLL itself

.dll file extension of all functions of the dll and an export table so what the link can becompleted 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 importation.

The Header Filea DLL Header File Is Very Similar To Other Classes Header Files. The Important Thing to Remember Is To Use The THE

Import_c Macro in The Declarations of All Functions to Be Exported:

Class CMYENGINE: Public CBASE

{

PUBLIC:

// Thase 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 ();

...

Private:

// Thase Functions Are Not visible by the

// clients of the dll and then do not need

// the import_c tag

CMYENGINE ();

Void constructL ();

Void someprivateMethod ();

}

The Implementation FileWriting A DLL HAS NOT MANY IMPACT ON CODE INTSELF. But There Area Two Important Points To Respect:

An Implementation for Thae

E32DLL () Function Shall Be provides (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 shavert.

Void someprivateMethod ()

{

// do something

}

The MMP Filethe Mmp File for the dll shop:

Define The Project's Target Type As

DLL

Use the appropriate uid2 value (0x1000008d)

During development phasesn, you shouth, tell the build environment That DLL Interface is not finalied by useing the exportunfrozenprimities:

Target myngine.dll

Targettype DLL

UID 0x1000008D

...

Exportunfrozen

Freezing the DLL interfaceOnce 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.

转载请注明原文地址:https://www.9cbs.com/read-75556.html

New Post(0)