Login | Register
My pages Projects Community openCollabNet

Hello World Example


This "hello World" example is converted into pure C++ from the orignal BREW SDK. It does not depend on AEEModgen.c or AEEAppGen.c.

#include "brewpp_runtime/brewpp.hpp" 
#include "helloworld.bid"


class CHelloWorld:public CDefaultBrewApplet
{
public:
    enum{CLS_ID = AEECLSID_HELLOWORLD };
    CHelloWorld(CDefaultBrewModule* mdl):CDefaultBrewApplet(mdl){}
    virtual boolean  BREW_CALL_CONV HandleEvent( AEEEvent eCode,uint16 wParam, uint32 dwParam);
};

boolean BREW_CALL_CONV CHelloWorld::HandleEvent( AEEEvent eCode,uint16 wParam, uint32 dwParam)
{
    const AECHAR szText[] = {'H','e','l','l','o',' ','W','o', 'r', 'l', 'd', '\0'};
    switch (eCode)
    {
       
        case EVT_APP_START:                      
           m_pIDisplay->DrawText(AEE_FONT_BOLD,szText,-1, 0,0,NULL, IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);
           m_pIDisplay->Update(false);
            return(TRUE);

        case EVT_APP_STOP:  
           return(TRUE);

        default:  ;  // do nothing.
   }
   return(FALSE);
}

extern "C" int AEEClsCreateInstance(AEECLSID ClsId,CDefaultBrewModule *pMod, void **ppobj)
{
    *ppobj = NULL;
    if(ClsId == CHelloWorld::CLS_ID)
    {
        *ppobj = (void**)new CHelloWorld(pMod);
        return(AEE_SUCCESS);
    }
    return EFAILED;
}

Extension Example


This example creates a BREW EXTENSION that returns a string.
#include "extension.h"
#include "brewpp_runtime/brewpp.hpp"
#include "AEEStdLib.h"

class CTestExtensionImp:public CBaseImp<IBrewTestExtension>
{
public:
    CTestExtensionImp(CDefaultBrewModule* pmod)
        :m_pIModule(pmod)
    {
        if(m_pIModule)
        {
            m_pIModule->AddRef();
        }
        STRTOWSTR("!!! Hello extension !!!",m_Msg,sizeof(m_Msg));
    }

    override const AECHAR* BREW_CALL_CONV getString()
    {
        return m_Msg;
    }

    override ~CTestExtensionImp()
    {
        if(m_pIModule)
        {
            m_pIModule->Release();
        }
    }

private:
    CDefaultBrewModule* m_pIModule;
    AECHAR m_Msg[32];
};

extern "C" int AEEClsCreateInstance(AEECLSID ClsId,CDefaultBrewModule *pMod, void **ppobj)
{
    *ppobj = NULL;
    if(ClsId == CTestExtensionImp::CLS_ID)
    {
        *ppobj = (void**)new CTestExtensionImp(pMod);
        return(AEE_SUCCESS);
    }
    return EFAILED;
}