Operating INI files in Symbian

Source: Internet
Author: User

During the past two days, I was so depressed about the program that operated the INI file. To save user data in my program, I first thought of the ini configuration file, I thought it would be as easy as Windows platform. I could just take the system's provided API and I couldn't find it for a long time. I checked it online and I had to resolve it myself, after being depressed for a long time, I read the demo and tried to write it. I always encountered n problems. Then I finally wrote it and posted it ..

The SDK has mentioned that the s60 program does not support INI file operations by default. If you want to support the program, you need to reload the openinifilelc member function, and I will reload the function of the app, because my project name is symbian2, we will use symbian2 as an example now. First, we need to reload it to open the symbian2app. h reload openinifilelc

Cdictionarystore * openinifilelc (RFS & AFS) const;

Then write in the Implementation Code as follows:

Cdictionarystore * csymbian2app: openinifilelc (RFS & AFS) const
{
Return ceikapplication: openinifilelc (AFS );
}

Reload, so that our program can support the INI file. Next, we need to write the INI function.

I have written these two functions into the Appui class.

Void csymbian2appui: writeinifile (tuid iinfo, void * PTR, tuint size)
{
Tint R;
Rfs fs;
FS. Connect ();
Cleanupclosepushl (FS );
Rdictionarywritestream rdsinifile;
Cdictionarystore * cdinifile = Application ()-> openinifilelc (FS); // create if it does not exist
Rdsinifile. assignlc (* cdinifile, iinfo );
Tptr8 Buf (tuint8 *) PTR, size, size );
Trap (R, rdsinifile. writel (BUF ));
Rdsinifile. commitl ();
Cleanupstack: popanddestroy ();
Cdinifile-> commitl ();
Cleanupstack: popanddestroy (2 );
}

Tbool csymbian2appui: readinifile (tuid iinfo, void * PTR, tuint & size)
{
Tint R;
Tbool result = efalse;
Rfs fs;
FS. Connect ();
Cleanupclosepushl (FS );
Rdictionaryreadstream rdsinifile;
Cdictionarystore * cdinifile = Application ()-> openinifilelc (FS );
If (cdinifile-> ispresentl (iinfo )){
Rdsinifile. openlc (* cdinifile, iinfo );
Tptr8 Buf (tuint8 *) PTR, size );
Trap (R, rdsinifile. readl (BUF ));
Cleanupstack: popanddestroy (); // rdsinifile
Result = etrue;
}
Cleanupstack: popanddestroy (2); // FS, cdinifile
Return result;
}

Isn't that right? It's really messy. It doesn't matter. You'll know it's easy to come up with two call examples.

How to Implement the call? For example, to write the configuration, We will write the configuration only when we exit. Then we will write it in the code of csymbian2appui: handlecommandl.

Case eeikcmdexit:
{
_ Partition (kbentiontext, "bention"); // defines the text constant equivalent to the field value in ini
Hbufc * STR = kbentiontext (). alloclc (); // converts it to hbufc16 bits.
Tuint aind = 20; // defines the length of the text to be written.
Tuid testuid = {0x0bdf1365}; // defines the text identifier equivalent to the field name in ini
Writeinifile (testuid, STR, aind); // write
Exit ();
Break;
}

Exit the program after running. Go to C:/Symbian/8.0a/s60_2nd_fp2_ SC/epoc32/wins/C/system/apps/symbian2
Below, is there an extra symbian2.ini file? Open it with UE. Is there any bention? It proves that the writing is successful. Haha

You can use the following code to read the configuration.

Hbufc * tstr;
Tuint aind = 20;
Tuid testuid = {0x0bdf1365}; // note that this is the same as above. This is equivalent to the field name and is an identifier.
If (readinifile (testuid, tstr, aind) {// tstr indicates the value of the read field.
// Do what you want
}

Maybe I have some mistakes in expression. Please give me more advice.

Trackback: http://tb.blog.csdn.net/TrackBack.aspx? Postid = 696131

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.