SDL_loadso.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /* WIKI CATEGORY: SharedObject */
  19. /**
  20. * # CategorySharedObject
  21. *
  22. * System-dependent library loading routines.
  23. *
  24. * Shared objects are code that is programmatically loadable at runtime.
  25. * Windows calls these "DLLs", Linux calls them "shared libraries", etc.
  26. *
  27. * To use them, build such a library, then call SDL_LoadObject() on it. Once
  28. * loaded, you can use SDL_LoadFunction() on that object to find the address
  29. * of its exported symbols. When done with the object, call SDL_UnloadObject()
  30. * to dispose of it.
  31. *
  32. * Some things to keep in mind:
  33. *
  34. * - These functions only work on C function names. Other languages may have
  35. * name mangling and intrinsic language support that varies from compiler to
  36. * compiler.
  37. * - Make sure you declare your function pointers with the same calling
  38. * convention as the actual library function. Your code will crash
  39. * mysteriously if you do not do this.
  40. * - Avoid namespace collisions. If you load a symbol from the library, it is
  41. * not defined whether or not it goes into the global symbol namespace for
  42. * the application. If it does and it conflicts with symbols in your code or
  43. * other shared libraries, you will not get the results you expect. :)
  44. */
  45. #ifndef SDL_loadso_h_
  46. #define SDL_loadso_h_
  47. #include <SDL3/SDL_stdinc.h>
  48. #include <SDL3/SDL_error.h>
  49. #include <SDL3/SDL_begin_code.h>
  50. /* Set up for C function definitions, even when using C++ */
  51. #ifdef __cplusplus
  52. extern "C" {
  53. #endif
  54. /**
  55. * An opaque datatype that represents a loaded shared object.
  56. *
  57. * \since This datatype is available since SDL 3.1.3.
  58. *
  59. * \sa SDL_LoadObject
  60. * \sa SDL_LoadFunction
  61. * \sa SDL_UnloadObject
  62. */
  63. typedef struct SDL_SharedObject SDL_SharedObject;
  64. /**
  65. * Dynamically load a shared object.
  66. *
  67. * \param sofile a system-dependent name of the object file.
  68. * \returns an opaque pointer to the object handle or NULL on failure; call
  69. * SDL_GetError() for more information.
  70. *
  71. * \threadsafety It is safe to call this function from any thread.
  72. *
  73. * \since This function is available since SDL 3.1.3.
  74. *
  75. * \sa SDL_LoadFunction
  76. * \sa SDL_UnloadObject
  77. */
  78. extern SDL_DECLSPEC SDL_SharedObject * SDLCALL SDL_LoadObject(const char *sofile);
  79. /**
  80. * Look up the address of the named function in a shared object.
  81. *
  82. * This function pointer is no longer valid after calling SDL_UnloadObject().
  83. *
  84. * This function can only look up C function names. Other languages may have
  85. * name mangling and intrinsic language support that varies from compiler to
  86. * compiler.
  87. *
  88. * Make sure you declare your function pointers with the same calling
  89. * convention as the actual library function. Your code will crash
  90. * mysteriously if you do not do this.
  91. *
  92. * If the requested function doesn't exist, NULL is returned.
  93. *
  94. * \param handle a valid shared object handle returned by SDL_LoadObject().
  95. * \param name the name of the function to look up.
  96. * \returns a pointer to the function or NULL on failure; call SDL_GetError()
  97. * for more information.
  98. *
  99. * \threadsafety It is safe to call this function from any thread.
  100. *
  101. * \since This function is available since SDL 3.1.3.
  102. *
  103. * \sa SDL_LoadObject
  104. */
  105. extern SDL_DECLSPEC SDL_FunctionPointer SDLCALL SDL_LoadFunction(SDL_SharedObject *handle, const char *name);
  106. /**
  107. * Unload a shared object from memory.
  108. *
  109. * Note that any pointers from this object looked up through
  110. * SDL_LoadFunction() will no longer be valid.
  111. *
  112. * \param handle a valid shared object handle returned by SDL_LoadObject().
  113. *
  114. * \threadsafety It is safe to call this function from any thread.
  115. *
  116. * \since This function is available since SDL 3.1.3.
  117. *
  118. * \sa SDL_LoadObject
  119. */
  120. extern SDL_DECLSPEC void SDLCALL SDL_UnloadObject(SDL_SharedObject *handle);
  121. /* Ends C function definitions when using C++ */
  122. #ifdef __cplusplus
  123. }
  124. #endif
  125. #include <SDL3/SDL_close_code.h>
  126. #endif /* SDL_loadso_h_ */