Final Platform Layer  0.9.6-beta
Using Dynamic Libraries

FPL has built-in support for loading dynamic libraries (.dll/.so).

Loading a dynamic library

To load a dynamic library, such as .dll or .so you simply call fplDynamicLibraryLoad() with the name of the library or the full path.

if (fplDynamicLibraryLoad("mylibrary.dll", &libHandle)) {
// ... using the library
// Unload it when you are done
}
Note
Call fplDynamicLibraryUnload() to unload a loaded library when you are done.

Getting a procedure address

To get a procedure address from a function inside a library, simply call fplGetDynamicLibraryProc() .

typedef int(fn_LengthSquared)(int a, int b);
if (fplDynamicLibraryLoad("mymathy.dll", &libHandle)) {
// Get "LengthSquared" raw procedure address
void *lenSqFuncRaw = fplGetDynamicLibraryProc(&libHandle, "LengthSquared");
// Get "LengthSquared" casted procedure address
fn_LengthSquared *lenSqFunc = (fn_LengthSquared *)fplGetDynamicLibraryProc(&libHandle, "LengthSquared");
// Use the procedure like any function pointer
int len = lenSqFunc(3, 6);
// Unload it when you are done
}
fplDynamicLibraryLoad
fpl_platform_api bool fplDynamicLibraryLoad(const char *libraryFilePath, fplDynamicLibraryHandle *outHandle)
Loads a dynamic library and returns if the load was successful or not.
fplDynamicLibraryUnload
fpl_platform_api void fplDynamicLibraryUnload(fplDynamicLibraryHandle *handle)
Unloads the loaded library and resets the handle to zero.
fplDynamicLibraryHandle
A structure containing the internal handle to a dynamic library.
Definition: final_platform_layer.h:4220
fplGetDynamicLibraryProc
fpl_platform_api void * fplGetDynamicLibraryProc(const fplDynamicLibraryHandle *handle, const char *name)
Returns the dynamic library procedure address for the given procedure name.