diff options
Diffstat (limited to 'psqlsetup.c')
| -rw-r--r-- | psqlsetup.c | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/psqlsetup.c b/psqlsetup.c index a12be04..d2bd038 100644 --- a/psqlsetup.c +++ b/psqlsetup.c @@ -7,8 +7,6 @@ HINSTANCE s_hModule; /* Saved module handle. */ #ifdef PG_BIN -#include "loadlib.h" -#include <DelayImp.h> #include <stdio.h> #include <string.h> #include <sql.h> @@ -30,7 +28,8 @@ SQLDummyOrdinal(void) #endif /* PG_BIN */ -static HINSTANCE s_hLModule; +static HINSTANCE s_hLModule = NULL; +static HINSTANCE s_hLModule2 = NULL; /* This is where the Driver Manager attaches to this Driver */ extern GLOBAL_VALUES globals; @@ -59,9 +58,19 @@ static void finalize_global_cs(void) #endif /* _DEBUG */ } +#ifdef UNICODE_SUPPORT +CSTR psqlodbcdll = "psqlodbc35w.dll"; +#else +CSTR psqlodbcdll = "psqlodbc30a.dll"; + +#endif + BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) { + char dllPath[MAX_PATH] = ""; + char *sptr; + switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: @@ -71,10 +80,12 @@ DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) getCommonDefaults(DBMS_NAME, ODBCINST_INI, NULL); #ifdef PG_BIN if (s_hLModule = LoadLibraryEx(PG_BIN "\\libpq.dll", NULL, LOAD_WITH_ALTERED_SEARCH_PATH), s_hLModule == NULL) + mylog("libpq in the folder %s couldn't be loaded\n", PG_BIN); +#endif /* PG_BIN */ + if (NULL == s_hLModule) { - char dllPath[MAX_PATH] = "", message[MAX_PATH] = ""; + char message[MAX_PATH] = ""; - mylog("libpq in the folder %s couldn't be loaded\n", PG_BIN); SQLGetPrivateProfileString(DBMS_NAME, "Driver", "", dllPath, sizeof(dllPath), ODBCINST_INI); if (dllPath[0]) { @@ -88,21 +99,39 @@ DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) snprintf(message, sizeof(message), "libpq in neither %s nor %s%s could be loaded", PG_BIN, drive, dir); } } +#ifdef PG_BIN else snprintf(message, sizeof(message), "libpq in the folder %s couldn't be loaded", PG_BIN); +#endif /* PG_BIN */ if (message[0]) MessageBox(NULL, message, "psqlsetup", MB_OK); } - EnableDelayLoadHook(); -#endif + if (GetModuleFileName(s_hModule, dllPath, sizeof(dllPath)) <= 0) + { + MessageBox(NULL, "GetModuleFileName error", "psqlsetup", MB_OK); + return TRUE; + } + if (sptr = strrchr(dllPath, '\\'), NULL == sptr) + { + MessageBox(NULL, "strrchr error", "psqlsetup", MB_OK); + return FALSE; + } + strcpy_s(sptr + 1, MAX_PATH - (size_t)(sptr - dllPath), psqlodbcdll); + if (s_hLModule2 = LoadLibraryEx(dllPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH), s_hLModule2 == NULL) + { + MessageBox(NULL, dllPath, "psqlodbc load error", MB_OK); + return TRUE; + } break; case DLL_THREAD_ATTACH: break; case DLL_PROCESS_DETACH: - CleanupDelayLoadedDLLs(); - FreeLibrary(s_hLModule); + if (NULL != s_hLModule2) + FreeLibrary(s_hLModule2); + if (NULL != s_hLModule) + FreeLibrary(s_hLModule); finalize_global_cs(); return TRUE; |
