Esempio n. 1
0
// ////////////////////////////////////////////////////////////////////////////
bool LocateDllPredicate::IsMatchingDllInternal(const std::string &full_name)
{
	MLB::Utility::VersionNumber this_version;

	DetermineProductVersion(full_name).swap(this_version);

	candidate_list_.push_back(DllMatchItem(full_name, this_version));
	matched_list_.push_back(DllMatchItem(full_name, this_version));

	if (matched_list_.size() == 1)
		best_match_ = matched_list_.front();

	return(true);
}
Esempio n. 2
0
// ////////////////////////////////////////////////////////////////////////////
void DllLoader::LoadDll()
{
	if (IsLoaded())
		return;

	HMODULE                     this_handle;
	MLB::Utility::VersionNumber this_version;

	if ((this_handle = OS_GetModuleHandle(dll_name_, false)) != NULL) {
		if (!(dll_load_flags_ & PassIfAlreadyLoaded))
			MLB::Utility::ThrowException("Unable to load dll '" + dll_name_ +
				"' because it is already loaded into this process's address "
				"space.");
		try {
			std::string                 tmp_name(OS_GetModuleFileName(this_handle));
			MLB::Utility::VersionNumber tmp_version(
				DetermineProductVersion(tmp_name));
			this_version = tmp_version;
			if (!dll_predicate_ptr_->IsVersionMatch(tmp_name))
				MLB::Utility::ThrowException("The matching predicate reports that "
					"the loaded dll (product version " + tmp_version.ToString() +
					") is not compatible (" +
					dll_predicate_ptr_->DescribePredicate() + ").");
		}
		catch (const std::exception &except) {
			MLB::Utility::Rethrow(except, "Unable to load dll '" + dll_name_ +
				"' which is already loaded into this process's address space: " +
				std::string(except.what()));
		}
	}
	else if ((this_handle = ResolveAndLoadDll(dll_name_, *dll_predicate_ptr_,
		dll_full_name_)) == NULL)
		MLB::Utility::ThrowException("Unable to load dll '" + dll_name_ +
			"' because it could not be located (a total of " +
			MLB::Utility::AnyToString(dll_predicate_ptr_->candidate_list_.size()) +
			" potential candidate(s) were found, with the highest version number "
			"being " + dll_predicate_ptr_->GetBestMatchVersion().ToString() +
			").");
	else
		this_version = dll_predicate_ptr_->GetBestMatchVersion();

	dll_handle_  = this_handle;
	dll_version_ = this_version;
}