examples/SysLibs/ResourceFiles/ReadText/ReadText.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 writes the text "hello world!" from a resource file to the console
00015 // Use it as the basis of all examples which depend on BAFL
00016 //
00017 
00018 #include "CommonToResourceFilesEx.h"
00019 #include <readtext.rsg>
00020 
00021         // do the example
00022 LOCAL_C void doExampleL()
00023     {
00024         _LIT(KFormat,"%S\n");
00025 
00026         // open resource file
00027         RResourceFile resourceFile; // resource file pointer
00028         // open  file on the emulator(__WINS__  is defined for the Windows emulator)
00029         // (leave if error)
00030         #if defined(__WINS__)
00031         _LIT(KZSystemDataHelloRsc,"Z:\\Resource\\apps\\ReadText.rsc");
00032         resourceFile.OpenL(fsSession, KZSystemDataHelloRsc);
00033         #endif
00034 
00035         // open file on the target phone
00036         // ( __EPOC32__ is defined for all target hardware platforms regardless of processor type/hardware architecture)
00037         #if defined(__EPOC32__)
00038         _LIT(KCSystemDataHelloRsc,"Z:\\Resource\\apps\\ReadText.rsc");
00039         resourceFile.OpenL(fsSession, KCSystemDataHelloRsc);
00040         #endif
00041 
00042         HBufC8* dataBuffer=resourceFile.AllocReadLC(HELLO);
00043         TResourceReader reader;
00044         reader.SetBuffer(dataBuffer);
00045         TPtrC textdata = reader.ReadTPtrC();
00046 
00047         // write string to test console
00048         console->Printf(KFormat, &textdata);
00049         // clean up data buffer
00050         CleanupStack::PopAndDestroy(); // finished with dataBuffer
00051         // close resource file
00052         resourceFile.Close(); // finished with resourceFile
00053         }

Generated by  doxygen 1.6.2