How to obtain the pointer of the current Applet By using functions in the BREW application

Source: Internet
Author: User

During BREW application development, we often use the current small value in function functions.ProgramSome interface instances, such as ishell and idisplay, usually pass their own struct or object pointer containing the iapplet instance to the function, and then implement our operations.

For example:

The draw () function implements some painting operations, which are usually implemented as follows:

Void draw (ishell * pshell, idisplay * pdisplay)
{
Ishell_getdeviceinfo (pshell ,.....);
Ishell_loadresstring (pshell ,.....);
Idisplay_setcolor (pdisplay ,.....);
Idisplay_drawtext (pdisplay ,.....);
.........
Idisplay_update (pdisplay );
}
Every time we want to pass the pointer of these instances, it is quite troublesome and it seems that the overhead is also higher.
We can use getappinstance () to obtain these interface pointers.

Void draw ()
{
Aeeapplet * pthis = (aeeapplet *) getappinstance (); // obtain the iapplet pointer and forcibly convert it to aeeapplet
// Then we can conveniently use pthis.
Ishell_getdeviceinfo (pthis-> m_pishell ,.....);
Ishell_loadresstring (pthis-> m_pishell ,.....);
Idisplay_setcolor (pthis-> m_pidisplay ,.....);
Idisplay_drawtext (pthis-> m_pidisplay ,.....);
.........
Idisplay_update (pthis-> m_idisplay );
}

In my opinion, it is more convenient for us to compile common functions or to write a Connection Library.
This wayCodeCode can be reused later.
I think so. You are welcome to discuss it.
My email elsec@126.com

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.