Esempio n. 1
0
RETCODE     SQL_API
PGAPI_AllocEnv(HENV FAR * phenv)
{
    CSTR func = "PGAPI_AllocEnv";
    SQLRETURN   ret = SQL_SUCCESS;

    mylog("**** in %s ** \n", func);

    /*
     * Hack for systems on which none of the constructor-making techniques
     * in hsqlodbc.c work: if globals appears not to have been
     * initialized, then cause it to be initialized.  Since this should be
     * the first function called in this shared library, doing it here
     * should work.
     */
    if (globals.socket_buffersize <= 0)
    {
        initialize_global_cs();
        getCommonDefaults(DBMS_NAME, ODBCINST_INI, NULL);
    }

    *phenv = (HENV) EN_Constructor();
    if (!*phenv)
    {
        *phenv = SQL_NULL_HENV;
        EN_log_error(func, "Error allocating environment", NULL);
        ret = SQL_ERROR;
    }

    mylog("** exit %s: phenv = %p **\n", func, *phenv);
    return ret;
}
Esempio n. 2
0
BOOL		WINAPI
DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
{
	switch (ul_reason_for_call)
	{
		case DLL_PROCESS_ATTACH:
			s_hModule = hInst;	/* Save for dialog boxes */

			if (initialize_global_cs() == 0)
				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)
			{
				char dllPath[MAX_PATH] = "", 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])
				{
					char drive[_MAX_DRIVE], dir[_MAX_DIR];

					_splitpath(dllPath, drive, dir, NULL, NULL);
					snprintf(dllPath, sizeof(dllPath), "%s%slibpq.dll", drive, dir);
					if (s_hLModule = LoadLibraryEx(dllPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH), s_hLModule == NULL)
					{
						mylog("libpq in the folder %s%s couldn't be loaded\n", drive, dir);
						snprintf(message, sizeof(message), "libpq in neither %s nor %s%s could be loaded", PG_BIN, drive, dir);
					}
				}
				else
					snprintf(message, sizeof(message),  "libpq in the folder %s couldn't be loaded", PG_BIN);
				if (message[0])
					MessageBox(NULL, message, "psqlsetup", MB_OK);
			}
			EnableDelayLoadHook();
#endif
			break;

		case DLL_THREAD_ATTACH:
			break;

		case DLL_PROCESS_DETACH:
			CleanupDelayLoadedDLLs();
			FreeLibrary(s_hLModule);
			finalize_global_cs();
			return TRUE;

		case DLL_THREAD_DETACH:
			break;

		default:
			break;
	}

	return TRUE;

	UNREFERENCED_PARAMETER(lpReserved);
}