3
#include "ortp-config-win32.h"
5
#include "ortp-config.h"
9
typedef struct __STRUCT_SHARED_DATA__
15
} SHARED_DATA, * LPSHARED_DATA;
17
#ifdef EXTERNAL_LOGGER
20
#define RegisterLog(logVar, logString);
21
#define UnregisterLog(logVar, logString);
24
extern DWORD dwoRTPLogLevel;
26
#define SHMEMSIZE sizeof(SHARED_DATA)
28
static LPSHARED_DATA lpSharedData;
29
static HANDLE hMapObject = NULL; // handle to file mapping
32
HINSTANCE hinstDLL, // handle to DLL module
33
DWORD fdwReason, // reason for calling function
34
LPVOID lpReserved // reserved
38
WORD wVersionRequested;
41
// Perform actions based on the reason for calling.
44
case DLL_PROCESS_ATTACH:
46
OutputDebugString("--> dll_entry.c - oRTP.dll - DLL_PROCESS_ATTACH()\n");
48
wVersionRequested = MAKEWORD( 1, 0 );
50
if (WSAStartup(wVersionRequested,&wsaData)!=0)
55
// Create a named file mapping object.
56
hMapObject = CreateFileMapping( INVALID_HANDLE_VALUE, // use paging file
57
NULL, // default security attributes
58
PAGE_READWRITE, // read/write access
59
0, // size: high 32-bits
60
SHMEMSIZE, // size: low 32-bits
61
"oRTPSharedMemory"); // name of map object
63
if (hMapObject == NULL)
66
// The first process to attach initializes memory.
67
fInit = (GetLastError() != ERROR_ALREADY_EXISTS);
69
// Get a pointer to the file-mapped shared memory.
71
lpSharedData = (LPSHARED_DATA) MapViewOfFile( hMapObject, // object to map view of
72
FILE_MAP_WRITE, // read/write access
73
0, // high offset: map from
74
0, // low offset: beginning
75
0); // default: map entire file
76
if (lpSharedData == NULL)
79
// Initialize memory if this is the first process.
83
OutputDebugString("--> dll_entry.c - oRTP.dll - Initializing module\n");
85
lpSharedData->m_dwStartTime = GetTickCount();
86
lpSharedData->m_nReference = 1;
87
lpSharedData->m_bInitialize = FALSE;
90
RegisterLog(&dwoRTPLogLevel, "LOG_ORTP");
94
OutputDebugString("--> dll_entry.c - oRTP.dll - Binding\n");
95
lpSharedData->m_nReference++;
99
case DLL_THREAD_ATTACH:
101
if (lpSharedData != NULL)
103
if (lpSharedData->m_bInitialize == FALSE)
108
// Start the scheduler
109
//ortp_scheduler_init();
111
lpSharedData->m_bInitialize = TRUE;
116
case DLL_THREAD_DETACH:
119
case DLL_PROCESS_DETACH:
121
if (lpSharedData != NULL)
123
OutputDebugString("--> dll_entry.c - oRTP.dll - Binding\n");
124
lpSharedData->m_nReference--;
126
if (lpSharedData->m_nReference == 0)
128
OutputDebugString("--> dll_entry.c - oRTP.dll - Detaching\n");
131
UnregisterLog(&dwoRTPLogLevel, "LOG_ORTP");
134
// Unmap shared memory from the process's address space.
135
UnmapViewOfFile(lpSharedData);
138
// Close the process's handle to the file-mapping object.
139
CloseHandle(hMapObject);
140
hMapObject = INVALID_HANDLE_VALUE;
146
return TRUE; // Successful DLL_PROCESS_ATTACH.