SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
Classes | Typedefs | Functions
Shared Object/DLL Management

System-dependent library loading routines. More...

Collaboration diagram for Shared Object/DLL Management:

Classes

struct  SDL::SharedObjectParam
 Safely wrap SharedObject for non owning parameters. More...
 
class  SDL::SharedObject
 An opaque datatype that represents a loaded shared object. More...
 
struct  SDL::SharedObjectRef
 Semi-safe reference for SharedObject. More...
 

Typedefs

using SDL::SharedObjectRaw = SDL_SharedObject *
 Alias to raw representation for SharedObject.
 

Functions

SharedObject SDL::LoadObject (StringParam sofile)
 Dynamically load a shared object. More...
 
FunctionPointer SDL::LoadFunction (SharedObjectParam handle, StringParam name)
 Look up the address of the named function in a shared object. More...
 
void SDL::UnloadObject (SharedObjectRaw handle)
 Unload a shared object from memory. More...
 
FunctionPointer SDL::SharedObject::LoadFunction (StringParam name)
 Look up the address of the named function in a shared object. More...
 
void SDL::SharedObject::Unload ()
 Unload a shared object from memory. More...
 

Detailed Description

Shared objects are code that is programmatically loadable at runtime. Windows calls these "DLLs", Linux calls them "shared libraries", etc.

To use them, build such a library, then call SharedObject.SharedObject() on it. Once loaded, you can use SharedObject.LoadFunction() on that object to find the address of its exported symbols. When done with the object, call SharedObject.Unload() to dispose of it.

Some things to keep in mind:

Function Documentation

◆ LoadFunction() [1/2]

FunctionPointer SDL::LoadFunction ( SharedObjectParam  handle,
StringParam  name 
)
inline

This function pointer is no longer valid after calling SharedObject.Unload().

This function can only look up C function names. Other languages may have name mangling and intrinsic language support that varies from compiler to compiler.

Make sure you declare your function pointers with the same calling convention as the actual library function. Your code will crash mysteriously if you do not do this.

If the requested function doesn't exist, nullptr is returned.

Parameters
handlea valid shared object handle returned by SharedObject.SharedObject().
namethe name of the function to look up.
Returns
a pointer to the function or nullptr on failure; call GetError() for more information.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.
See also
SharedObject.SharedObject

◆ LoadFunction() [2/2]

FunctionPointer SDL::SharedObject::LoadFunction ( StringParam  name)
inline

This function pointer is no longer valid after calling SharedObject.Unload().

This function can only look up C function names. Other languages may have name mangling and intrinsic language support that varies from compiler to compiler.

Make sure you declare your function pointers with the same calling convention as the actual library function. Your code will crash mysteriously if you do not do this.

If the requested function doesn't exist, nullptr is returned.

Parameters
namethe name of the function to look up.
Returns
a pointer to the function or nullptr on failure; call GetError() for more information.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.
See also
SharedObject.SharedObject

◆ LoadObject()

SharedObject SDL::LoadObject ( StringParam  sofile)
inline
Parameters
sofilea system-dependent name of the object file.
Returns
an opaque pointer to the object handle or nullptr on failure; call GetError() for more information.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.
See also
SharedObject.LoadFunction
SharedObject.Unload

◆ Unload()

void SDL::SharedObject::Unload ( )
inline

Note that any pointers from this object looked up through SharedObject.LoadFunction() will no longer be valid.

Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.
See also
SharedObject.SharedObject

◆ UnloadObject()

void SDL::UnloadObject ( SharedObjectRaw  handle)
inline

Note that any pointers from this object looked up through SharedObject.LoadFunction() will no longer be valid.

Parameters
handlea valid shared object handle returned by SharedObject.SharedObject().
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.
See also
SharedObject.SharedObject