2010-11-18 10:39:59 +08:00
|
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
2010-11-19 14:43:13 +08:00
|
|
|
|
//实现TCOM所需要的DLL函数
|
2010-11-18 10:39:59 +08:00
|
|
|
|
|
2010-11-19 14:43:13 +08:00
|
|
|
|
//DLL提供的获取指定CLSID的指定接口
|
2010-11-18 10:39:59 +08:00
|
|
|
|
SS_EXPORT HRESULT TDllGetClassObject(TREFCLSID rclsid, TREFIID riid, LPVOID * ppv);
|
|
|
|
|
|
2010-11-19 14:43:13 +08:00
|
|
|
|
//DLL提供的查询DLL能否被Unload
|
2010-11-18 10:39:59 +08:00
|
|
|
|
SS_EXPORT HRESULT TDllCanUnloadNow(void);
|
|
|
|
|
|
2010-11-19 14:43:13 +08:00
|
|
|
|
//DLL提供的把DLL的TCOM信息加入到注册表
|
2010-11-18 10:39:59 +08:00
|
|
|
|
SS_EXPORT HRESULT TDllRegisterServer(void);
|
|
|
|
|
|
2010-11-19 14:43:13 +08:00
|
|
|
|
//DLL提供的把DLL的TCOM信息从注册表中删除
|
2010-11-18 10:39:59 +08:00
|
|
|
|
SS_EXPORT HRESULT TDllUnregisterServer(void);
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef __TCOM_OUTPUT_DEBUG_INFO__
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2010-11-19 14:43:13 +08:00
|
|
|
|
//TCOM实现中需要用到的函数和数据
|
2010-11-18 10:39:59 +08:00
|
|
|
|
|
2010-11-19 14:43:13 +08:00
|
|
|
|
//实例对象被引用的次数
|
2010-11-18 10:39:59 +08:00
|
|
|
|
static Int32 __TCOM_ClsidInstanceRefCount;
|
|
|
|
|
|
2010-11-19 14:43:13 +08:00
|
|
|
|
//ClassFactory被Locked的次数
|
2010-11-18 10:39:59 +08:00
|
|
|
|
static Int32 __TCOM_CalssFactoryLockedCount;
|
|
|
|
|
|
2010-11-19 14:43:13 +08:00
|
|
|
|
//做必要的初始化
|
2010-11-18 10:39:59 +08:00
|
|
|
|
static Int32 __TCOM_Init()
|
|
|
|
|
{
|
|
|
|
|
__TCOM_ClsidInstanceRefCount = 0;
|
|
|
|
|
__TCOM_CalssFactoryLockedCount = 0;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-19 14:43:13 +08:00
|
|
|
|
//做必要的清除工作
|
2010-11-18 10:39:59 +08:00
|
|
|
|
static Int32 __TCOM_DeInit()
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-19 14:43:13 +08:00
|
|
|
|
//DLL全局使用:增加对象实例被引用次数
|
2010-11-18 10:39:59 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-19 14:43:13 +08:00
|
|
|
|
//DLL全局使用:减少对象实例被引用次数
|
2010-11-18 10:39:59 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-19 14:43:13 +08:00
|
|
|
|
//DLL全局使用:增加ClassFactory被Locked的次数
|
2010-11-18 10:39:59 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-19 14:43:13 +08:00
|
|
|
|
//DLL全局使用:减少ClassFactory被Locked的次数
|
2010-11-18 10:39:59 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-19 14:43:13 +08:00
|
|
|
|
//实现TCOM所需要的DLL函数
|
2010-11-18 10:39:59 +08:00
|
|
|
|
|
2010-11-19 14:43:13 +08:00
|
|
|
|
//DLL提供的获取指定CLSID的指定接口
|
2010-11-18 10:39:59 +08:00
|
|
|
|
SS_EXPORT HRESULT TDllGetClassObject(TREFCLSID rclsid, TREFIID riid, LPVOID * ppv)
|
|
|
|
|
{
|
|
|
|
|
return TCOM_Srv_GetClassObject(rclsid, riid, ppv);
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-19 14:43:13 +08:00
|
|
|
|
//DLL提供的查询DLL能否被Unload
|
2010-11-18 10:39:59 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-19 14:43:13 +08:00
|
|
|
|
//DLL提供的把DLL的TCOM信息加入到注册表
|
2010-11-18 10:39:59 +08:00
|
|
|
|
SS_EXPORT HRESULT TDllRegisterServer(void)
|
|
|
|
|
{
|
|
|
|
|
return TCOM_Srv_RegisterServer();
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-19 14:43:13 +08:00
|
|
|
|
//DLL提供的把DLL的TCOM信息从注册表中删除
|
2010-11-18 10:39:59 +08:00
|
|
|
|
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:
|
2010-11-19 14:43:13 +08:00
|
|
|
|
//进程加载动态库进行的操作
|
2010-11-18 10:39:59 +08:00
|
|
|
|
#ifdef __TCOM_SUPPORT__
|
|
|
|
|
__TCOM_Init();
|
|
|
|
|
#endif
|
|
|
|
|
break;
|
|
|
|
|
case DLL_THREAD_ATTACH:
|
2010-11-19 14:43:13 +08:00
|
|
|
|
//线程加载动态库进行的操作
|
2010-11-18 10:39:59 +08:00
|
|
|
|
break;
|
|
|
|
|
case DLL_THREAD_DETACH:
|
2010-11-19 14:43:13 +08:00
|
|
|
|
//线程卸载动态库进行的操作
|
2010-11-18 10:39:59 +08:00
|
|
|
|
break;
|
|
|
|
|
case DLL_PROCESS_DETACH:
|
2010-11-19 14:43:13 +08:00
|
|
|
|
//进程卸载动态库进行的操作
|
2010-11-18 10:39:59 +08:00
|
|
|
|
#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()
|
|
|
|
|
{
|
2010-11-19 14:43:13 +08:00
|
|
|
|
//进程加载动态库进行的操作
|
2010-11-18 10:39:59 +08:00
|
|
|
|
#ifdef __TCOM_SUPPORT__
|
|
|
|
|
__TCOM_Init();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void __attribute((destructor)) TG3_Dll_Detach()
|
|
|
|
|
{
|
2010-11-19 14:43:13 +08:00
|
|
|
|
//进程卸载动态库进行的操作
|
2010-11-18 10:39:59 +08:00
|
|
|
|
#ifdef __TCOM_SUPPORT__
|
|
|
|
|
__TCOM_DeInit();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2010-11-19 14:43:13 +08:00
|
|
|
|
//如果不是作为TG3的动态库应用,请在VC项目中和TMK3文件中定义 __TG3_PURE_DLL__ 宏
|
2010-11-18 10:39:59 +08:00
|
|
|
|
#ifndef __TG3_PURE_DLL__
|
|
|
|
|
|
2010-11-19 14:43:13 +08:00
|
|
|
|
//动态库应用使用的统一导出名字的入口函数
|
2010-11-18 10:39:59 +08:00
|
|
|
|
SS_EXPORT Int32 TDllTG3AppMain(const TUChar * pAppID, UInt32 nCmd, void * pCmdParam)
|
|
|
|
|
{
|
|
|
|
|
Int32 retValue;
|
|
|
|
|
|
2010-11-19 14:43:13 +08:00
|
|
|
|
//初始化TCOM
|
2010-11-18 10:39:59 +08:00
|
|
|
|
TCoInitialize(NULL);
|
|
|
|
|
|
|
|
|
|
retValue = TG3AppMain(pAppID, nCmd, pCmdParam);
|
|
|
|
|
|
2010-11-19 14:43:13 +08:00
|
|
|
|
//释放TCOM
|
2010-11-18 10:39:59 +08:00
|
|
|
|
TCoUninitialize();
|
|
|
|
|
|
|
|
|
|
return retValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|