Resources | Resources |



CreateInstance function

When you use the C Application Wizard for a MOD, the Wizard creates an AEEClsCreateInstance() function, which instantiates the applet class for the application by calling AEEApplet_New(), as shown in the example below. AEEClsCreateInstance() then calls MyApp_InitAppData() to initialize data used by the application (see InitAppData function). MyApp_InitAppData() is created by the Wizard.

int AEEClsCreateInstance(AEECLSID ClsId, IShell * piShell, IModule * piModule, 
						 void ** ppObj)
    *ppObj = NULL;

    // Confirm this applet is the one intended to be created (classID matches):
    if( AEECLSID_C_BASICAPP == ClsId ) {
        // Create the applet and make room for the applet structure.
        // NOTE: FreeAppData is called after EVT_APP_STOP is sent to HandleEvent.
	    if( TRUE == AEEApplet_New(sizeof(MyApp),
                        (PFNFREEAPPDATA)MyApp_FreeAppData) ) {
            // Initialize applet data. This is called before EVT_APP_START is
            // sent to the HandleEvent function.
		    if(TRUE == MyApp_InitAppData((MyApp*)*ppObj)) {
			    return AEE_SUCCESS;  // Data initialized successfully
		    else {
                // Release the applet. This will free the memory allocated for
                // the applet when AEEApplet_New was called.
                return AEE_EFAILED;
        } // End AEEApplet_New
    return AEE_EFAILED;