示例#1
0
HRESULT CLAVAudio::InitDTSDecoder()
{
  if (!m_hDllExtraDecoder) {
    // Add path of LAVAudio.ax into the Dll search path
    WCHAR wModuleFile[1024];
    GetModuleFileName(g_hInst, wModuleFile, 1024);
    PathRemoveFileSpecW(wModuleFile);
    wcscat_s(wModuleFile, TEXT("\\dtsdecoderdll.dll"));

    // Try loading from the filters directory
    HMODULE hDll = LoadLibraryEx(wModuleFile, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
    // And try from any global directories if this failed
    if (hDll == NULL) {
      hDll = LoadLibrary(TEXT("dtsdecoderdll.dll"));
    }
    CheckPointer(hDll, E_FAIL);

    m_hDllExtraDecoder = hDll;
  }

  DTSDecoder *context = new DTSDecoder();

  context->pDtsOpen = (DtsOpen)GetProcAddress(m_hDllExtraDecoder, "DtsApiDecOpen");
  if(!context->pDtsOpen) goto fail;

  context->pDtsClose = (DtsClose)GetProcAddress(m_hDllExtraDecoder, "DtsApiDecClose");
  if(!context->pDtsClose) goto fail;

  context->pDtsReset = (DtsReset)GetProcAddress(m_hDllExtraDecoder, "DtsApiDecReset");
  if(!context->pDtsReset) goto fail;

  context->pDtsSetParam = (DtsSetParam)GetProcAddress(m_hDllExtraDecoder, "DtsApiDecSetParam");
  if(!context->pDtsSetParam) goto fail;

  context->pDtsDecode = (DtsDecode)GetProcAddress(m_hDllExtraDecoder, "DtsApiDecodeData");
  if(!context->pDtsDecode) goto fail;

  context->dtsContext = context->pDtsOpen();
  if(!context->dtsContext) goto fail;

  context->dtsPCMBuffer = (BYTE *)av_mallocz(LAV_AUDIO_BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);

  m_DTSBitDepth = 24;
  m_DTSDecodeChannels = 8;

  m_pDTSDecoderContext = context;

  FlushDTSDecoder();

  return S_OK;
fail:
  SAFE_DELETE(context);
  FreeLibrary(m_hDllExtraDecoder);
  m_hDllExtraDecoder = NULL;
  return E_FAIL;
}
示例#2
0
bool ReadMPQFiles() {
	FILE *phil;
	phil = fopen("C:\\philtest.txt", "a+"); fprintf(phil, "phil reading files\n"); fclose(phil);
	int fileCount = 0;
	HMODULE hModule = GetModuleHandle("StormLib.dll");
	if (hModule) {
		phil = fopen("C:\\philtest.txt", "a+"); fprintf(phil, "phil dll already loaded\n"); fclose(phil);
	}
	//HMODULE dllHandle = LoadLibrary("StormLib.dll");
	HMODULE dllHandle = LoadLibraryEx("StormLib.dll", NULL, LOAD_IGNORE_CODE_AUTHZ_LEVEL);
	phil = fopen("C:\\philtest.txt", "a+"); fprintf(phil, "here with xhandle %d\n", (int)dllHandle); fclose(phil);
	if (dllHandle) {
		phil = fopen("C:\\philtest.txt", "a+"); fprintf(phil, "opened dll!\n"); fclose(phil);
		SFileOpenArchive = (MPQOpenArchive)GetProcAddress(dllHandle, "SFileOpenArchive");
		SFileCloseArchive = (MPQCloseArchive)GetProcAddress(dllHandle, "SFileCloseArchive");
		SFileOpenFileEx = (MPQOpenFile)GetProcAddress(dllHandle, "SFileOpenFileEx");
		SFileGetFileSize = (MPQGetSize)GetProcAddress(dllHandle, "SFileGetFileSize");
		SFileReadFile = (MPQReadFile)GetProcAddress(dllHandle, "SFileReadFile");
		SFileCloseFile = (MPQCloseFile)GetProcAddress(dllHandle, "SFileCloseFile");

		if (SFileOpenArchive && SFileCloseArchive && SFileOpenFileEx && SFileCloseFile && SFileGetFileSize && SFileReadFile) {
			HANDLE hMpq = NULL;
			MPQArchive archive("phil.mpq"); // phil fixme phil
			if (archive.error == ERROR_SUCCESS) {
				phil = fopen("C:\\philtest.txt", "a+"); fprintf(phil, "opened the archive\n"); fclose(phil);
				MPQFile armorFile(&archive, "Armor.txt");
				if (armorFile.error == ERROR_SUCCESS) {
					fileCount++;
					MpqDataMap["armor"] = new MPQData(&armorFile);
				}
				MPQFile weaponsFile(&archive, "Weapons.txt");
				if (weaponsFile.error == ERROR_SUCCESS) {
					fileCount++;
					MpqDataMap["weapons"] = new MPQData(&weaponsFile);
				}
				MPQFile miscFile(&archive, "Misc.txt");
				if (miscFile.error == ERROR_SUCCESS) {
					fileCount++;
					MpqDataMap["misc"] = new MPQData(&miscFile);
				}
				MPQFile itemTypesFile(&archive, "ItemTypes.txt");
				if (itemTypesFile.error == ERROR_SUCCESS) {
					fileCount++;
					MpqDataMap["itemtypes"] = new MPQData(&itemTypesFile);
				}
				phil = fopen("C:\\philtest.txt", "a+"); fprintf(phil, "file errors %d, %d, %d, %d\n", armorFile.error, weaponsFile.error, miscFile.error, itemTypesFile.error); fclose(phil);
			}
			phil = fopen("C:\\philtest.txt", "a+"); fprintf(phil, "archive error %d\n", archive.error); fclose(phil);
		}
		FreeLibrary(dllHandle);
	} else {
		phil = fopen("C:\\philtest.txt", "a+"); fprintf(phil, "couldn't open dll: %d\n", GetLastError()); fclose(phil);
	}
	phil = fopen("C:\\philtest.txt", "a+"); fprintf(phil, "file count is %d\n", fileCount); fclose(phil);
	return fileCount == 4;
}
示例#3
0
bool PluginLoader::getScyllaPluginName(Plugin * pluginData)
{
	bool retValue = false;
	char * pluginName = 0;
	def_ScyllaPluginNameW ScyllaPluginNameW = 0;
	def_ScyllaPluginNameA ScyllaPluginNameA = 0;

	HMODULE hModule = LoadLibraryEx(pluginData->fullpath, 0, DONT_RESOLVE_DLL_REFERENCES); //do not call DllMain

	if (hModule)
	{
		ScyllaPluginNameW = (def_ScyllaPluginNameW)GetProcAddress(hModule, "ScyllaPluginNameW");

		if (ScyllaPluginNameW)
		{
			wcscpy_s(pluginData->pluginName, ScyllaPluginNameW());

#ifdef DEBUG_COMMENTS
			Scylla::debugLog.log(L"getPluginName :: Plugin name %s", pluginData->pluginName);
#endif

			retValue = true;
		}
		else
		{
			ScyllaPluginNameA = (def_ScyllaPluginNameA)GetProcAddress(hModule, "ScyllaPluginNameA");

			if (ScyllaPluginNameA)
			{
				pluginName = ScyllaPluginNameA();

				StringConversion::ToUTF16(pluginName, pluginData->pluginName, _countof(pluginData->pluginName));

#ifdef DEBUG_COMMENTS
				Scylla::debugLog.log(L"getPluginName :: Plugin name mbstowcs_s %s", pluginData->pluginName);
#endif

				if (wcslen(pluginData->pluginName) > 1)
				{
					retValue = true;
				}
			}
		}

		FreeLibrary(hModule);

		return retValue;
	}
	else
	{
#ifdef DEBUG_COMMENTS
		Scylla::debugLog.log(L"getPluginName :: LoadLibraryEx failed %s", pluginData->fullpath);
#endif
		return false;
	}
}
示例#4
0
bool CUpdateUtil::RegisterOLE(CString pszDllName, CString pszDllEntryPoint)
{
	::CoInitialize(NULL);
	bool bReturn =  false;
	CString strTempFileName = pszDllName;
	strTempFileName.MakeLower();
	if(strTempFileName.Find(".exe") > 0)
	{
		strTempFileName += " /RegServer";
		ShellExecute(NULL, NULL, strTempFileName, NULL, NULL, SW_HIDE);
		bReturn = true;
	}
	else
	{
			
		// Load the library.
		HINSTANCE hLib = LoadLibraryEx(pszDllName, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
		if (hLib < (HINSTANCE)HINSTANCE_ERROR) {
			SetLastError(UPDATE_ERROR_DLL_LOAD_LIBRARY);
			TRACE("UPDATE_ERROR_DLL_LOAD_LIBRARY : %s\n", pszDllName);
			goto CleanupOle;
		}

		// Find the entry point.
		FARPROC lpDllEntryPoint;
		(FARPROC&)lpDllEntryPoint = GetProcAddress(hLib, pszDllEntryPoint);

		if (lpDllEntryPoint == NULL) {
			SetLastError(UPDATE_ERROR_DLL_GET_PROC_ADDRESS);
			TRACE("UPDATE_ERROR_DLL_GET_PROC_ADDRESS : %s\n", pszDllName);
			goto CleanupLibrary;
		}
		
		// Call the entry point.
		if (lpDllEntryPoint)
		{
			if(Error((*lpDllEntryPoint)()) )
					goto CleanupLibrary;
		}

		SetLastError(UPDATE_SUCCESS_REGSVR_DLL);
		TRACE("UPDATE_SUCCESS_REGSVR_DLL : %s\n", pszDllName);
		
		//Horray
		bReturn = true;

	CleanupLibrary:
			FreeLibrary(hLib);
	    
	CleanupOle:
		OleUninitialize();
	}
	::CoUninitialize();	

    return bReturn;
}
示例#5
0
	std::wstring render_message(const int truncate_message, DWORD dwLang = 0) const {
		std::vector<std::wstring> args;
		std::wstring ret;
		std::wstring file;
		if (!get_dll(file)) {
			return file;
		}
		strEx::splitList dlls = strEx::splitEx(file, _T(";"));
		for (strEx::splitList::const_iterator cit = dlls.begin(); cit != dlls.end(); ++cit) {
			//std::wstring msg = error::format::message::from_module((*cit), eventID(), _sz);
			std::wstring msg;
			try {
				HMODULE hDLL = LoadLibraryEx((*cit).c_str(), NULL, DONT_RESOLVE_DLL_REFERENCES);
				if (hDLL == NULL) {
					msg = _T("failed to load: ") + (*cit) + _T(", reason: ") + strEx::itos(GetLastError());
					continue;
				}
				if (dwLang == 0)
					dwLang = MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT);
				boost::tuple<DWORD,std::wstring> formated_data = safe_format(hDLL, dwLang);
				if (formated_data.get<0>() != 0) {
					FreeLibrary(hDLL);
					if (formated_data.get<0>() == 15100) {
						// Invalid MUI file (wrong language)
						msg = _T("");
						continue;
					}
					if (formated_data.get<0>() == 317) {
						// Missing message
						msg = _T("");
						continue;
					}
					msg = _T("failed to lookup error code: ") + strEx::itos(eventID()) + _T(" from DLL: ") + (*cit) + _T("( reason: ") + strEx::itos(formated_data.get<0>()) + _T(")");
					continue;
				}
				FreeLibrary(hDLL);
				msg = formated_data.get<1>();
			} catch (...) {
				msg = _T("Unknown exception getting message");
			}
			strEx::replace(msg, _T("\n"), _T(" "));
			strEx::replace(msg, _T("\t"), _T(" "));
			std::string::size_type pos = msg.find_last_not_of(_T("\n\t "));
			if (pos != std::string::npos) {
				msg = msg.substr(0,pos);
			}
			if (!msg.empty()) {
				if (!ret.empty())
					ret += _T(", ");
				ret += msg;
			}
		}
		if (truncate_message > 0 && ret.length() > truncate_message)
			ret = ret.substr(0, truncate_message);
		return ret;
	}
示例#6
0
BOOL CVersionInfo::LoadVersionInfoResource(const CString& strModulePath, CVersionInfoBuffer &viBuf, LPCTSTR lpszResourceId, WORD wLangId)
{
	HRSRC hResInfo; 

	HMODULE hModule = LoadLibraryEx(strModulePath, NULL, DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE);
	if (NULL == hModule)
		return FALSE;

	if ((NULL == lpszResourceId) && (wLangId == 0xFFFF))
	{
		//Load first RT_VERSION resource that will be found
		
		m_lpszResourceId = NULL;

		EnumResourceNames(hModule, RT_VERSION, (ENUMRESNAMEPROC)EnumResourceNamesFuncFindFirst, (LONG_PTR)this);
		
		if (NULL == m_lpszResourceId)
		{
			FreeLibrary(hModule);
			return FALSE;
		}
		
		// Now the m_lpszResourceId must be the name of the resource
		m_wLangId = 0xFFFF;
		EnumResourceLanguages(hModule, RT_VERSION, m_lpszResourceId, (ENUMRESLANGPROC)EnumResourceLangFuncFindFirst, (LONG_PTR)this);

		// Found resource, copy the ID's to local vars
		lpszResourceId = m_lpszResourceId;
		wLangId = m_wLangId;
	}

	hResInfo = FindResourceEx(hModule, RT_VERSION, lpszResourceId, wLangId); 
	// Write the resource language to the resource information file. 

	DWORD dwSize = SizeofResource(hModule, hResInfo);
	if (dwSize)
	{
		HGLOBAL hgRes = LoadResource(hModule, hResInfo);
		if (hgRes)
		{
			LPVOID lpMemory = LockResource(hgRes);
			if (lpMemory)
			{
				viBuf.Write(lpMemory,dwSize);
				
				UnlockResource(hgRes);
				FreeLibrary(hModule);
				return TRUE;
			}
		}
	}

	FreeLibrary(hModule);
	return FALSE;

}
示例#7
0
文件: Library.c 项目: jnr/jffi
static void*
dl_open(const char* name, int flags)
{
    if (name == NULL) {
        return GetModuleHandle(NULL);
    } else {
        DWORD dwFlags = PathIsRelative(name) ? 0 : LOAD_WITH_ALTERED_SEARCH_PATH;
        return LoadLibraryEx(name, NULL, dwFlags);
    }
}
示例#8
0
void * caml_dlopen(char * libname, int for_execution)
{
  HMODULE m;
  m = LoadLibraryEx(libname, NULL,
                    for_execution ? 0 : DONT_RESOLVE_DLL_REFERENCES);
  /* Under Win 95/98/ME, LoadLibraryEx can fail in cases where LoadLibrary
     would succeed.  Just try again with LoadLibrary for good measure. */
  if (m == NULL) m = LoadLibrary(libname);
  return (void *) m;
}
示例#9
0
WORD getMaxIconId(TCHAR* lpFileName)
{
	WORD nMaxID = 0;
	HINSTANCE hLib = LoadLibraryEx(lpFileName,NULL,DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE);
	if(hLib == NULL) { _tprintf(_T("Unable to load library '%s'\n"), lpFileName); return 0xFFFF; }
	// Enumerate icon "names" (IDs) to get next available ID
	if(!EnumResourceNames(hLib, RT_ICON, (ENUMRESNAMEPROC)getMaxIconId_EnumNamesFunc,(LONG_PTR)&nMaxID)) { _tprintf(_T("Unable to enum icons\n")); return 0xFFFF; }	
	FreeLibrary(hLib);
	IFDEBUG( _tprintf(_T("MaxIcon=%d\n"), nMaxID); )
	return nMaxID;
示例#10
0
void *
dlopen(const char* path, int mode __UNUSED__)
{
   HMODULE module = NULL;

   if (!path)
     {
        module = GetModuleHandle(NULL);
        if (!module)
          get_last_error("GetModuleHandle returned: ");
     }
   else
     {
        char        *new_path;
        size_t       l;
        unsigned int i;

        /* according to MSDN, we must change the slash to backslash */
        l = strlen(path);
        new_path = (char *)malloc(sizeof(char) * (l + 1));
        if (!new_path)
          {
             if (dl_err)
               free(dl_err);
             dl_err = strdup("not enough resource");
             dl_err_viewed = 0;
             return NULL;
          }
        for (i = 0; i <= l; i++)
          {
             if (path[i] == '/')
               new_path[i] = '\\';
             else
               new_path[i] = path[i];
          }
#ifdef UNICODE
        {
           wchar_t *wpath;

           wpath = evil_char_to_wchar(new_path);
           module = LoadLibrary(wpath);
           free(wpath);
        }
#else
        module = LoadLibraryEx(new_path, NULL,
                               LOAD_WITH_ALTERED_SEARCH_PATH);
#endif /* ! UNICODE */
        if (!module)
          get_last_error("LoadLibraryEx returned: ");

        free(new_path);
     }

   return module;
}
示例#11
0
// DLL reading for Win32
HINSTANCE Win32SecureLoadLibraryEx(char *dllname, DWORD flags)
{
	char tmp1[MAX_PATH];
	char tmp2[MAX_PATH];
	char tmp3[MAX_PATH];
	HINSTANCE h;
	// Validate arguments
	if (dllname == NULL)
	{
		return NULL;
	}

	Format(tmp1, sizeof(tmp1), "%s\\%s", MsGetSystem32Dir(), dllname);
	Format(tmp2, sizeof(tmp2), "%s\\JPKI\\%s", MsGetProgramFilesDir(), dllname);
	Format(tmp3, sizeof(tmp3), "%s\\LGWAN\\%s", MsGetProgramFilesDir(), dllname);

	h = LoadLibraryEx(dllname, NULL, flags);
	if (h != NULL)
	{
		return h;
	}

	h = LoadLibraryEx(tmp1, NULL, flags);
	if (h != NULL)
	{
		return h;
	}

	h = LoadLibraryEx(tmp2, NULL, flags);
	if (h != NULL)
	{
		return h;
	}

	h = LoadLibraryEx(tmp3, NULL, flags);
	if (h != NULL)
	{
		return h;
	}

	return NULL;
}
示例#12
0
文件: RegTool.c 项目: kichik/nsis-1
void RegDll(char *file)
{
    HMODULE mod = LoadLibraryEx(file, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
    if (mod)
    {
        FARPROC regfunc = GetProcAddress(mod, "DllRegisterServer");
        if (regfunc)
            regfunc();
        FreeLibrary(mod);
    }
}
示例#13
0
// wraps LoadLibraryEx() since 360 doesn't support that
static HMODULE InternalLoadLibrary( const char *pName, Sys_Flags flags )
{
#if defined(_X360)
	return LoadLibrary( pName );
#else
	if ( flags & SYS_NOLOAD )
		return GetModuleHandle( pName );
	else
		return LoadLibraryEx( pName, NULL, LOAD_WITH_ALTERED_SEARCH_PATH );
#endif
}
示例#14
0
// ----------------------------------------------------------------------------------
HMODULE loadLibraryEx(LPCTSTR lpFileName, HANDLE hFile, DWORD dwFlags)
{
	HMODULE hExe;
	hExe = LoadLibraryEx(TEXT(lpFileName), hFile, dwFlags);
	if (hExe == NULL)
		{
		QTextStream(stdout, QIODevice::WriteOnly) << "Could not load .exe " << lpFileName << "\n";
		return 0;
		}
	return hExe;
}
示例#15
0
HMODULE hbwapi_LoadLibrarySystem( LPCTSTR pFileName )
{
   TCHAR * pLibPath = hbwapi_FileNameAtSystemDir( pFileName );

   /* TODO: Replace flag with LOAD_LIBRARY_SEARCH_SYSTEM32 in the future [vszakats] */
   HMODULE h = LoadLibraryEx( pLibPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH );

   hb_xfree( pLibPath );

   return h;
}
Trans2QuikApi::Trans2QuikApi(const std::string& dll)
{
	m_handle = LoadLibraryEx(dll.c_str(), NULL, 0);
	if(!m_handle)
		throw std::runtime_error("Unable to load dll");

	LOAD_SYMBOL_2(TRANS2QUIK_CONNECT, 16);
	LOAD_SYMBOL_2(TRANS2QUIK_DISCONNECT, 12);
	LOAD_SYMBOL_2(TRANS2QUIK_IS_QUIK_CONNECTED, 12);
	LOAD_SYMBOL_2(TRANS2QUIK_IS_DLL_CONNECTED, 12);
	LOAD_SYMBOL_2(TRANS2QUIK_SEND_SYNC_TRANSACTION, 36);
	LOAD_SYMBOL_2(TRANS2QUIK_SEND_ASYNC_TRANSACTION, 16);
	LOAD_SYMBOL_2(TRANS2QUIK_SET_CONNECTION_STATUS_CALLBACK, 16);
	LOAD_SYMBOL_2(TRANS2QUIK_SET_TRANSACTIONS_REPLY_CALLBACK, 16);
	LOAD_SYMBOL_2(TRANS2QUIK_SUBSCRIBE_ORDERS, 8);
	LOAD_SYMBOL_2(TRANS2QUIK_SUBSCRIBE_TRADES, 8);
	LOAD_SYMBOL_2(TRANS2QUIK_START_ORDERS, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_START_TRADES, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_UNSUBSCRIBE_ORDERS, 0);
	LOAD_SYMBOL_2(TRANS2QUIK_UNSUBSCRIBE_TRADES, 0);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_DATE, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_SETTLE_DATE, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_TIME, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_IS_MARGINAL, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_ACCRUED_INT, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_YIELD, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_TS_COMMISSION, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_CLEARING_CENTER_COMMISSION, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_EXCHANGE_COMMISSION, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_TRADING_SYSTEM_COMMISSION, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_PRICE2, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_REPO_RATE, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_REPO_VALUE, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_REPO2_VALUE, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_ACCRUED_INT2, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_REPO_TERM, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_START_DISCOUNT, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_LOWER_DISCOUNT, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_UPPER_DISCOUNT, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_BLOCK_SECURITIES, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_DATE_TIME, 8);

	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_CURRENCY, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_SETTLE_CURRENCY, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_SETTLE_CODE, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_ACCOUNT, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_BROKERREF, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_CLIENT_CODE, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_USERID, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_FIRMID, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_PARTNER_FIRMID, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_EXCHANGE_CODE, 4);
	LOAD_SYMBOL_2(TRANS2QUIK_TRADE_STATION_ID, 4);
}
示例#17
0
文件: os.cpp 项目: embedthis/appweb-2
int Mpr::loadDll(char *path, char *fnName, void *arg, void **handlePtr)
{
	MprDllEntryProc	fn;
	char			localPath[MPR_MAX_FNAME], dir[MPR_MAX_FNAME];
    void			*handle;
	char			*cp;
	int				rc;

	mprAssert(path && *path);
	mprAssert(fnName && *fnName);

	mprGetDirName(dir, sizeof(dir), path);
	mprSetModuleSearchPath(dir);

	mprStrcpy(localPath, sizeof(localPath), path);
	//	TODO - good to have a x-platform method for this.
	for (cp = localPath; *cp; cp++) {
		if (*cp == '/') {
			*cp = '\\';
		}
	}

    if ((handle = GetModuleHandle(mprGetBaseName(localPath))) == 0) {
		if ((handle = LoadLibraryEx(localPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH)) == 0) {
			char cwd[1024], *env;
			getcwd(cwd, sizeof(cwd) - 1);
			env = getenv("PATH");
			mprLog(0, "ERROR %d\n", GetLastError());
			mprLog(0, "Can't load %s\nReason: \"%d\"\n", path, mprGetOsError());
			mprLog(0, "CWD %s\n PATH %s\n", cwd, env);
			return MPR_ERR_CANT_OPEN;
		}
    }

	fn = (MprDllEntryProc) GetProcAddress((HINSTANCE) handle, fnName);
	if (fn == 0) {
		FreeLibrary((HINSTANCE) handle);
		mprLog(0, "Can't load %s\nReason: can't find function \"%s\"\n", 
			localPath, fnName);
		return MPR_ERR_NOT_FOUND;
	}
	mprLog(MPR_INFO, "Loading DLL %s\n", path);

	if ((rc = (fn)(arg)) < 0) {
		FreeLibrary((HINSTANCE) handle);
		mprError(MPR_L, MPR_LOG, "Initialization for %s failed.", path);
		return MPR_ERR_CANT_INITIALIZE;
	}
	if (handlePtr) {
		*handlePtr = handle;
	}
	return rc;
}
示例#18
0
void
print_last_error_message()
{
	DWORD dwError = GetLastError();

	HMODULE hModule = LoadLibraryEx(
		_T("ndasmsg.dll"),
		NULL,
		LOAD_LIBRARY_AS_DATAFILE);

	LPTSTR lpszErrorMessage = NULL;

	if (dwError & APPLICATION_ERROR_MASK) 
	{
		if (NULL != hModule) 
		{
			INT iChars = FormatMessage(
				FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE,
				hModule,
				dwError,
				0,
				(LPTSTR) &lpszErrorMessage,
				0,
				NULL);
			iChars;
		}
	}
	else
	{
		INT iChars = FormatMessage(
			FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
			NULL,
			dwError,
			0,
			(LPTSTR) &lpszErrorMessage,
			0,
			NULL);
		iChars;
	}

	if (NULL != lpszErrorMessage) 
	{
		_tprintf(_T("Error : %d(%08x) : %s\n"), dwError, dwError, lpszErrorMessage);
		LocalFree(lpszErrorMessage);
	}
	else
	{
		_tprintf(_T("Unknown error : %d(%08x)\n"), dwError, dwError);
	}

	/* refresh error */
	SetLastError(dwError);
}
示例#19
0
/*
 * Load DLL file just once regardless of how many functions
 * we load/call in it.
 */
static void
LoadKernel32()
{
	if (kernel32 != NULL)
		return;

	kernel32 = LoadLibraryEx("kernel32.dll", NULL, 0);
	if (kernel32 == NULL)
		ereport(FATAL,
			  (errmsg_internal("could not load kernel32.dll: error code %lu",
							   GetLastError())));
}
FARPROC WINAPI delayHookNotifyFunc (unsigned dliNotify, PDelayLoadInfo pdli)
{
  switch (dliNotify)
  {
    case dliNotePreLoadLibrary:
     if (stricmp(pdli->szDll, "libmicrohttpd-5.dll") == 0)
     {
       CStdString strDll = CSpecialProtocol::TranslatePath(DLL_PATH_LIBMICROHTTP);
       HMODULE hMod = LoadLibraryEx(strDll.c_str(), 0, LOAD_WITH_ALTERED_SEARCH_PATH);
       return (FARPROC)hMod;
     }
     if (stricmp(pdli->szDll, "libssh.dll") == 0)
     {
       CStdString strDll = CSpecialProtocol::TranslatePath("special://xbmcbin/system/libssh.dll");
       HMODULE hMod = LoadLibraryEx(strDll.c_str(), 0, LOAD_WITH_ALTERED_SEARCH_PATH);
       return (FARPROC)hMod;
     }
     break;
  }
  return NULL;
}
示例#21
0
// Get the provider DLL that contains the string resources for the
// category strings, event message strings, and parameter insert strings.
// For this example, the path to the DLL is hardcoded but typically,
// you would read the CategoryMessageFile, EventMessageFile, and 
// ParameterMessageFile registry values under the source's registry key located 
// under \SYSTEM\CurrentControlSet\Services\Eventlog\Application in
// the HKLM registry hive. In this example, all resources are included in
// the same resource-only DLL.
static HMODULE GetMessageResources(const TCHAR* resourcedll)
{
	HMODULE hResources = NULL;

	hResources = LoadLibraryEx(resourcedll, NULL, /*LOAD_LIBRARY_AS_IMAGE_RESOURCE | */LOAD_LIBRARY_AS_DATAFILE);
	if (NULL == hResources)
	{
		wprintf(L"LoadLibrary failed with %lu.\n", GetLastError());
	}

	return hResources;
}
示例#22
0
const char* CCONV _RA_InstallIntegration()
{
	SetErrorMode( 0 );
	
#ifdef _DEBUG
	g_hRADLL = LoadLibraryEx( TEXT( "RA_Integration_d.dll" ), nullptr, 0 );
#else
	g_hRADLL = LoadLibrary( TEXT( "RA_Integration.dll" ) );
#endif
	if( g_hRADLL == NULL )
	{
		char buffer[ 1024 ];
		sprintf_s( buffer, 1024, "LoadLibrary failed: %d : %s\n", ::GetLastError(), GetLastErrorAsString().c_str() );
		MessageBoxA( nullptr, buffer, "Sorry!", MB_OK );

		return "0.000";
	}

	//	Install function pointers one by one
 
	_RA_IntegrationVersion	= (const char*(CCONV *)())								GetProcAddress( g_hRADLL, "_RA_IntegrationVersion" );
	_RA_InitI				= (int(CCONV *)(HWND, int, const char*))				GetProcAddress( g_hRADLL, "_RA_InitI" );
	_RA_Shutdown			= (int(CCONV *)())										GetProcAddress( g_hRADLL, "_RA_Shutdown" );
	_RA_UserLoggedIn		= (bool(CCONV *)())										GetProcAddress( g_hRADLL, "_RA_UserLoggedIn" );
	_RA_Username			= (const char*(CCONV *)())								GetProcAddress( g_hRADLL, "_RA_Username" );
	_RA_AttemptLogin		= (void(CCONV *)(bool))									GetProcAddress( g_hRADLL, "_RA_AttemptLogin" );
	_RA_UpdateOverlay		= (int(CCONV *)(ControllerInput*, float, bool, bool))	GetProcAddress( g_hRADLL, "_RA_UpdateOverlay" );
	_RA_UpdatePopups		= (int(CCONV *)(ControllerInput*, float, bool, bool))	GetProcAddress( g_hRADLL, "_RA_UpdatePopups" );
	_RA_RenderOverlay		= (void(CCONV *)(HDC, RECT*))							GetProcAddress( g_hRADLL, "_RA_RenderOverlay" );
	_RA_RenderPopups		= (void(CCONV *)(HDC, RECT*))							GetProcAddress( g_hRADLL, "_RA_RenderPopups" );
	_RA_OnLoadNewRom		= (int(CCONV *)(const BYTE*, unsigned int))				GetProcAddress( g_hRADLL, "_RA_OnLoadNewRom" );
	_RA_InstallMemoryBank	= (void(CCONV *)(int, void*, void*, int))				GetProcAddress( g_hRADLL, "_RA_InstallMemoryBank" );
	_RA_ClearMemoryBanks	= (void(CCONV *)())										GetProcAddress( g_hRADLL, "_RA_ClearMemoryBanks" );
	_RA_UpdateAppTitle		= (void(CCONV *)(const char*))							GetProcAddress( g_hRADLL, "_RA_UpdateAppTitle" );
	_RA_HandleHTTPResults	= (void(CCONV *)())										GetProcAddress( g_hRADLL, "_RA_HandleHTTPResults" );
	_RA_ConfirmLoadNewRom	= (bool(CCONV *)(bool))									GetProcAddress( g_hRADLL, "_RA_ConfirmLoadNewRom" );
	_RA_CreatePopupMenu		= (HMENU(CCONV *)(void))								GetProcAddress( g_hRADLL, "_RA_CreatePopupMenu" );
	_RA_InitDirectX			= (void(CCONV *)(void))									GetProcAddress( g_hRADLL, "_RA_InitDirectX" );
	_RA_OnPaint				= (void(CCONV *)(HWND))									GetProcAddress( g_hRADLL, "_RA_OnPaint" );
	_RA_InvokeDialog		= (void(CCONV *)(LPARAM))								GetProcAddress( g_hRADLL, "_RA_InvokeDialog" );
	_RA_SetPaused			= (void(CCONV *)(bool))									GetProcAddress( g_hRADLL, "_RA_SetPaused" );
	_RA_OnLoadState			= (void(CCONV *)(const char*))							GetProcAddress( g_hRADLL, "_RA_OnLoadState" );
	_RA_OnSaveState			= (void(CCONV *)(const char*))							GetProcAddress( g_hRADLL, "_RA_OnSaveState" );
	_RA_DoAchievementsFrame = (void(CCONV *)())										GetProcAddress( g_hRADLL, "_RA_DoAchievementsFrame" );
	_RA_SetConsoleID		= (int(CCONV *)(unsigned int))							GetProcAddress( g_hRADLL, "_RA_SetConsoleID" );
	_RA_HardcoreModeIsActive= (int(CCONV *)())										GetProcAddress( g_hRADLL, "_RA_HardcoreModeIsActive" );
	_RA_HTTPGetRequestExists= (int(CCONV *)(const char*))							GetProcAddress( g_hRADLL, "_RA_HTTPGetRequestExists" );

	_RA_InstallSharedFunctions = ( void(CCONV *)( bool(*)(), void(*)(), void(*)(), void(*)(), void(*)(char*), void(*)(), void(*)(const char*) ) ) GetProcAddress( g_hRADLL, "_RA_InstallSharedFunctionsExt" );

	return _RA_IntegrationVersion ? _RA_IntegrationVersion() : "0.000";
}
示例#23
0
	/*-------------------------------------------------------------------------
	*  WindowsError
	*  
	*--------------------------------------------------------------------------*/
	int WindowsError(int errorCode, char *errorText){
		HMODULE hModule = NULL; // default to system source
		LPSTR MessageBuffer;
		DWORD dwBufferLength;
		DWORD dwLastError=(DWORD)errorCode;

		DWORD dwFormatFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER |FORMAT_MESSAGE_IGNORE_INSERTS |FORMAT_MESSAGE_FROM_SYSTEM;

		// If dwLastError is in the network range, load the message source.

		if(dwLastError >= NERR_BASE && dwLastError <= MAX_NERR) {
			DEBUGPARSE(Message,"Loading netmsg.dll");
			hModule = LoadLibraryEx(TEXT("netmsg.dll"),NULL,LOAD_LIBRARY_AS_DATAFILE);
			if(hModule != NULL)
				dwFormatFlags |= FORMAT_MESSAGE_FROM_HMODULE;
		}

		// Call FormatMessage() to allow for message 
		//  text to be acquired from the system 
		//  or from the supplied module handle.

		DEBUGPARSE(Message,"Precall FormatMessageA.");
		if(dwBufferLength = FormatMessageA(dwFormatFlags,hModule, dwLastError,MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),(LPSTR) &MessageBuffer,0,NULL)){
			DEBUGPARSE(Message,"Identified dwBufferLength:%d",dwBufferLength);
			strncpy_s(errorText,250,MessageBuffer,249);
			DEBUGPARSE(Message,"Copy done.");
			//Remove last cr-return
			if (errorText[strlen(errorText)-2]==(char)13) {
				errorText[strlen(errorText)-2]=(char)0;
			}
			DEBUGPARSE(Message,"CRLF Padding cleared.");

			if (dwBufferLength>250) {
				DEBUGPARSE(Message,"Adding dots to long message.");
				strcat_s(errorText,5,"...");
				DEBUGPARSE(Message,"done adding dots to long message.");
			}
			// Free the buffer allocated by the system.
			LocalFree(MessageBuffer);
			DEBUGPARSE(Message,"Free MessageBuffer done.");
			return dwBufferLength;
		} else {
			DEBUGPARSE(Message,"Else: Identified dwBufferLength:%d",dwBufferLength);
		}

		//
		// If we loaded a message source, unload it.
		//
		if(hModule != NULL)
			FreeLibrary(hModule);
		return dwBufferLength;
	}
示例#24
0
文件: DllLibrary.cpp 项目: ifzz/FDK
CDllLibrary::CDllLibrary(const tstring& path)
    : m_module()
    , m_getProtocolType()
    , m_createConnection()
{
    SetErrorMode(SEM_FAILCRITICALERRORS);
    m_module = LoadLibraryEx(path.c_str(), nullptr, LOAD_WITH_ALTERED_SEARCH_PATH);
    if (nullptr != m_module)
    {
        m_getProtocolType = reinterpret_cast<GetProtocolTypeFunc>(GetProcAddress(m_module, cGetProtocolTypeName));
        m_createConnection = reinterpret_cast<CreateConnectionFunc>(GetProcAddress(m_module, cCreateConnectionName));
    }
}
示例#25
0
// This function get the function to do GAP Tessellation from
// tessint.dll.  This is required because of the link order between
// core.dll and tessint.dll and gmi.dll.  -- Charlie Thaeler
static void
GetGTessFunction()
{
    if (psGTessFunc)
        return;
    // Get the library handle for tessint.dll
    HINSTANCE hInst = NULL;
	hInst = LoadLibraryEx(_T("tessint.dll"), NULL, 0);
    assert(hInst);

    psGTessFunc = (GTess)GetProcAddress(hInst, _T("GapTessellate"));
	assert(psGTessFunc);
}
示例#26
0
int CallApplicationMain(const wchar_t* moduleName, const char* functionName, CALL_APPLICATION_MAIN_DATA* data, dnx::trace_writer& trace_writer)
{
    HMODULE hostModule = nullptr;
    try
    {
        const auto runtime_new_path = get_runtime_path(trace_writer);
        if (runtime_new_path.length() > 0)
        {
            trace_writer.write(std::wstring(L"Redirecting runtime to: ").append(runtime_new_path), true);
            SetEnvironmentVariable(_T("DNX_DEFAULT_LIB"), runtime_new_path.c_str());

            #if defined(CORECLR_WIN)
                SetEnvironmentVariable(_T("CORECLR_DIR"), runtime_new_path.c_str());
                data->runtimeDirectory = runtime_new_path.c_str();
            #endif
        }

        auto module_path = dnx::utils::path_combine(runtime_new_path, moduleName);
        hostModule = LoadLibraryEx(module_path.c_str(), NULL, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
        if (!hostModule)
        {
            throw std::runtime_error(std::string("Failed to load: ")
                .append(dnx::utils::to_string(moduleName)));
        }

        trace_writer.write(std::wstring(L"Loaded module: ").append(module_path), true);

        auto pfnCallApplicationMain = reinterpret_cast<FnCallApplicationMain>(GetProcAddress(hostModule, functionName));
        if (!pfnCallApplicationMain)
        {
            std::ostringstream oss;
            oss << "Failed to find export '" << functionName << "' in " << dnx::utils::to_string(moduleName);
            throw std::runtime_error(oss.str());
        }

        trace_writer.write(std::wstring(L"Found export: ").append(dnx::utils::to_wstring(functionName)), true);

        HRESULT hr = pfnCallApplicationMain(data);
        FreeLibrary(hostModule);
        return SUCCEEDED(hr) ? data->exitcode : hr;
    }
    catch (...)
    {
        if (hostModule)
        {
            FreeLibrary(hostModule);
        }

        throw;
    }
}
示例#27
0
CStdString ElementRatings::GetXMLStreamFromResource(LPTSTR lpResource, const CStdString& sResourceType)
{
	try
	{

		HGLOBAL hResourceLoaded;
		HRSRC   hRes;
		char    *lpResLock;
		DWORD   dwSizeRes;

		HMODULE hMod = LoadLibraryEx(GetModulePathForXMLResources().c_str(), 0, LOAD_LIBRARY_AS_DATAFILE);
		if (NULL == hMod)
			ThrowException(_T("Unable to load dll for XML resources"),-1);

		hRes = FindResource(hMod, lpResource, sResourceType.c_str());
		if (NULL == hRes)
		{
			FreeLibrary(hMod);
			ThrowException(_T("Unable to find the requested resource"),-1);
		}

		hResourceLoaded = LoadResource(hMod, hRes);
		if (NULL == hResourceLoaded)
		{
			FreeLibrary(hMod);
			ThrowException(_T("Unable to load the requested resource"),-1);
		}

		lpResLock = (char *) LockResource(hResourceLoaded);
		if (NULL == lpResLock)
		{
			FreeLibrary(hMod);
			ThrowException(_T("Unable to lock the requested resource"),-1);
		}

		dwSizeRes = SizeofResource(hMod, hRes);

		USES_CONVERSION;
		CStdString s(lpResLock);
		s.resize(dwSizeRes);

		FreeResource(hResourceLoaded);
		FreeLibrary(hMod);
		return s;
	}
	catch (Workshare::Exception const& e)
	{
		LOG_WS_ERROR(CStdString(e.ErrorMessage).c_str());
	}
	return _T("");
}
示例#28
0
/*
* exceptWriteDump
*
* Purpose:
*
* Writes minidump information to the specified file.
*
*/
BOOL exceptWriteDump(
	EXCEPTION_POINTERS *ExceptionPointers,
	ULONGLONG IdFile
	)
{
	BOOL bResult;
	HANDLE hDbgHelp, hFile;
	DWORD dwRetVal;
	MINIDUMP_EXCEPTION_INFORMATION mdei;
	WCHAR szTemp[MAX_PATH * 2];

	bResult = FALSE;
	hDbgHelp = GetModuleHandle(L"dbghelp.dll");
	if (hDbgHelp == NULL) {
		RtlSecureZeroMemory(szTemp, sizeof(szTemp));
		if (!GetSystemDirectory(szTemp, MAX_PATH)) {
			return bResult;
		}
		_strcat(szTemp, L"\\dbghelp.dll");

		hDbgHelp = LoadLibraryEx(szTemp, 0, 0);
		if (hDbgHelp == NULL) {
			return bResult;
		}
	}

	pMiniDumpWriteDump = (pfnMiniDumpWriteDump)GetProcAddress(hDbgHelp, "MiniDumpWriteDump");
	if (pMiniDumpWriteDump == NULL) {
		return bResult;
	}

	RtlSecureZeroMemory(szTemp, sizeof(szTemp));
	dwRetVal = GetTempPath(MAX_PATH, szTemp);
	if (dwRetVal > MAX_PATH || (dwRetVal == 0)) {
		return bResult;
	}
	_strcat(szTemp, L"wobjex");
	u64tostr(IdFile, _strend(szTemp));
	_strcat(szTemp, L".dmp");

	hFile = CreateFile(szTemp, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
	if (hFile != INVALID_HANDLE_VALUE) {
		mdei.ThreadId = GetCurrentThreadId();
		mdei.ExceptionPointers = ExceptionPointers;
		mdei.ClientPointers = FALSE;
		bResult = pMiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &mdei, NULL, NULL);
		CloseHandle(hFile);
	}
	return bResult;
}
示例#29
0
Bool
winGetDDProcAddresses ()
{
  Bool			fReturn = TRUE;
  
  /* Load the DirectDraw library */
  g_hmodDirectDraw = LoadLibraryEx ("ddraw.dll", NULL, 0);
  if (g_hmodDirectDraw == NULL)
    {
      ErrorF ("winGetDDProcAddresses - Could not load ddraw.dll\n");
      fReturn = TRUE;
      goto winGetDDProcAddresses_Exit;
    }

  /* Try to get the DirectDrawCreate address */
  g_fpDirectDrawCreate = GetProcAddress (g_hmodDirectDraw,
					 "DirectDrawCreate");
  if (g_fpDirectDrawCreate == NULL)
    {
      ErrorF ("winGetDDProcAddresses - Could not get DirectDrawCreate "
	      "address\n");
      fReturn = TRUE;
      goto winGetDDProcAddresses_Exit;
    }

  /* Try to get the DirectDrawCreateClipper address */
  g_fpDirectDrawCreateClipper = GetProcAddress (g_hmodDirectDraw,
						"DirectDrawCreateClipper");
  if (g_fpDirectDrawCreateClipper == NULL)
    {
      ErrorF ("winGetDDProcAddresses - Could not get "
	      "DirectDrawCreateClipper address\n");
      fReturn = FALSE;
      goto winGetDDProcAddresses_Exit;
    }

  /*
   * Note: Do not unload ddraw.dll here.  Do it in GiveUp
   */

 winGetDDProcAddresses_Exit:
  /* Unload the DirectDraw library if we failed to initialize */
  if (!fReturn && g_hmodDirectDraw != NULL)
    {
      FreeLibrary (g_hmodDirectDraw);
      g_hmodDirectDraw = NULL;
    }
  
  return fReturn;
}
示例#30
0
	D3DCompiler()
	{
		mod_d3dcompiler_ = LoadLibraryEx(TEXT("d3dcompiler_47.dll"), NULL, 0);
		if (mod_d3dcompiler_)
		{
			DynamicD3DCompile_ = reinterpret_cast<D3DCompileFunc>(GetProcAddress(mod_d3dcompiler_, "D3DCompile"));
			DynamicD3DReflect_ = reinterpret_cast<D3DReflectFunc>(GetProcAddress(mod_d3dcompiler_, "D3DReflect"));
			DynamicD3DStripShader_ = reinterpret_cast<D3DStripShaderFunc>(GetProcAddress(mod_d3dcompiler_, "D3DStripShader"));
		}
		else
		{
			MessageBoxW(NULL, L"Can't load d3dcompiler_47.dll", L"Error", MB_OK);
		}
	}