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 // (leave if error) 00056 #if defined(__WINS__) 00057 // add MultiRead1 version 23 00058 _LIT(KZSystemDataBasigbRsc,"Z:\\Resource\\apps\\MultiRead1.rsc"); 00059 multiReader->AddResourceFileL(KZSystemDataBasigbRsc,23); 00060 // add MultiRead2 version 17 00061 _LIT(KZSystemDataBasiguRsc,"Z:\\Resource\\apps\\MultiRead2.rsc"); 00062 multiReader->AddResourceFileL(KZSystemDataBasiguRsc,17); 00063 #endif 00064 00065 // open a resource file on the target phone 00066 // ( __EPOC32__ is defined for all target hardware platforms regardless of processor type/hardware architecture) 00067 #if defined(__EPOC32__) 00068 // add MultiRead1 version 23 00069 _LIT(KCSystemDataBasigbRsc,"Z:\\Resource\\apps\\MultiRead1.rsc"); 00070 multiReader->AddResourceFileL(KCSystemDataBasigbRsc,23); 00071 00072 // add MultiRead2 version 17 00073 _LIT(KCSystemDataBasiguRsc,"Z:\\Resource\\apps\\MultiRead2.rsc"); 00074 multiReader->AddResourceFileL(KCSystemDataBasiguRsc,17); 00075 #endif 00076 00077 // read resource that returns a reference to another resource 00078 HBufC8* refBuffer=multiReader->AllocReadLC(R_USER_HELLOREF); 00079 TResourceReader theReader; 00080 theReader.SetBuffer(refBuffer); 00081 TInt referencedId=theReader.ReadInt32(); // treat resource as integer 00082 CleanupStack::PopAndDestroy(); // refBuffer 00083 // read the other resource 00084 HBufC8* dataBuffer=multiReader->AllocReadLC(referencedId); 00085 TResourceReader reader; 00086 reader.SetBuffer(dataBuffer); 00087 TPtrC textdata = reader.ReadTPtrC(); 00088 00089 // write string to test console 00090 console->Printf(KFormat, &textdata); 00091 // clean up data buffer 00092 CleanupStack::PopAndDestroy(); // finished with dataBuffer 00093 // cleanup multi-reader 00094 CleanupStack::PopAndDestroy(); // multi-reader 00095 }