Symbian: Build the complete process of self-starting programs

Source: Internet
Author: User

Most of the time, we want our mobile phones to run our programs and do what we want to do. This requires the following knowledge.

First, let's talk about the danger of this method:
1. I still don't know how to delete the MDL file in the mobile phone system, so once I put the MDL file in the mobile phone, if I want to delete it completely, I can't, the better way is to replace an invalid MDL file.
2. If an error occurs in the MDL file program, the machine may fail to be turned on. I did not encounter it. I confirmed on the simulator that there was no problem before putting it on the mobile phone.

Add a legal statement. The use of this article is nothing to do with all the harmful actions.

Okay, let's talk about how to do this:

First, create a mime program, that is, select s60 MIME type recognizer when creating the program.

After entering
Modify the. h file as follows:
1. Add the header file and Lib
# Include <apgcli. h>

# Include <f32file. h>

# Include <apacmdln. h>

# Include <e32std. h>

# Include <apmstd. h>

Lib: apparc. Lib apgrfx. Lib

2. Modify the UID of the program to be started. Here I take 0x0473de92 as an example. The program I want to start is test. App. The following statement is displayed in the. PKG file of this project:
# {"Test"}, (0x05dbdd8c), 1, 0, 0
0x05dbdd8c is the UID of the program.

Replace the following two rows:
Const tuid ktest1recogdlluid = {0x03d8c1a3}; // The UID is generated by the system, which is different from yours.
Const tint ktest1recogimplementationuid = 0x03d8c1a3;
To:
Const tuid kmorangemimerecogdlluid = {0x05dbdd8c };
Const tint kmorangemimerecogimplementationuid = 0x05dbdd8c;

3. Add a function declaration:
In
Tdatatype supporteddatatypel (tint aindex) const;

The following three function declarations are added:
Static void startthread ();
Static tint startappthread (Tany * aparam );
Static void startappbyuid ();

 

 

Modify the. cpp file:
1. Add a header file
# Include <apmrec. h>

# Include <apmstd. h>

# Include <apacmdln. h>

2. Add a function: that is, add the implementation of the three functions just declared:

 

Void cmorangemimerecog: startthread ()
{
Rlog: log (_ L ("in startthread ()"));

Tint res = kerrnone;
// Create a new thread for starting our application
Rthread * startappthread;
Startappthread = new rthread ();
User: leaveiferror (RES = startappthread-> Create (
_ L ("mythreadname "),
Cmorangemimerecog: startappthread,
Kdefastackstacksize,
Kminheapsize,
Kminheapsize,
Null,
Eownerthread ));
Startappthread-> setpriority (eprioritynormal );
Startappthread-> resume ();
Startappthread-> close ();
}

Tint cmorangemimerecog: startappthread (Tany */* aparam */)
{

Rlog: log (_ L ("in startappthread (Tany */* aparam */))"));

// Wait 5 seconds...
Rtimer timer; // the asynchronous timer and...
Trequeststatus timerstatus; //... its associated Request status
Timer. createlocal (); // always created for this thread.
// Get current time (microseconds since 0ad nominal Gregorian)
TTime time;
Time. hometime ();
// Add ten seconds to the time
Ttimeintervalseconds timeintervalseconds (30 );
Time + = timeintervalseconds;
// Issue and wait
Timer. At (timerstatus, time );
User: waitforrequest (timerstatus );
Cactivescheduler * scheduler = new cactivescheduler ();
If (Scheduler = NULL)
Return kerrnomemory;
Cactivescheduler: Install (Scheduler );
// Create a trap cleanup
Ctrapcleanup * cleanup = ctrapcleanup: New ();
Tint err;
If (cleanup = NULL)
{
Err = kerrnomemory;
}
Else
{
Trap (err, startappbyuid ());
}
Delete cleanup;
Delete cactivescheduler: Current ();
Return err;
}

Void cmorangemimerecog: startappbyuid ()
{

Rapalssession RAS;

User: leaveiferror (RAS. Connect ());

Cleanupclosepushl (RAS );

Tapaappinfo appinfo;

RAS. getappinfo (appinfo, kmorangemimerecogdlluid); // kmorangemimerecogdlluid is the UID of the program

Capacommandline * cmd = capacommandline: newlc ();

CMD-> setlibrarynamel (appinfo. ifullname );
CMD-> setcommandl (eapacommandrun );

RAS. Startapp (* cmd );

Cleanupstack: popanddestroy (CMD );

Cleanupstack: Pop ();
RAS. Close ();
}

 

 

 

3. Modify the automatically generated function capadatarecognizertype * createrecognizer ()

Modify to the following content:

Export_c capadatarecognizertype * createrecognizer ()
{
Capadatarecognizertype * thing = new cmorangemimerecog ();

// Start thread for our application

Cmorangemimerecog: startthread ();

Return thing;
}

In fact, cmorangemimerecog: startthread ();

Enables the system to call our functions at startup to do our work.

 

This compilation is very similar to the following web pages.

Http://www.sf.org.cn/Article/symbiandev/200701/19987.html

In fact, I also read the article, but there are two imperfections in that article, that is, the addition of apgrfx when adding a library. lib causes the lnk2019 error during program compilation. This error is generated when the corresponding function cannot be found during database connection. The other disadvantage is that the relative path is used for the program path, I just failed to set the path. User: leaveiferror (findfile. findbydir (fnapppath, knulldesc); started with UID only after leave. In addition, 5 seconds seems to be too fast, and my program is set to 30 seconds.

Also referred to the http://discussion.forum.nokia.com/forum/showpost.php? P = 216160 & postcount = 2

Appendix: the solution for starting the trial path has been solved. If you have time, write it again.

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.