Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 10:22, 6 June 2008.

CS001009 - Loading DLL by RLibrary

From Forum Nokia Wiki


ID CS001009 Creation date June 6, 2008
Platform S60 3rd Edition, MR Tested on devices Nokia N95
Category Symbian C++ Subcategory Code Examples


Keywords (APIs, classes, methods, functions): RLibrary

Overview

This code snippet shows how to load a polymorphic DLL dynamically.

A static DLL is automatically loaded in the RAM when a program that uses it is started. It is also automatically unloaded when it is not needed anymore.

A polymorphic DLL is loaded by calling RLibrary::Load() and unloaded using RLibrary::Close(). Several polymorphic DLLs can show the same interface to their clients. This kind of DLLs are generally used by a framework to provide plug-in features.

MMP file

The following capabilities and libraries are required:

CAPABILITY      None
LIBRARY         euser.lib

Polymorphic DLL

  • UID2 must be 0x1000008d in DLL's MMP file.
  • DLL must have equal or greater CAPABILITIES than the loading process. Once loaded, DLL runs at the capability level of the loading process. Therefore, a DLL must have all capabilities required by all its client executables, even if the code within the DLL itself does not require some of these capabilities.
  • Define VIRTUAL INTERFACE class that the polymorphic DLLs will implement
  • DLL should have one EXPORTED static function that returns an instance of the interface's class.

Your DLL header

class MMyDll
    {
    public:
        virtual TInt Data() = 0;
    };
   
class CMyDll : public MMyDll 
    {
    public:
        IMPORT_C  static MMyDll* NewL();
        virtual TInt Data();
    };

DLL source

EXPORT_C MMyDll* CMyDll::NewL()
    {
    return new CMyDll();
    }
 
TInt CMyDll::Data()
    {
    return 1;
    }

Loading DLL dynamically

#include <e32std.h>
 
RLibrary library;
 
// Load dll
User::LeaveIfError(library.Load(_L("CMyDll")));     
 
// Find exported function
TLibraryFunction NewL=library.Lookup(1);
MMyDll* mydll=(MMyDll*) NewL();
   
// Close the library
library.Close();
 
TInt value = mydll->Data();
delete mydll;

Postconditions

The DLL is loaded dynamically.

Related Discussions
Thread Thread Starter Forum Replies Last Post
elf2e32 ....... naimulah General Symbian C++ 4 2006-11-03 16:15
use dll several times lkz633 General Symbian C++ 2 2006-07-10 06:20
System crash while calling insertL() from another thread matlev General Symbian C++ 6 2007-03-01 18:19
S60 3rd capabilities problem? iulian_moldovan General Symbian C++ 8 2007-06-18 14:35
Emulator startup time (udeb) kenandr General Symbian C++ 0 2004-08-30 07:09
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX