axmol/HelloWorld/TG3AppDllEntry.cpp

232 lines
5.3 KiB
C++
Raw Normal View History

#include "ssGlobal.h"
#include "ssTsd.h"
#include "TG3_Type.h"
#include <stdio.h>
#include "TCOM.h"
#include "ssAppMgr.h"
#include "TG3AppDllEntry.h"
#ifdef __TCOM_SUPPORT__
#ifdef __cplusplus
extern "C" {
#endif
//ʵ<><CAB5>TCOM<4F><4D><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>DLL<4C><4C><EFBFBD><EFBFBD>
//DLL<4C><EFBFBD>Ļ<EFBFBD>ȡָ<C8A1><D6B8>CLSID<49><44>ָ<EFBFBD><D6B8><EFBFBD>ӿ<EFBFBD>
SS_EXPORT HRESULT TDllGetClassObject(TREFCLSID rclsid, TREFIID riid, LPVOID * ppv);
//DLL<4C><EFBFBD>IJ<EFBFBD>ѯDLL<4C>ܷ<EFBFBD><DCB7><EFBFBD>Unload
SS_EXPORT HRESULT TDllCanUnloadNow(void);
//DLL<4C><EFBFBD>İ<EFBFBD>DLL<4C><4C>TCOM<4F><4D>Ϣ<EFBFBD><CFA2><EFBFBD>뵽ע<EBB5BD><D7A2><EFBFBD><EFBFBD>
SS_EXPORT HRESULT TDllRegisterServer(void);
//DLL<4C><EFBFBD>İ<EFBFBD>DLL<4C><4C>TCOM<4F><4D>Ϣ<EFBFBD><CFA2>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE>
SS_EXPORT HRESULT TDllUnregisterServer(void);
#ifdef __cplusplus
}
#endif
#ifdef __TCOM_OUTPUT_DEBUG_INFO__
#include <stdio.h>
#endif
//TCOMʵ<4D><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>õ<EFBFBD><C3B5>ĺ<EFBFBD><C4BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//ʵ<><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õĴ<C3B5><C4B4><EFBFBD>
static Int32 __TCOM_ClsidInstanceRefCount;
//ClassFactory<72><79>Locked<65>Ĵ<EFBFBD><C4B4><EFBFBD>
static Int32 __TCOM_CalssFactoryLockedCount;
//<2F><><EFBFBD><EFBFBD>Ҫ<EFBFBD>ij<EFBFBD>ʼ<EFBFBD><CABC>
static Int32 __TCOM_Init()
{
__TCOM_ClsidInstanceRefCount = 0;
__TCOM_CalssFactoryLockedCount = 0;
return 0;
}
//<2F><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
static Int32 __TCOM_DeInit()
{
return 0;
}
//DLLȫ<4C><C8AB>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD>Ӷ<EFBFBD><D3B6><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><C3B4><EFBFBD>
Int32 TCOM_AddClsidInstanceRefCount()
{
__TCOM_ClsidInstanceRefCount++;
#ifdef __TCOM_OUTPUT_DEBUG_INFO__
SS_printf("[TCOM_SYSTEM] TCOM_AddClsidInstanceRefCount: address: %p, value: %d.\n",
&__TCOM_ClsidInstanceRefCount, __TCOM_ClsidInstanceRefCount);
#endif
if(__TCOM_ClsidInstanceRefCount <= 0)
{
return 0;
}
return __TCOM_ClsidInstanceRefCount;
}
//DLLȫ<4C><C8AB>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD>ٶ<EFBFBD><D9B6><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><C3B4><EFBFBD>
Int32 TCOM_DecClsidInstanceRefCount()
{
__TCOM_ClsidInstanceRefCount--;
#ifdef __TCOM_OUTPUT_DEBUG_INFO__
SS_printf("[TCOM_SYSTEM] TCOM_DecClsidInstanceRefCount: address: %p, value: %d.\n",
&__TCOM_ClsidInstanceRefCount, __TCOM_ClsidInstanceRefCount);
#endif
if(__TCOM_ClsidInstanceRefCount <= 0)
{
return 0;
}
return __TCOM_ClsidInstanceRefCount;
}
//DLLȫ<4C><C8AB>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD>ClassFactory<72><79>Locked<65>Ĵ<EFBFBD><C4B4><EFBFBD>
Int32 TCOM_AddCalssFactoryLockedCount()
{
__TCOM_CalssFactoryLockedCount++;
#ifdef __TCOM_OUTPUT_DEBUG_INFO__
SS_printf("[TCOM_SYSTEM] TCOM_AddCalssFactoryLockedCount: address: %p, value: %d.\n",
&__TCOM_CalssFactoryLockedCount, __TCOM_CalssFactoryLockedCount);
#endif
if(__TCOM_CalssFactoryLockedCount <= 0)
{
return 0;
}
return __TCOM_CalssFactoryLockedCount;
}
//DLLȫ<4C><C8AB>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD>ClassFactory<72><79>Locked<65>Ĵ<EFBFBD><C4B4><EFBFBD>
Int32 TCOM_DecCalssFactoryLockedCount()
{
__TCOM_CalssFactoryLockedCount--;
#ifdef __TCOM_OUTPUT_DEBUG_INFO__
SS_printf("[TCOM_SYSTEM] TCOM_DecCalssFactoryLockedCount: address: %p, value: %d.\n",
&__TCOM_CalssFactoryLockedCount, __TCOM_CalssFactoryLockedCount);
#endif
if(__TCOM_CalssFactoryLockedCount <= 0)
{
return 0;
}
return __TCOM_CalssFactoryLockedCount;
}
//ʵ<><CAB5>TCOM<4F><4D><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>DLL<4C><4C><EFBFBD><EFBFBD>
//DLL<4C><EFBFBD>Ļ<EFBFBD>ȡָ<C8A1><D6B8>CLSID<49><44>ָ<EFBFBD><D6B8><EFBFBD>ӿ<EFBFBD>
SS_EXPORT HRESULT TDllGetClassObject(TREFCLSID rclsid, TREFIID riid, LPVOID * ppv)
{
return TCOM_Srv_GetClassObject(rclsid, riid, ppv);
}
//DLL<4C><EFBFBD>IJ<EFBFBD>ѯDLL<4C>ܷ<EFBFBD><DCB7><EFBFBD>Unload
SS_EXPORT HRESULT TDllCanUnloadNow(void)
{
#ifdef __TCOM_OUTPUT_DEBUG_INFO__
SS_printf("[TCOM_SYSTEM] TDllCanUnloadNow: address1: %p, address2: %p, value1: %d, value2: %d.\n",
&__TCOM_ClsidInstanceRefCount, &__TCOM_CalssFactoryLockedCount, __TCOM_ClsidInstanceRefCount,
__TCOM_CalssFactoryLockedCount);
#endif
if((__TCOM_ClsidInstanceRefCount <= 0) && (__TCOM_CalssFactoryLockedCount <= 0))
return TCOM_S_TRUE;
return TCOM_S_FALSE;
}
//DLL<4C><EFBFBD>İ<EFBFBD>DLL<4C><4C>TCOM<4F><4D>Ϣ<EFBFBD><CFA2><EFBFBD>뵽ע<EBB5BD><D7A2><EFBFBD><EFBFBD>
SS_EXPORT HRESULT TDllRegisterServer(void)
{
return TCOM_Srv_RegisterServer();
}
//DLL<4C><EFBFBD>İ<EFBFBD>DLL<4C><4C>TCOM<4F><4D>Ϣ<EFBFBD><CFA2>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE>
SS_EXPORT HRESULT TDllUnregisterServer(void)
{
return TCOM_Srv_UnregisterServer();
}
#endif //__TCOM_SUPPORT__
#ifdef _WIN32
#ifndef SS_MAKEDLL
#error Error!!! SS_MAKEDLL Must defined!
#endif
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
//<2F><><EFBFBD>̼<EFBFBD><CCBC>ض<EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD><EFBFBD>еIJ<D0B5><C4B2><EFBFBD>
#ifdef __TCOM_SUPPORT__
__TCOM_Init();
#endif
break;
case DLL_THREAD_ATTACH:
//<2F>̼߳<DFB3><CCBC>ض<EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD><EFBFBD>еIJ<D0B5><C4B2><EFBFBD>
break;
case DLL_THREAD_DETACH:
//<2F>߳<EFBFBD>ж<EFBFBD>ض<EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD><EFBFBD>еIJ<D0B5><C4B2><EFBFBD>
break;
case DLL_PROCESS_DETACH:
//<2F><><EFBFBD><EFBFBD>ж<EFBFBD>ض<EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD><EFBFBD>еIJ<D0B5><C4B2><EFBFBD>
#ifdef __TCOM_SUPPORT__
__TCOM_DeInit();
#endif
break;
}
return TRUE;
}
#else //linux
#ifndef SS_SHARED
#error Error!!! SS_SHARED Must defined!
#endif
void __attribute((constructor)) TG3_Dll_Attach()
{
//<2F><><EFBFBD>̼<EFBFBD><CCBC>ض<EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD><EFBFBD>еIJ<D0B5><C4B2><EFBFBD>
#ifdef __TCOM_SUPPORT__
__TCOM_Init();
#endif
}
void __attribute((destructor)) TG3_Dll_Detach()
{
//<2F><><EFBFBD><EFBFBD>ж<EFBFBD>ض<EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD><EFBFBD>еIJ<D0B5><C4B2><EFBFBD>
#ifdef __TCOM_SUPPORT__
__TCOM_DeInit();
#endif
}
#endif
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪTG3<47>Ķ<EFBFBD>̬<EFBFBD><CCAC>Ӧ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD>VC<56><43>Ŀ<EFBFBD>к<EFBFBD>TMK3<4B>ļ<EFBFBD><C4BC>ж<EFBFBD><D0B6><EFBFBD> __TG3_PURE_DLL__ <20><>
#ifndef __TG3_PURE_DLL__
//<2F><>̬<EFBFBD><CCAC>Ӧ<EFBFBD><D3A6>ʹ<EFBFBD>õ<EFBFBD>ͳһ<CDB3><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>ں<EFBFBD><DABA><EFBFBD>
SS_EXPORT Int32 TDllTG3AppMain(const TUChar * pAppID, UInt32 nCmd, void * pCmdParam)
{
Int32 retValue;
//<2F><>ʼ<EFBFBD><CABC>TCOM
TCoInitialize(NULL);
retValue = TG3AppMain(pAppID, nCmd, pCmdParam);
//<2F>ͷ<EFBFBD>TCOM
TCoUninitialize();
return retValue;
}
#endif