10#include "../../stdafx.h"
14#include "../../library_loader.h"
15#include "../../3rdparty/fmt/format.h"
17#include "../../safeguards.h"
19static std::string GetLoadError()
21 auto error_code = GetLastError();
24 if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr, error_code,
25 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer,
static_cast<DWORD
>(std::size(buffer)),
nullptr) == 0) {
26 return fmt::format(
"Unknown error {}", error_code);
34 void *h = ::LoadLibraryW(
OTTD2FS(filename).c_str());
36 this->
error = GetLoadError();
53 void *p =
reinterpret_cast<void *
>(::GetProcAddress(
handle, symbol_name.c_str()));
55 this->
error = GetLoadError();
std::optional< std::string > error
The last error that occurred, if set.
void * OpenLibrary(const std::string &filename)
Open the library with the given filename.
void * handle
Handle to the library.
void * GetSymbol(const std::string &symbol_name)
Get a symbol from the library.
void CloseLibrary()
Close the library.
std::wstring OTTD2FS(const std::string &name)
Convert from OpenTTD's encoding to a wide string.
std::string FS2OTTD(const std::wstring &name)
Convert to OpenTTD's encoding from a wide string.