Path: blob/master/thirdparty/sdl/include/SDL3/SDL_loadso.h
9912 views
/*1Simple DirectMedia Layer2Copyright (C) 1997-2025 Sam Lantinga <[email protected]>34This software is provided 'as-is', without any express or implied5warranty. In no event will the authors be held liable for any damages6arising from the use of this software.78Permission is granted to anyone to use this software for any purpose,9including commercial applications, and to alter it and redistribute it10freely, subject to the following restrictions:11121. The origin of this software must not be misrepresented; you must not13claim that you wrote the original software. If you use this software14in a product, an acknowledgment in the product documentation would be15appreciated but is not required.162. Altered source versions must be plainly marked as such, and must not be17misrepresented as being the original software.183. This notice may not be removed or altered from any source distribution.19*/2021/* WIKI CATEGORY: SharedObject */2223/**24* # CategorySharedObject25*26* System-dependent library loading routines.27*28* Shared objects are code that is programmatically loadable at runtime.29* Windows calls these "DLLs", Linux calls them "shared libraries", etc.30*31* To use them, build such a library, then call SDL_LoadObject() on it. Once32* loaded, you can use SDL_LoadFunction() on that object to find the address33* of its exported symbols. When done with the object, call SDL_UnloadObject()34* to dispose of it.35*36* Some things to keep in mind:37*38* - These functions only work on C function names. Other languages may have39* name mangling and intrinsic language support that varies from compiler to40* compiler.41* - Make sure you declare your function pointers with the same calling42* convention as the actual library function. Your code will crash43* mysteriously if you do not do this.44* - Avoid namespace collisions. If you load a symbol from the library, it is45* not defined whether or not it goes into the global symbol namespace for46* the application. If it does and it conflicts with symbols in your code or47* other shared libraries, you will not get the results you expect. :)48* - Once a library is unloaded, all pointers into it obtained through49* SDL_LoadFunction() become invalid, even if the library is later reloaded.50* Don't unload a library if you plan to use these pointers in the future.51* Notably: beware of giving one of these pointers to atexit(), since it may52* call that pointer after the library unloads.53*/5455#ifndef SDL_loadso_h_56#define SDL_loadso_h_5758#include <SDL3/SDL_stdinc.h>59#include <SDL3/SDL_error.h>6061#include <SDL3/SDL_begin_code.h>62/* Set up for C function definitions, even when using C++ */63#ifdef __cplusplus64extern "C" {65#endif6667/**68* An opaque datatype that represents a loaded shared object.69*70* \since This datatype is available since SDL 3.2.0.71*72* \sa SDL_LoadObject73* \sa SDL_LoadFunction74* \sa SDL_UnloadObject75*/76typedef struct SDL_SharedObject SDL_SharedObject;7778/**79* Dynamically load a shared object.80*81* \param sofile a system-dependent name of the object file.82* \returns an opaque pointer to the object handle or NULL on failure; call83* SDL_GetError() for more information.84*85* \threadsafety It is safe to call this function from any thread.86*87* \since This function is available since SDL 3.2.0.88*89* \sa SDL_LoadFunction90* \sa SDL_UnloadObject91*/92extern SDL_DECLSPEC SDL_SharedObject * SDLCALL SDL_LoadObject(const char *sofile);9394/**95* Look up the address of the named function in a shared object.96*97* This function pointer is no longer valid after calling SDL_UnloadObject().98*99* This function can only look up C function names. Other languages may have100* name mangling and intrinsic language support that varies from compiler to101* compiler.102*103* Make sure you declare your function pointers with the same calling104* convention as the actual library function. Your code will crash105* mysteriously if you do not do this.106*107* If the requested function doesn't exist, NULL is returned.108*109* \param handle a valid shared object handle returned by SDL_LoadObject().110* \param name the name of the function to look up.111* \returns a pointer to the function or NULL on failure; call SDL_GetError()112* for more information.113*114* \threadsafety It is safe to call this function from any thread.115*116* \since This function is available since SDL 3.2.0.117*118* \sa SDL_LoadObject119*/120extern SDL_DECLSPEC SDL_FunctionPointer SDLCALL SDL_LoadFunction(SDL_SharedObject *handle, const char *name);121122/**123* Unload a shared object from memory.124*125* Note that any pointers from this object looked up through126* SDL_LoadFunction() will no longer be valid.127*128* \param handle a valid shared object handle returned by SDL_LoadObject().129*130* \threadsafety It is safe to call this function from any thread.131*132* \since This function is available since SDL 3.2.0.133*134* \sa SDL_LoadObject135*/136extern SDL_DECLSPEC void SDLCALL SDL_UnloadObject(SDL_SharedObject *handle);137138/* Ends C function definitions when using C++ */139#ifdef __cplusplus140}141#endif142#include <SDL3/SDL_close_code.h>143144#endif /* SDL_loadso_h_ */145146147