// ////////////////////////////////////////////////////////////////////////////
std::string &OS_GetModuleFileName(HMODULE module_handle,
	std::string &module_name)
{
	char tmp_buffer[(MLB::Utility::MaxPathNameLength * 2) + 1];

	return(module_name.assign(OS_GetModuleFileName(module_handle, tmp_buffer,
		sizeof(tmp_buffer) - 1)));
}
Exemple #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;
}
// ////////////////////////////////////////////////////////////////////////////
std::string OS_GetModuleFileName(HMODULE module_handle)
{
	std::string module_name;

	return(OS_GetModuleFileName(module_handle, module_name));
}