Skip to content

shared_library load

Alairion edited this page May 8, 2021 · 8 revisions

Functions

    template<typename Func, typename = std::enable_if_t<std::is_pointer_v<Func> && std::is_function_v<std::remove_pointer_t<Func>>>>
(1) Func load(const std::string& symbol) const noexcept;
    template<typename Func, typename = std::enable_if_t<std::is_function_v<Func>>>
(2) Func* load(const std::string& symbol) const noexcept;
  1. Load a function within the binary. This function returns a pointer to the specified function, or nullptr if the function can not be found.
  2. Calls load<Func*>(symbol).

Parameters

Name Description
symbol The symbol name, i.e. the function name

Return value

  1. Return a function pointer, of type Func, on the requested function, on if it can be found. Otherwise, return nullptr.
  2. Return a function pointer, of type Func*, on the requested function, on if it can be found. Otherwise, return nullptr.

Preconditions

*this must represents a valid binary.
symbol must not be an empty string.

  1. Resolves only if Func is a function pointer.
  2. Resolves only if Func is a function.

Complexity

Constant.

Exceptions

Does not throw.

Implementation details

  1. On Windows, the symbol is loaded using GetProcAddress
    On Posix systems, the symbol is loaded using dlsym
  2. This function is just a wrapper around the first one

Clone this wiki locally