Symbian
Symbian OS Library

SYMBIAN OS V9.3

[Index] [Spacer] [Previous] [Next]



How to use a polymorphic interface DLL

The following code can use any implementation of the interface defined by the example class, CMessenger, to issue a simple greeting.

The example simply issues a greeting to the person whose name is passed in the descriptor aName. The name of the DLL, which contains the implementation to be used, is passed in the descriptor aLibraryName.

void UseDllL(const TFileName& aLibraryName,const TDesC& aName)
    {
          // Use RLibrary object to interface to the DLL
    RLibrary library;
          // Dynamically load the DLL
    TUidType uidType(KDynamicLibraryUid,KMessengerUid);
    User::LeaveIfError(library.Load(aLibraryName,uidType));
          // Function at ordinal 1 creates new CMessenger
    TLibraryFunction entry=library.Lookup(1);
          // Call the function to create new CMessenger
    CMessenger* messenger=(CMessenger*) entry();
          // Push pointer to CMessenger onto the cleanup stack
    CleanupStack::PushL(messenger);
          // Second-phase constructor for CMessenger
    messenger->ConstructL(console, aName);
          // Use Cmessenger object to issue greeting
    messenger->ShowMessage();
          // Pop CMessenger object off cleanup stack and destroy
    CleanupStack::PopAndDestroy();
          // Finished with the DLL
    library.Close();
    }


Notes: