00001 /* 00002 Copyright (c) 2000-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. 00003 00004 Redistribution and use in source and binary forms, with or without 00005 modification, are permitted provided that the following conditions are met: 00006 00007 * Redistributions of source code must retain the above copyright notice, this 00008 list of conditions and the following disclaimer. 00009 * Redistributions in binary form must reproduce the above copyright notice, 00010 this list of conditions and the following disclaimer in the documentation 00011 and/or other materials provided with the distribution. 00012 * Neither the name of Nokia Corporation nor the names of its contributors 00013 may be used to endorse or promote products derived from this software 00014 without specific prior written permission. 00015 00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 00027 Description: 00028 This example shows how to use multiple resource files with cross-referenced 00029 resources. It depends on the resource file created for the MultiRead1 project. 00030 It introduces a second resource file, MultiRead2, which contains an LLINK 00031 to a resource defined in the MultiRead1 project. The important point to note is 00032 that the effect of introducing this second resource file is minimal: just 00033 another #include file; and the logic in doExampleL() would be identical whether 00034 the LLINK pointed to another resource in the same file or a different file. 00035 */ 00036 00037 00038 00039 00040 00041 #include "CommonToResourceFilesEx.h" 00042 #include <multiread2.rsg> // user resources 00043 #include "MultiRead.h" // definition of multi-resource-reader class 00044 00045 // Do the example 00046 void doExampleL() 00047 { 00048 _LIT(KFormat,"%S\n"); 00049 00050 // allocate multi-reader 00051 CMultipleResourceFileReader* multiReader = 00052 CMultipleResourceFileReader::NewLC(); 00053 00054 // open resource file on the emulator(__WINS__ is defined for the Windows emulator) 00055 #if defined(__WINS__) 00056 // add MultiRead1 version 23 00057 _LIT(KZSystemDataBasigbRsc,"Z:\\Resource\\apps\\MultiRead1.rsc"); 00058 multiReader->AddResourceFileL(KZSystemDataBasigbRsc,23); 00059 // add MultiRead2 version 17 00060 _LIT(KZSystemDataBasiguRsc,"Z:\\Resource\\apps\\MultiRead2.rsc"); 00061 multiReader->AddResourceFileL(KZSystemDataBasiguRsc,17); 00062 #else // open a resource file on the target phone 00063 // add MultiRead1 version 23 00064 _LIT(KCSystemDataBasigbRsc,"C:\\Resource\\apps\\MultiRead1.rsc"); 00065 multiReader->AddResourceFileL(KCSystemDataBasigbRsc,23); 00066 // add MultiRead2 version 17 00067 _LIT(KCSystemDataBasiguRsc,"C:\\Resource\\apps\\MultiRead2.rsc"); 00068 multiReader->AddResourceFileL(KCSystemDataBasiguRsc,17); 00069 #endif 00070 00071 // read resource that returns a reference to another resource 00072 HBufC8* refBuffer=multiReader->AllocReadLC(R_USER_HELLOREF); 00073 TResourceReader theReader; 00074 theReader.SetBuffer(refBuffer); 00075 TInt referencedId=theReader.ReadInt32(); // treat resource as integer 00076 CleanupStack::PopAndDestroy(); // refBuffer 00077 // read the other resource 00078 HBufC8* dataBuffer=multiReader->AllocReadLC(referencedId); 00079 TResourceReader reader; 00080 reader.SetBuffer(dataBuffer); 00081 TPtrC textdata = reader.ReadTPtrC(); 00082 00083 // write string to test console 00084 console->Printf(KFormat, &textdata); 00085 // clean up data buffer 00086 CleanupStack::PopAndDestroy(); // finished with dataBuffer 00087 // cleanup multi-reader 00088 CleanupStack::PopAndDestroy(); // multi-reader 00089 }