You Are Here:

Community: Wiki

This page was last modified on 13 October 2008, at 19:32.

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 Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fJavaE5fVerifiedE5fE28PortuguE25C3E25AAsE29X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ