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

📄 math.c

📁 进行 Brew Extension 编程的一个例子。其中包含了 Extension 和 Applet 的两个例子 和详细的文档说明
💻 C
字号:
/*===========================================================================

FILE: Math.c
===========================================================================*/


/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
//#include "AEEModGen.h"          // Module interface definitions
//#include "AEEAppGen.h"          // Applet interface definitions
#include "AEEShell.h"           // Shell interface definitions
#include "aeestdlib.h"
#include "Math.bid"
#include "Math.h"

int MyMath_New(int16 nSize, IShell *pIShell, IModule* pIModule,IModule ** ppMod);
uint32 Math_AddRef(IMath* pMe);
uint32 Math_Release(IMath* pMe);
int Math_QueryInterface(IMath* me,AEECLSID class, void** ppo);
int Math_Add(IMath *me, int a, int b);

typedef struct IMath
{
	// Declare our VTable
	const AEEVTBL(IMath) * pvt;
	uint32          m_nRefs;  // References count
	
	//IShell         *m_pIShell;
	//IDisplay       *m_pIDisplay;
	//IModule        *m_pIModule;
} CMath;



int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
{
	DBGPRINTF("******** AEEClsCreateInstance Math\n");
   *ppObj = NULL;
		
   if(ClsId == AEECLSID_MATH){
	   return MyMath_New(sizeof(IMath), pIShell, po,(IModule **)ppObj);
   }
	return (EFAILED);
}

int MyMath_New(int16 nSize, IShell *pIShell, IModule* pIModule,IModule ** ppMod) 
{
	IMath*            pMe = NULL;
   VTBL(IMath) *     modFuncs;
   DBGPRINTF("!!! MyMath_New \n");

   if( !ppMod || !pIShell || !pIModule )
   {
	   DBGPRINTF("!!!  !ppMod || !pIShell || !pIModule\n");
      return EFAILED;
	}
   *ppMod = NULL;
   // Allocate memory for the ExtensionCls object
   if( nSize < sizeof(IMath) )
      nSize += sizeof(IMath);
   // Allocate the module’s struct and initialize it. Note that the 
   // modules and apps must not have any static data. 
   // Hence, we need to allocate the vtbl as well.
   if( (pMe = (IMath*)MALLOC(nSize + sizeof(VTBL(IMath)))) == NULL )
      return ENOMEMORY; 
   modFuncs = (VTBL(IMath)*)((byte *)pMe + nSize);
   //Initialize individual entries in the VTBL
   modFuncs->AddRef              = Math_AddRef;
   modFuncs->Release             = Math_Release;
   modFuncs->QueryInterface      = Math_QueryInterface;
   modFuncs->Add		         = Math_Add;
   

   // 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);
//    // Create an instance of the IDisplay
//    if( ISHELL_CreateInstance(pIShell, AEECLSID_DISPLAY, 
//                         (void **)&pMe->m_pIDisplay) != SUCCESS )
// 
//       return EFAILED;

   // Set the pointer in the parameter
   *ppMod = (IModule*)pMe;
   DBGPRINTF("!!! MyMath_New OK\n");
   return AEE_SUCCESS;
}


static uint32 Math_AddRef(IMath* pMe) 
{
	// Increment reference count
	return ++(pMe->m_nRefs);
}

static uint32 Math_Release(IMath* pMe)
{
	// Decrement reference count
	if( --pMe->m_nRefs != 0 )
		return pMe->m_nRefs;
	
//// Ref count is zero.  Release memory associated with this object.
//// Release interfaces
// 	if( pMe->m_pIDisplay )
// 		IDISPLAY_Release(pMe->m_pIDisplay);
// 	ISHELL_Release(pMe->m_pIShell);
// 	IMODULE_Release(pMe->m_pIModule);

	
	//Free the object itself
	FREE_VTBL(pMe, IModule);
	FREE( pMe );
	DBGPRINTF("!!! Math_Release\n");

	return 0;
}

static int Math_QueryInterface(IMath* me,AEECLSID class, void** ppo) 
{

	switch (class) 
	{
	case AEECLSID_QUERYINTERFACE:
	case AEECLSID_BASE:
		*ppo = me;
		Math_AddRef(me);
		DBGPRINTF("!!! Math_QueryInterface SUCCESS\n");

		return SUCCESS;
// 	case AEECLSID_DISPLAY:
// 		*ppo = me->m_pIDisplay;
// 		return SUCCESS;
	default:
		*ppo = NULL;
		DBGPRINTF("!!! Math_QueryInterface ECLASSNOTSUPPORT\n");

		return ECLASSNOTSUPPORT;
	}
}


int Math_Add(IMath *me, int a, int b)
{
	DBGPRINTF("!!! Math_Add\n");

	return a + b;
}

⌨️ 快捷键说明

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