⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gatewayextension.cpp

📁 使用C++开发Brew 应用扩展模块例子。
💻 CPP
字号:
/*===========================================================================

FILE: GatewayExtension.c
VITULAR Information Techongy CO.,Ltd
All Rights Reserved.
2005/03/25
===========================================================================*/


/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#include "GatewayExtension.h"

/*-------------------------------------------------------------------
Applet structure. All variables in here are reference via "pMe->"
-------------------------------------------------------------------*/
// create an applet structure that's passed around. All variables in
// here will be able to be referenced as static.
typedef struct _GatewayExtension
{
	// Declare our VTable
	// by doing so, we have placed function pointers
	// in the begininng of this structure
	DECLARE_VTBL(IGatewayExtension)

	// Class member variables
	uint32		m_nRefs;		// References to us
	IShell *	   m_pIShell;		// copy of Shell pointer
	IDisplay *	m_pIDisplay;	// Display interface pointer
	IModule *	m_pIModule;		// IModule interface pointer
}GatewayExtension;

// Exported AEEClsCreateInstance
extern int			AEEClsCreateInstance(AEECLSID, IShell*, IModule*, void**);

/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static uint32		GatewayExtension_AddRef(IGatewayExtension * po);
static uint32		GatewayExtension_Release(IGatewayExtension * po);

/*===========================================================================

Function:  GatewayExtendsion_New()

Description:
		This function is called from AEEClsCreateInstance. This helps 
		with construction of the class and initialization of it's members.	

Prototype:
	int GatewayExtendsion_New(int16 nSize, IShell *pIShell, IModule* pIModule, IModule ** ppMod)

Parameters:
	nSize: Specifies the size (in bytes) of the structure to be allocated for the module
	Typically, this is the size of the structure (or class)
	pIShell: Pointer to IShell interface
	pIModule: Pointer to the IModule interface
	ppMod: [ou]: On return, *ppMod contains a valid pointer to the ExtensionCls structure 
	(or class)

Return Value:
	AEE_SUCCESS: If successful
	Error code: IF failed

Comments:  None

Side Effects: None

==============================================================================*/
int GatewayExtension_New(int16 nSize, IShell *pIShell, IModule* pIModule, IModule ** ppMod)
{
	GatewayExtension *			   pMe = NULL;
	VTBL(IGatewayExtension) *	modFuncs;

	if( !ppMod || !pIShell || !pIModule )
		return EFAILED;

	*ppMod = NULL;

	// Allocate memory for the ExtensionCls object
	if( nSize < sizeof(GatewayExtension) )
		nSize += sizeof(GatewayExtension);

	if( (pMe = (GatewayExtension *)MALLOC(nSize + sizeof(IGatewayExtensionVtbl))) == NULL )
		return ENOMEMORY;

	// Allocate the vtbl and initialize it. Note that the modules and apps must not
	// have any static data. Hence, we need to allocate the vtbl as well.
	modFuncs = (IGatewayExtensionVtbl *)((byte *)pMe + nSize);
	//Initialize individual entries in the VTBL

	modFuncs->AddRef			= GatewayExtension_AddRef;
	modFuncs->Release			= GatewayExtension_Release;
	modFuncs->DrawSmiley		= GatewayExtension_DrawSmiley;
	//modFuncs->DrawHello			= GatewayExtension_DrawHello;

	// initialize the vtable
	INIT_VTBL(pMe, IModule, *modFuncs);

	// initialize the data members
	pMe->m_nRefs      = 1;
	pMe->m_pIShell    = pIShell;
	pMe->m_pIModule   = pIModule;

	// Add References and get IDisplay
	ISHELL_AddRef(pIShell);
	IMODULE_AddRef(pIModule);
	if( ISHELL_CreateInstance(pIShell, AEECLSID_DISPLAY, (void **)&pMe->m_pIDisplay) != SUCCESS )
		return EFAILED;

	// Set the pointer in the parameter
	*ppMod = (IModule*)pMe;

	return AEE_SUCCESS;
}


/*===========================================================================

Function:  GatewayExtension_AddRef()

Description:
		This function increases the reference count for the ExtensionCls object

Prototype:
	uint32 GatewayExtension_AddRef(IGatewayExtension * po)

Parameters:
   po: Pointer to IGatewayExtension interface whos reference count is to be incremented

Return Value:
	The updated reference count

Comments:  None

Side Effects: None

==============================================================================*/
static uint32 GatewayExtension_AddRef(IGatewayExtension * po)
{
   return (++((GatewayExtension *)po)->m_nRefs);
}
/*===========================================================================

Function:  GatewayExtension_Release()

Description:
		This function decreases the reference count for the ExtensionCls object. If
		the reference count reaches zero, it does the required cleanup

Prototype:
	uint32 GatewayExtension_Release(IExtensionCls* po)

Parameters:
   po: Pointer to the IGatewayExtension interface whose reference count needs to be
	decremented.

Return Value:
   The updated reference count

Comments:  None

Side Effects: None

==============================================================================*/
static uint32 GatewayExtension_Release(IGatewayExtension * po)
{
	GatewayExtension *		pMe = (GatewayExtension *)po;

	if( --pMe->m_nRefs != 0 )
		return pMe->m_nRefs;

	// Ref count is zero. So, release memory associated with this object.

	if( pMe->m_pIDisplay )
		IDISPLAY_Release(pMe->m_pIDisplay);

	// Release interfaces
	ISHELL_Release(pMe->m_pIShell);
	IMODULE_Release(pMe->m_pIModule);
	//Free the object itself
	FREE_VTBL(pMe, IModule);
	FREE( pMe );

	return 0;
}

/*===========================================================================

Function:  AEEClsCreateInstance()

Description:
		This function decreases the reference count for the ExtensionCls object. If
		the reference count reaches zero, it does the required cleanup.
		Calls a helper function to initialize the class members and VTable.

Prototype:
	uint32 AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)

Parameters:
   ClsId: Clsid passed in
   pIShell: IShell pointer
   po: IModule pointer
   ppObj[out]: Pointer to a pointer of the class object to fill

Return Value:
   AEE_SUCCESS on pass
   Error code on failure
Comments:  None

Side Effects: None

==============================================================================*/
int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
{
	*ppObj = NULL;
		
	if( ClsId == GATEWAYEXTENSION_CLSID )
	{
		if( GatewayExtension_New(sizeof(GatewayExtension), pIShell, po, (IModule **)ppObj) == SUCCESS )
			return AEE_SUCCESS;
	}
	return EFAILED;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -