2 * Description: This module contains the main entry point (DllMain)
3 * for the library. It also contains functions to get
4 * and set global variables for the driver in the registry.
13 #include "dlg_specific.h"
18 #ifdef _WSASTARTUP_IN_DLLMAIN_
20 #endif /* _WSASTARTUP_IN_DLLMAIN_ */
25 GLOBAL_VALUES globals
;
27 EXTERN_C RETCODE SQL_API
SQLDummyOrdinal(void);
29 #if defined(WIN_MULTITHREAD_SUPPORT)
30 extern CRITICAL_SECTION conns_cs
, common_cs
;
31 #elif defined(POSIX_MULTITHREAD_SUPPORT)
32 extern pthread_mutex_t conns_cs
, common_cs
;
34 #ifdef POSIX_THREADMUTEX_SUPPORT
35 #ifdef PG_RECURSIVE_MUTEXATTR
36 static pthread_mutexattr_t recur_attr
;
37 const pthread_mutexattr_t
*getMutexAttr(void)
43 if (0 != pthread_mutexattr_init(&recur_attr
))
46 pthread_mutexattr_settype(&recur_attr
,
47 PG_RECURSIVE_MUTEXATTR
))
55 const pthread_mutexattr_t
*getMutexAttr(void)
59 #endif /* PG_RECURSIVE_MUTEXATTR */
60 #endif /* POSIX_THREADMUTEX_SUPPORT */
61 #endif /* WIN_MULTITHREAD_SUPPORT */
63 int initialize_global_cs(void)
73 _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF
| _CRTDBG_LEAK_CHECK_DF
);
74 #endif /* _MEMORY_DEBUG_ */
77 #ifdef POSIX_THREADMUTEX_SUPPORT
79 #endif /* POSIX_THREADMUTEX_SUPPORT */
87 static void finalize_global_cs(void)
94 // _CrtDumpMemoryLeaks();
95 #endif /* _MEMORY_DEBUG_ */
100 HINSTANCE NEAR s_hModule
; /* Saved module handle. */
101 /* This is where the Driver Manager attaches to this Driver */
103 DllMain(HANDLE hInst
, ULONG ul_reason_for_call
, LPVOID lpReserved
)
105 #ifdef _WSASTARTUP_IN_DLLMAIN_
106 WORD wVersionRequested
;
108 #endif /* _WSASTARTUP_IN_DLLMAIN_ */
110 switch (ul_reason_for_call
)
112 case DLL_PROCESS_ATTACH
:
113 s_hModule
= (HINSTANCE
)hInst
; /* Save for dialog boxes */
115 #ifdef _WSASTARTUP_IN_DLLMAIN_
116 /* Load the WinSock Library */
117 wVersionRequested
= MAKEWORD(1, 1);
119 if (WSAStartup(wVersionRequested
, &wsaData
))
122 /* Verify that this is the minimum version of WinSock */
123 if (LOBYTE(wsaData
.wVersion
) != 1 ||
124 HIBYTE(wsaData
.wVersion
) != 1)
129 #endif /* _WSASTARTUP_IN_DLLMAIN_ */
130 if (initialize_global_cs() == 0)
132 char pathname
[_MAX_PATH
], fname
[_MAX_FNAME
];
133 OSVERSIONINFO osversion
;
135 getCommonDefaults(DBMS_NAME
, ODBCINST_INI
, NULL
);
136 if (GetModuleFileName(NULL
, pathname
, sizeof(pathname
)) > 0)
138 _splitpath(pathname
, NULL
, NULL
, fname
, NULL
);
139 if (stricmp(fname
, "msaccess") == 0)
142 osversion
.dwOSVersionInfoSize
= sizeof(osversion
);
143 if (GetVersionEx(&osversion
))
145 platformId
= osversion
.dwPlatformId
;
147 mylog("exe name=%s plaformId=%d\n", fname
, platformId
);
151 case DLL_THREAD_ATTACH
:
154 case DLL_PROCESS_DETACH
:
155 mylog("DETACHING PROCESS\n");
156 /* my(q)log is unavailable from here */
157 finalize_global_cs();
158 #ifdef _WSASTARTUP_IN_DLLMAIN_
160 #endif /* _WSASTARTUP_IN_DLLMAIN_ */
163 case DLL_THREAD_DETACH
:
172 UNREFERENCED_PARAMETER(lpReserved
);
175 #else /* not WIN32 */
179 /* This function is called at library initialization time. */
181 static BOOL
__attribute__ ((constructor
)) init(void)
183 initialize_global_cs();
184 getCommonDefaults(DBMS_NAME
, ODBCINST_INI
, NULL
);
188 #else /* not __GNUC__ */
191 * These two functions do shared library initialziation on UNIX, well at least
192 * on Linux. I don't know about other systems.
196 initialize_global_cs();
197 getCommonDefaults(DBMS_NAME
, ODBCINST_INI
, NULL
);
203 finalize_global_cs();
206 #endif /* not __GNUC__ */
207 #endif /* not WIN32 */
211 * This function is used to cause the Driver Manager to
212 * call functions by number rather than name, which is faster.
213 * The ordinal value of this function must be 199 to have the
214 * Driver Manager do this. Also, the ordinal values of the
215 * functions must match the value of fFunction in SQLGetFunctions()
217 RETCODE SQL_API
SQLDummyOrdinal(void)