Skip to content

shared_library

Alairion edited this page May 8, 2021 · 7 revisions

nes::shared_library

Defined in header <nes/shared_library.hpp>

class shared_library;

Description

nes::shared_library represents a shared library object. It is a wrapper around system-specific functions used to load binaries and get addresses of functions contained within them.

nes::shared_library can load other binaries, such as shared libraries, and also the calling binary. Once loaded, you can use the load function to get addresses of functions you need.

Member types

Type Description
native_handle_type The underlying, implementation-defined, representation of a shared library

Public Member functions

Function Description
shared_library Constructs the shared library object
~shared_library Destroys the shared library object
operator= Assigns a new handle to the shared library object
load Returns a pointer to a function within the shared library
native_handle Returns the underlying, implementation-defined, representation of a shared library

Example

This example show how to load a shared library. In this one the loaded library is Vulkan.

#include <nes/shared_library.hpp>
#include <vulkan.h>

//Paths are still platform specific
#if defined(VK_USE_PLATFORM_WIN32_KHR) //Windows
constexpr const char* vulkan_path = "vulkan-1.dll";
#elif defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR) //Linux
constexpr const char* vulkan_path = "libvulkan.so";
#endif

int main()
{
    //Load the library
    nes::shared_library vulkan_loader{vulkan_path};

    //Get the address of "vkGetInstanceProcAddr" function
    auto vk_get_instance_proc_addr{vulkan_loader.load<PFN_vkGetInstanceProcAddr>("vkGetInstanceProcAddr")};
    if(vulkan_get_instance_proc_addr)
    {
        //Do something with the function you loaded
    }
}
Clone this wiki locally