#ifdef PG_BIN
-#include "loadlib.h"
-#include <DelayImp.h>
#include <stdio.h>
#include <string.h>
#include <sql.h>
#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;
#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:
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])
{
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;