The simplest use of a resource file involves reading string resources and interpreting the source data.
Resources are defined in terms of structs which are accessed and read by the RResourceFile class, and interpreted by the TResourceReader . An application may also use resources from multiple files simultaneously. See Resource File examples for more information.
Consider a sample resource file where a struct of STRING is defined having a single member of type LTEXT :
// define structures
STRUCT STRING
{
LTEXT text;
}
// define resources
RESOURCE STRING hello
{
text=Bonjour tout le monde!;
}
In this example, once the resource data is no longer needed, the heap descriptor, dataBuffer, can be removed from the cleanup stack and destroyed as shown in the code fragment:
CleanupStack::PopAndDestroy();
When all operations on the resource file are complete, the resource file can be closed using the RResourceFile::close() function as:
resourceFile.Close();
Consider a resource constructed from the following definition.
RESOURCE ARRAY anarray
{
items=
{
LBUF { txt="Esc"; },
LBUF { txt="Enter"; },
LBUF { txt="Tab"; },
LBUF { txt="Del"; },
LBUF { txt="Space"; }
};
}
A TPtrC representing the second item can be constructed using the ReadTPtrC() function. The example simply takes the length of the text Enter :
// open the resource file
...
HBufC8* res = resourceFile.AllocReadLC( ANARRAY );
TResourceReader theReader;
...
TInt len;
len = ( theReader.ReadTPtrC( 1,res ) ).Length(); // len == 5
...
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.