Notes for C ++ Implementation of brew applicationsFor the debugger of vc6.0, it must support the C ++ language. For arm or GCC, there is also an available c ++ compiler, in addition, any phone that supports brew can run the target that is compiled and connected through arm or GCC.CodeTherefore, from the environment perspective, brew development can apply the C ++ language.
Anyone who has done brew development knows that iwindow and statemachine are both C languages used, and the C compiler is also used by the compiler, however, there are not many applications for Object-Oriented C ++ languages with excellent ideas.
In fact, brew development fully supports the C ++ language.
However, the brew examples we generally see are all written in C, and there are not many examples of C ++. In addition, for the brew of C ++, more things need to be done, such as the heavy-load definition character, etc. Below I will make a brief analysis on the Normal C ++ language development brew.
To enable a brew written in C ++ProgramTo run the SDK, you must complete the following steps:
1. class definition in the C ++ header file:
// Cppapp. h
# Ifndef _ cppapp_h _
# DEFINE _ cppapp_h _
// Class definition
Class cppapp: Public aeeapplet
{
}
# Endif
2. Before defining a class, # include introduces the header file to be referenced:
# Include "aeeappgen. H" // The subject class inherits aeeapplet
# Include "aeemodgen. H"
# Include "aeemenu. H" // class cppapp defines imenuctl interface member variables
------------------------------------------------------------
3. The Program subject class should inherit aeeapplet as its subclass: Class cppapp: Public aeeapplet
4. The event processing mechanism class is encapsulated as follows:
()
Cppapp. h:
{< br> Public:
static Boolean handleevent (cppapp * pcppapp, aeeevent ecode, uint16 wparam, uint32 dwparam);
// public interface for event processing, static type ?? Cppapp * pcppapp reference pcppapp-> onevent ();
static void freeappdata (cppapp * pcppapp);
static Boolean initappdata (iapplet * piapplet ); // static type ?? Easy to call in brew C mode ??
Protected:
Boolean onappinitdata (); // onxxxxxx: indicates class encapsulated xxxxxx event processing to protect members
// Initialize program data, which can be common
Void onappfreedata ();
// Release the program to allocate resources, universal mechanism
Boolean onevent (aeeevent ecode, uint16 wparam, uint32 dwparam );
// Handle events encapsulated by the subject class
}
(B)
Cppapp. cpp:
Boolean cppapp: handleevent (cppapp * pcppapp, aeeevent ecode, uint16 wparam, uint32 dwparam)
{
Return pcppapp-> onevent (ecode, wparam, dwparam );
}
Conclusion: 1. The onevent (aeeevent, uint16, uint32) of the entity class protects the response of the class to the event;
2. handleevent of the static public interface of the subject class, which calls onevent in the class to complete event response;
5. register the program entry and event processing mechanism in C ++:
Extern "C"
// Easy to call in brew C mode ??
// Aeeclscreateinstance can only be called by brew in C mode as a program entry ??
Int aeeclscreateinstance (aeeclsid CLSID, ishell * pishell, imodule * pimodule, void ** ppobj)
// Each parameter is the input value of the brew framework.
{
If (CLSID = aeeclsid_cppapp)
{
If (! Aeeapplet_new (sizeof (cppapp), CLSID, pishell, pimodule, (iapplet **) ppobj, (aeehandler) cppapp: handleevent,
(Pfnfreeappdata) cppapp: freeappdata ))
// Register the event processing and program data release functions implemented in C ++
Return efailed;
If (! Cppapp: initappdata (iapplet *) * ppobj ))
// Initialize program data
Return efailed;
Return success;
}
Return efailed;
}
6. Introduce the header file in the cppapp. cpp file of the subject class:
# Include "cppapp. H"
# Include "otherclass. H" // introduce the required C ++ Class header file
# Include "cppapp. Bid" // CLSID judgment in aeeclscreateinstance
# Include "aeestdlib. H" // introduce the header file of the helper functions such as strcpy referenced in the class implementation
# Include "cppapp_res.h" // reference the resorceid in the class implementation and reference the resource
7. Introduce the header file in the non-subject CPP file:
# Include "otherclass. H"
# Include "aeestdlib. H" // introduce the header file of the helper functions such as strcpy referenced in the class implementation
# Include "cppapp_res.h" // reference the resorceid in the class implementation and reference the resource
8. Bar resource file introduction:
9. Declare the brew interface variable in the non-subject class and introduce the corresponding header file:
# Include "aeedisp. H" // declare the idisplay * interface member in the class
-----------------
# Include "aeeshell. H"
-----------------
Writer (ishell * pishell );
{
-----------------
Ishell_createinstance (pishell, aeeclsid_display, (void **) & m_pidisplay );
// The ishell * pishell parameter used by writer comes from "# include" aeeshell. H "" and creates m_pidisplay, which is directly referenced below;
-----------------
Idisplay_erasergn (m_pidisplay, 0, 0, m_di.cxscreen, m_di.cyscreen );
// Reference the created member variable;
-----------------
}
10. # Use of define:
In CPP # define cannot be referenced by other CPP. In some. h # define if some. H is introduced by other. H, it can be used in other. cpp