DLLs

From CENS Urban Sensing

The following is a recipe for creating polymorphic DLLs for Symbian s60 3rd edition using Carbide.c++

Setting up the project

  1. create a new "Basic Dynamically Linked Library" project
  2. make sure uid2 is 0x1000008d
  3. edit the pkg file adding the line [0x101F7961], 0, 0, 0, {"Series60ProductID"}
  4. edit the pkg's install path to be \sys\bin\YOURDLLNAME.dll
  5. make sure the dlls capabilities are a superset of any application that will be calling it.

Creating the DLL

The easiest (and Symbian recommended) way to create polymorphic dlls is to define an pure virtual interface class that the polymorphic dlls will implement.

For example:

   class MMathFunc {
   public:
       virtual TReal Apply(TReal) = 0;
   };

Then have your dlls use the implementation's .h file implement the interface. The dll should have a single exported static function that returns and instance of the interface's class.

   #include "MathFunc.h" 
    
   class TSquare : public MMathFunc {
   public:
       IMPORT_C  static MMathFunc* NewL();
       virtual TReal Apply(TReal);
   };
   #include "Square.h"
    
   EXPORT_C MMathFunc* TSquare::NewL() {
       return new TSquare();
   }
    
   TReal TSquare::Apply(TReal aReal) {
       return aReal * aReal;
   }

Using the dll

To use the dll you include the interface's .h file and load the dll using RLibrary:

   RLibrary library;
   User::LeaveIfError(library.Load(_L("Square")));     
   TLibraryFunction NewL=library.Lookup(1);
   MMathFunc* mf=(MMathFunc*) NewL();
   
   // be sure to close the library when you are done loading dlls
   library.Close();
   
   //use the object created by the dll            
   TReal r = 2.0;
   r = mf->Apply(r);
   delete mf;


--Redfood 11:53, 31 January 2007 (PST)