×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    47

    problem about Reading data from a RESOURCE FILE to an application

    Dear all

    I have met a problem during reading data from a resource file. I have refered to the default example code (base\readdata), but I got a "program close" error in my emulator

    the following the part of my code for reading data
    **********************************************
    RResourceFile resourceFile;
    RFs fsSession;
    fsSession.Connect();

    resourceFile.OpenL( fsSession, _L ("C:\\system\\apps\\owm\\owm.rsc") );

    resourceFile.ConfirmSignatureL(0);

    HBufC8* res = resourceFile.AllocReadLC(CDA);
    iLog->Log(_L("dddd"));

    delete res;
    resourceFile.Close();
    fsSession.Close();
    iLog->LogNewline();

    **********************************************

    I know that i have to call ConfirmSignature() before calling AllocReadLC(), but I still get the error. I can log the string "dddd" so it means i got the error after calling the AllocReadLC or probably later

    So anyone knows what's going on????
    Help~~~~~
    thx a lot

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,166
    Hi

    In case you want to read resource in standard application from the default resource file you could ustilize the functions provided by CEikonEnv. ReadResourceAsDes16 or AllocReadResourceL for example.

    yucca

  3. #3
    Registered User
    Join Date
    Apr 2004
    Posts
    47
    another question here...

    i failed to get the correct data from my resource file
    i have succeeded in loading the RSC file, then i tried to access the data by TResourceReader (just as the example from the SDK)

    i tried this

    theReader.ReadInt32() (nb sth like this, to get a LONG)

    and

    theReader.ReadHufC8 (nb still sth like this, to get a LTEXT)

    but i have got some strange things...but not my data defined in the RESOURCE file....

    my resource file is like this
    RESOURCE ARRAY cda
    {
    datament = {
    DATA{
    longNum = 8;
    ltextString = "ABC";
    },
    ..............

    };
    }

  4. #4
    Super Contributor
    Join Date
    Mar 2004
    Location
    Czech Republic
    Posts
    2,037
    Hi,
    I use this code reading a string from array of strings defined in my .rss file.May be it will help you:

    ===========[C source]===========

    HBufC* GetStringLC() {
    // copy resources from file to newly allocated memory
    HBufC8* pArray = CEikonEnv::Static()->AllocReadResourceAsDes8LC(R_ARRAY_OF_STRINGS);

    // obtain pointer to requested string by returned index
    TResourceReader reader;
    TInt index = iSettings.GetStringIndex();
    TPtrC ptr = reader.ReadTPtrC(index, pArray);

    // allocate memory for requested string
    HBufC* pStr = ptr.AllocL();

    CleanupStack::PopAndDestroy(pArray);
    CleanupStack::PushL(pStr);

    return pStr;
    }

    ===========[RSS part]===========
    // ---------------------------------------------------------
    RESOURCE ARRAY r_array_of_strings {
    items = {
    LBUF { txt = " str1"; },
    LBUF { txt = "str2"; },
    LBUF { txt = "str3"; },
    ....
    };
    }

    Of course it is better to put strings into LOC file.

    Bye STeN

  5. #5
    Registered User
    Join Date
    Dec 2005
    Posts
    2

    Re: problem about Reading data from a RESOURCE FILE to an application

    Hello windalfred0.

    I have had a similar problem and your code seem fine. If u are using TBUF in your resource source files, dont! It is not putting in the rigth data into your resource file. There should be a byte with the text length and a padding byte "oxab" after that. Try changing your compiled resource file (change the first unicode character of your string to something like 0x10ab assuming your string is 10 characters long and it should work).

    Use the following instead in your resource source file:

    // Define structures
    STRUCT STRING
    {
    LTEXT text;
    }

    RESOURCE STRING foony
    {
    text = "The cow said FOO!";
    }
    The error your program gives is a BAFL 15. Look it up in your sdk documentation and you can get more information on it. The best way to see the difference is to compile a simple resource file using TBUF and then one using STRING you can then see the difference in the file. The second file should be 2 bytes bigger for the length byte and padding byte. That is if you only have one string of course.

    All the best.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×