examples/SysLibs/ResourceFiles/MultiRead2/MultiRead2.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 // This example shows how to use multiple resource files with cross-referenced
00015 // resources.  It depends on the resource file created for the MultiRead1 project.
00016 // It introduces a second resource file, MultiRead2, which contains an LLINK
00017 // to a resource defined in the MultiRead1 project. The important point to note is
00018 // that the effect of introducing this second resource file is minimal: just
00019 // another #include file; and the logic in doExampleL() would be identical whether
00020 // the LLINK pointed to another resource in the same file or a different file.
00021 //
00022 
00023 
00024 
00025 #include "CommonToResourceFilesEx.h"
00026 #include <multiread2.rsg> // user resources
00027 #include "MultiRead.h"    // definition of multi-resource-reader class
00028 
00029 // Do the example
00030 void doExampleL()
00031         {
00032         _LIT(KFormat,"%S\n");
00033 
00034         // allocate multi-reader
00035         CMultipleResourceFileReader* multiReader =
00036                         CMultipleResourceFileReader::NewLC();
00037 
00038         // open resource file on the emulator(__WINS__  is defined for the Windows emulator)
00039         // (leave if error)
00040         #if defined(__WINS__)
00041         // add MultiRead1 version 23
00042         _LIT(KZSystemDataBasigbRsc,"Z:\\Resource\\apps\\MultiRead1.rsc");
00043         multiReader->AddResourceFileL(KZSystemDataBasigbRsc,23);
00044         // add MultiRead2 version 17
00045         _LIT(KZSystemDataBasiguRsc,"Z:\\Resource\\apps\\MultiRead2.rsc");
00046         multiReader->AddResourceFileL(KZSystemDataBasiguRsc,17);
00047         #endif
00048 
00049         // open a resource file on the target phone
00050         // ( __EPOC32__ is defined for all target hardware platforms regardless of processor type/hardware architecture)
00051         #if defined(__EPOC32__)
00052         // add MultiRead1 version 23
00053         _LIT(KCSystemDataBasigbRsc,"Z:\\Resource\\apps\\MultiRead1.rsc");
00054         multiReader->AddResourceFileL(KCSystemDataBasigbRsc,23);
00055         
00056         // add MultiRead2 version 17
00057         _LIT(KCSystemDataBasiguRsc,"Z:\\Resource\\apps\\MultiRead2.rsc");
00058         multiReader->AddResourceFileL(KCSystemDataBasiguRsc,17);
00059         #endif
00060         
00061         // read resource that returns a reference to another resource
00062         HBufC8* refBuffer=multiReader->AllocReadLC(R_USER_HELLOREF);
00063         TResourceReader theReader;
00064         theReader.SetBuffer(refBuffer);
00065         TInt referencedId=theReader.ReadInt32(); // treat resource as integer
00066         CleanupStack::PopAndDestroy(); // refBuffer
00067         // read the other resource
00068         HBufC8* dataBuffer=multiReader->AllocReadLC(referencedId);
00069         TResourceReader reader;
00070         reader.SetBuffer(dataBuffer);
00071         TPtrC textdata = reader.ReadTPtrC();
00072 
00073         // write string to test console
00074         console->Printf(KFormat, &textdata);
00075         // clean up data buffer
00076         CleanupStack::PopAndDestroy(); // finished with dataBuffer
00077         // cleanup multi-reader
00078         CleanupStack::PopAndDestroy(); // multi-reader
00079         }

Generated by  doxygen 1.6.2