4
* Description: This module contains the main entry point (DllMain)
5
* for the library. It also contains functions to get
6
* and set global variables for the driver in the registry.
12
* Comments: See "notice.txt" for copyright and license information.
22
#include "dlg_specific.h"
30
static int exepgm = 0;
31
BOOL isMsAccess() {return 1 == exepgm;}
32
BOOL isMsQuery() {return 2 == exepgm;}
33
BOOL isSqlServr() {return 3 == exepgm;}
35
GLOBAL_VALUES globals;
37
RETCODE SQL_API SQLDummyOrdinal(void);
39
#if defined(WIN_MULTITHREAD_SUPPORT)
40
extern CRITICAL_SECTION conns_cs, common_cs;
41
#elif defined(POSIX_MULTITHREAD_SUPPORT)
42
extern pthread_mutex_t conns_cs, common_cs;
44
#ifdef POSIX_THREADMUTEX_SUPPORT
45
#ifdef PG_RECURSIVE_MUTEXATTR
46
static pthread_mutexattr_t recur_attr;
47
const pthread_mutexattr_t* getMutexAttr(void)
53
if (0 != pthread_mutexattr_init(&recur_attr))
55
if (0 != pthread_mutexattr_settype(&recur_attr, PG_RECURSIVE_MUTEXATTR))
63
const pthread_mutexattr_t* getMutexAttr(void)
67
#endif /* PG_RECURSIVE_MUTEXATTR */
68
#endif /* POSIX_THREADMUTEX_SUPPORT */
69
#endif /* WIN_MULTITHREAD_SUPPORT */
71
int initialize_global_cs(void)
81
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF|_CRTDBG_LEAK_CHECK_DF);
82
#endif /* _MEMORY_DEBUG_ */
85
#ifdef POSIX_THREADMUTEX_SUPPORT
87
#endif /* POSIX_THREADMUTEX_SUPPORT */
95
static void finalize_global_cs(void)
101
#ifdef _MEMORY_DEBUG_
102
// _CrtDumpMemoryLeaks();
103
#endif /* _MEMORY_DEBUG_ */
108
HINSTANCE NEAR s_hModule; /* Saved module handle. */
109
/* This is where the Driver Manager attaches to this Driver */
111
DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
113
switch (ul_reason_for_call)
115
case DLL_PROCESS_ATTACH:
116
s_hModule = hInst; /* Save for dialog boxes */
118
if (initialize_global_cs() == 0)
120
char pathname[_MAX_PATH], fname[_MAX_FNAME];
121
OSVERSIONINFO osversion;
123
getCommonDefaults(DBMS_NAME, ODBCINST_INI, NULL);
124
if (GetModuleFileName(NULL, pathname, sizeof(pathname)) > 0)
126
_splitpath(pathname, NULL, NULL, fname, NULL);
127
if (stricmp(fname, "msaccess") == 0)
129
else if (strnicmp(fname, "msqry", 5) == 0)
131
else if (strnicmp(fname, "sqlservr", 8) == 0)
134
osversion.dwOSVersionInfoSize = sizeof(osversion);
135
if (GetVersionEx(&osversion))
137
platformId=osversion.dwPlatformId;
139
mylog("exe name=%s plaformId=%d\n", fname, platformId);
143
case DLL_THREAD_ATTACH:
146
case DLL_PROCESS_DETACH:
147
mylog("DETACHING PROCESS\n");
148
CleanupDelayLoadedDLLs();
149
/* my(q)log is unavailable from here */
150
finalize_global_cs();
153
case DLL_THREAD_DETACH:
162
UNREFERENCED_PARAMETER(lpReserved);
165
#else /* not WIN32 */
169
/* This function is called at library initialization time. */
172
__attribute__((constructor))
175
initialize_global_cs();
176
getCommonDefaults(DBMS_NAME, ODBCINST_INI, NULL);
180
#else /* not __GNUC__ */
183
* These two functions do shared library initialziation on UNIX, well at least
184
* on Linux. I don't know about other systems.
189
initialize_global_cs();
190
getCommonDefaults(DBMS_NAME, ODBCINST_INI, NULL);
197
finalize_global_cs();
200
#endif /* not __GNUC__ */
201
#endif /* not WIN32 */
205
* This function is used to cause the Driver Manager to
206
* call functions by number rather than name, which is faster.
207
* The ordinal value of this function must be 199 to have the
208
* Driver Manager do this. Also, the ordinal values of the
209
* functions must match the value of fFunction in SQLGetFunctions()
212
SQLDummyOrdinal(void)
4
* Description: This module contains the main entry point (DllMain)
5
* for the library. It also contains functions to get
6
* and set global variables for the driver in the registry.
12
* Comments: See "readme.txt" for copyright and license information.
22
#include "dlg_specific.h"
30
static int exepgm = 0;
31
BOOL isMsAccess() {return 1 == exepgm;}
32
BOOL isMsQuery() {return 2 == exepgm;}
33
BOOL isSqlServr() {return 3 == exepgm;}
35
GLOBAL_VALUES globals;
37
RETCODE SQL_API SQLDummyOrdinal(void);
39
#if defined(WIN_MULTITHREAD_SUPPORT)
40
extern CRITICAL_SECTION conns_cs, common_cs;
41
#elif defined(POSIX_MULTITHREAD_SUPPORT)
42
extern pthread_mutex_t conns_cs, common_cs;
44
#ifdef POSIX_THREADMUTEX_SUPPORT
45
#ifdef PG_RECURSIVE_MUTEXATTR
46
static pthread_mutexattr_t recur_attr;
47
const pthread_mutexattr_t* getMutexAttr(void)
53
if (0 != pthread_mutexattr_init(&recur_attr))
55
if (0 != pthread_mutexattr_settype(&recur_attr, PG_RECURSIVE_MUTEXATTR))
63
const pthread_mutexattr_t* getMutexAttr(void)
67
#endif /* PG_RECURSIVE_MUTEXATTR */
68
#endif /* POSIX_THREADMUTEX_SUPPORT */
69
#endif /* WIN_MULTITHREAD_SUPPORT */
71
int initialize_global_cs(void)
81
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF|_CRTDBG_LEAK_CHECK_DF);
82
#endif /* _MEMORY_DEBUG_ */
85
#ifdef POSIX_THREADMUTEX_SUPPORT
87
#endif /* POSIX_THREADMUTEX_SUPPORT */
95
static void finalize_global_cs(void)
101
#ifdef _MEMORY_DEBUG_
102
// _CrtDumpMemoryLeaks();
103
#endif /* _MEMORY_DEBUG_ */
108
HINSTANCE NEAR s_hModule; /* Saved module handle. */
109
/* This is where the Driver Manager attaches to this Driver */
111
DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
113
switch (ul_reason_for_call)
115
case DLL_PROCESS_ATTACH:
116
s_hModule = hInst; /* Save for dialog boxes */
118
if (initialize_global_cs() == 0)
120
char pathname[_MAX_PATH], fname[_MAX_FNAME];
121
OSVERSIONINFO osversion;
123
getCommonDefaults(DBMS_NAME, ODBCINST_INI, NULL);
124
if (GetModuleFileName(NULL, pathname, sizeof(pathname)) > 0)
126
_splitpath(pathname, NULL, NULL, fname, NULL);
127
if (stricmp(fname, "msaccess") == 0)
129
else if (strnicmp(fname, "msqry", 5) == 0)
131
else if (strnicmp(fname, "sqlservr", 8) == 0)
134
osversion.dwOSVersionInfoSize = sizeof(osversion);
135
if (GetVersionEx(&osversion))
137
platformId=osversion.dwPlatformId;
139
mylog("exe name=%s plaformId=%d\n", fname, platformId);
143
case DLL_THREAD_ATTACH:
146
case DLL_PROCESS_DETACH:
147
mylog("DETACHING PROCESS\n");
148
CleanupDelayLoadedDLLs();
149
/* my(q)log is unavailable from here */
150
finalize_global_cs();
153
case DLL_THREAD_DETACH:
162
UNREFERENCED_PARAMETER(lpReserved);
165
#else /* not WIN32 */
169
/* Shared library initializer and destructor, using gcc's attributes */
172
__attribute__((constructor))
175
initialize_global_cs();
176
getCommonDefaults(DBMS_NAME, ODBCINST_INI, NULL);
180
__attribute__((destructor))
183
finalize_global_cs();
186
#else /* not __GNUC__ */
188
/* Shared library initialization on non-gcc systems. */
192
initialize_global_cs();
193
getCommonDefaults(DBMS_NAME, ODBCINST_INI, NULL);
200
finalize_global_cs();
203
#endif /* not __GNUC__ */
204
#endif /* not WIN32 */
208
* This function is used to cause the Driver Manager to
209
* call functions by number rather than name, which is faster.
210
* The ordinal value of this function must be 199 to have the
211
* Driver Manager do this. Also, the ordinal values of the
212
* functions must match the value of fFunction in SQLGetFunctions()
215
SQLDummyOrdinal(void)