00001
00002 #ifdef WIN32
00003 #include "ortp-config-win32.h"
00004 #else
00005 #include "ortp-config.h"
00006 #endif
00007 #include "ortp/ortp.h"
00008
00009 typedef struct __STRUCT_SHARED_DATA__
00010 {
00011 DWORD m_nReference;
00012 DWORD m_dwStartTime;
00013 BOOL m_bInitialize;
00014
00015 } SHARED_DATA, * LPSHARED_DATA;
00016
00017 #ifdef EXTERNAL_LOGGER
00018 #include "logger.h"
00019 #else
00020 #define RegisterLog(logVar, logString);
00021 #define UnregisterLog(logVar, logString);
00022 #endif
00023
00024 extern DWORD dwoRTPLogLevel;
00025
00026 #define SHMEMSIZE sizeof(SHARED_DATA)
00027
00028 static LPSHARED_DATA lpSharedData;
00029 static HANDLE hMapObject = NULL;
00030
00031 BOOL WINAPI DllMain(
00032 HINSTANCE hinstDLL,
00033 DWORD fdwReason,
00034 LPVOID lpReserved
00035 )
00036 {
00037 BOOL fInit = FALSE;
00038 WORD wVersionRequested;
00039 WSADATA wsaData;
00040
00041
00042 switch( fdwReason )
00043 {
00044 case DLL_PROCESS_ATTACH:
00045
00046 OutputDebugString("--> dll_entry.c - oRTP.dll - DLL_PROCESS_ATTACH()\n");
00047
00048 wVersionRequested = MAKEWORD( 1, 0 );
00049
00050 if (WSAStartup(wVersionRequested,&wsaData)!=0)
00051 {
00052 return FALSE;
00053 }
00054
00055
00056 hMapObject = CreateFileMapping( INVALID_HANDLE_VALUE,
00057 NULL,
00058 PAGE_READWRITE,
00059 0,
00060 SHMEMSIZE,
00061 "oRTPSharedMemory");
00062
00063 if (hMapObject == NULL)
00064 return FALSE;
00065
00066
00067 fInit = (GetLastError() != ERROR_ALREADY_EXISTS);
00068
00069
00070
00071 lpSharedData = (LPSHARED_DATA) MapViewOfFile( hMapObject,
00072 FILE_MAP_WRITE,
00073 0,
00074 0,
00075 0);
00076 if (lpSharedData == NULL)
00077 return FALSE;
00078
00079
00080
00081 if (fInit)
00082 {
00083 OutputDebugString("--> dll_entry.c - oRTP.dll - Initializing module\n");
00084
00085 lpSharedData->m_dwStartTime = GetTickCount();
00086 lpSharedData->m_nReference = 1;
00087 lpSharedData->m_bInitialize = FALSE;
00088
00089
00090 RegisterLog(&dwoRTPLogLevel, "LOG_ORTP");
00091 }
00092 else
00093 {
00094 OutputDebugString("--> dll_entry.c - oRTP.dll - Binding\n");
00095 lpSharedData->m_nReference++;
00096 }
00097 break;
00098
00099 case DLL_THREAD_ATTACH:
00100
00101 if (lpSharedData != NULL)
00102 {
00103 if (lpSharedData->m_bInitialize == FALSE)
00104 {
00105
00106 ortp_init();
00107
00108
00109
00110
00111 lpSharedData->m_bInitialize = TRUE;
00112 }
00113 }
00114 break;
00115
00116 case DLL_THREAD_DETACH:
00117 break;
00118
00119 case DLL_PROCESS_DETACH:
00120
00121 if (lpSharedData != NULL)
00122 {
00123 OutputDebugString("--> dll_entry.c - oRTP.dll - Binding\n");
00124 lpSharedData->m_nReference--;
00125
00126 if (lpSharedData->m_nReference == 0)
00127 {
00128 OutputDebugString("--> dll_entry.c - oRTP.dll - Detaching\n");
00129
00130 ortp_exit();
00131 UnregisterLog(&dwoRTPLogLevel, "LOG_ORTP");
00132
00133
00134
00135 UnmapViewOfFile(lpSharedData);
00136 lpSharedData = NULL;
00137
00138
00139 CloseHandle(hMapObject);
00140 hMapObject = INVALID_HANDLE_VALUE;
00141 }
00142 }
00143 break;
00144 }
00145
00146 return TRUE;
00147 }