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

System-dependent library loading routines. More...

Classes

struct  SDL::SharedObject
 An opaque datatype that represents a loaded shared object. More...

Typedefs

using SDL::SharedObjectRaw = SDL_SharedObject*
 Alias to raw representation for SharedObject.
using SDL::SharedObjectRef = ResourceRef<SharedObject>
 Reference for SharedObject.

Functions

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

Detailed Description

System-dependent library loading routines.

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 LoadObject() 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:

  • These functions only work on 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.
  • Avoid namespace collisions. If you load a symbol from the library, it is not defined whether or not it goes into the global symbol namespace for the application. If it does and it conflicts with symbols in your code or other shared libraries, you will not get the results you expect. :)
  • Once a library is unloaded, all pointers into it obtained through SharedObject.LoadFunction() become invalid, even if the library is later reloaded. Don't unload a library if you plan to use these pointers in the future. Notably: beware of giving one of these pointers to atexit(), since it may call that pointer after the library unloads.

Typedef Documentation

◆ SharedObjectRef

Reference for SharedObject.

This does not take ownership!

Function Documentation

◆ LoadFunction() [1/2]

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

Look up the address of the named function in a shared object.

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 LoadObject().
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
LoadObject

◆ LoadFunction() [2/2]

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

Look up the address of the named function in a shared object.

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
LoadObject

◆ LoadObject()

SharedObject SDL::LoadObject ( StringParam sofile)
inline

Dynamically load a shared object.

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

◆ SharedObject()

SDL::SharedObject::SharedObject ( StringParam sofile)
inline

Dynamically load a shared object.

Parameters
sofilea system-dependent name of the object file.
Postcondition
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

Unload a shared object from memory.

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
LoadObject

◆ UnloadObject()

void SDL::UnloadObject ( SharedObjectRaw handle)
inline

Unload a shared object from memory.

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 LoadObject().
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.
See also
LoadObject