summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--loadlib.c14
-rw-r--r--loadlib.h1
-rw-r--r--psqlsetup.c47
3 files changed, 38 insertions, 24 deletions
diff --git a/loadlib.c b/loadlib.c
index c597f81..50739f2 100644
--- a/loadlib.c
+++ b/loadlib.c
@@ -156,20 +156,6 @@ DliErrorHook(unsigned dliNotify,
return (FARPROC) hmodule;
}
-#if (_MSC_VER < 1300)
-void EnableDelayLoadHook()
-{
- __pfnDliFailureHook = DliErrorHook;
- __pfnDliNotifyHook = DliErrorHook;
-}
-#else
-void EnableDelayLoadHook()
-{
- __pfnDliFailureHook2 = DliErrorHook;
- __pfnDliNotifyHook2 = DliErrorHook;
-}
-#endif /* _MSC_VER */
-
/*
* unload delay loaded libraries.
*/
diff --git a/loadlib.h b/loadlib.h
index a76b65b..f78ae33 100644
--- a/loadlib.h
+++ b/loadlib.h
@@ -32,7 +32,6 @@ void CALL_ReleaseTransactionObject(void *);
#endif /* _HANDLE_ENLIST_IN_DTC_ */
/* void UnloadDelayLoadedDLLs(BOOL); */
void CleanupDelayLoadedDLLs(void);
-void EnableDelayLoadHook(void);
#ifdef __cplusplus
}
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;