examples/Base/DLLs/UsingDLLs/UsingDLLs.cpp

00001 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
00002 // All rights reserved.
00003 // This component and the accompanying materials are made available
00004 // under the terms of "Eclipse Public License v1.0"
00005 // which accompanies this distribution, and is available
00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00007 //
00008 // Initial Contributors:
00009 // Nokia Corporation - initial contribution.
00010 //
00011 // Contributors:
00012 //
00013 // Description:
00014 // A program which uses dynamically linked DLLs.
00015 //
00016 
00017 // standard example header
00018 #include "CommonFramework.h"
00019 // f32 header needed for loading dlls.
00020 #include <f32file.h>
00021 
00022 #include "UsingDLLs.h"
00023 
00024 _LIT(KTxtHarry,"Harry");
00025 _LIT(KTxtSally,"Sally");
00026 _LIT(KTxtDr1,"PolymorphicDLL1.DLL");
00027 _LIT(KTxtDr2,"PolymorphicDLL2.DLL");
00028 
00029 _LIT(KTxt1,"dynamically linked DLL example \n\n");
00030 _LIT(KTxt2,"checking UID\n");
00031 _LIT(KTxt3,"DLL has incorrect UID... \n");
00032 
00033 void UseDllL(const TFileName& aDllName, const TDesC& aName);
00034 
00035 LOCAL_C void doExampleL()
00036     {
00037         // open file server session.
00038         RFs fs;
00039         User::LeaveIfError(fs.Connect());
00040         console->Printf(KTxt1);
00041         // use each DLL in turn
00042         TFileName  dll;
00043         dll = KTxtDr1;
00044         UseDllL(dll, KTxtHarry);
00045         dll = KTxtDr2;
00046         UseDllL(dll, KTxtSally);
00047         // close the file server session.
00048         fs.Close();
00049         }
00050 
00051 // how to use a DLL
00052 
00053 void UseDllL(const TFileName& aLibraryName, const TDesC& aName)
00054         {
00055                 // Use RLibrary object to interface to the DLL
00056         RLibrary library;
00057                 // Dynamically load DLL
00058         User::LeaveIfError(library.Load(aLibraryName));
00059                 // Check second UID is as expected; leave if not
00060         console->Printf(KTxt2);
00061         
00062         if (library.Type()[1] != KMessengerUid)
00063                 {
00064                 console->Printf(KTxt3);
00065                 User::Leave(KErrGeneral);
00066                 }
00067                 // Function at ordinal 1 creates  new CMessenger
00068         TLibraryFunction entry=library.Lookup(1);
00069                 // Call the function to create new CMessenger
00070         CMessenger* messenger=(CMessenger*) entry();
00071                 // Push pointer to CMessenger onto the cleanup stack
00072         CleanupStack::PushL(messenger);
00073                 // Second-phase constructor for CMessenger
00074         messenger->ConstructL(console, aName);
00075                 // Use CMessenger object to issue greeting
00076         messenger->ShowMessage();
00077                 // Pop CMessenger object off cleanup stack and destroy
00078         CleanupStack::PopAndDestroy();
00079                 // Finished with the DLL
00080         library.Close();
00081         }

Generated by  doxygen 1.6.2