SDL_sysloadso.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2023 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. #include "SDL_internal.h"
  19. #ifdef SDL_LOADSO_WINDOWS
  20. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  21. /* System dependent library loading routines */
  22. #include "../../core/windows/SDL_windows.h"
  23. void *SDL_LoadObject(const char *sofile)
  24. {
  25. void *handle;
  26. LPTSTR tstr;
  27. if (sofile == NULL) {
  28. SDL_InvalidParamError("sofile");
  29. return NULL;
  30. }
  31. tstr = WIN_UTF8ToString(sofile);
  32. #ifdef __WINRT__
  33. /* WinRT only publicly supports LoadPackagedLibrary() for loading .dll
  34. files. LoadLibrary() is a private API, and not available for apps
  35. (that can be published to MS' Windows Store.)
  36. */
  37. handle = (void *)LoadPackagedLibrary(tstr, 0);
  38. #else
  39. handle = (void *)LoadLibrary(tstr);
  40. #endif
  41. SDL_free(tstr);
  42. /* Generate an error message if all loads failed */
  43. if (handle == NULL) {
  44. char errbuf[512];
  45. SDL_strlcpy(errbuf, "Failed loading ", SDL_arraysize(errbuf));
  46. SDL_strlcat(errbuf, sofile, SDL_arraysize(errbuf));
  47. WIN_SetError(errbuf);
  48. }
  49. return handle;
  50. }
  51. SDL_FunctionPointer SDL_LoadFunction(void *handle, const char *name)
  52. {
  53. void *symbol = (void *)GetProcAddress((HMODULE)handle, name);
  54. if (symbol == NULL) {
  55. char errbuf[512];
  56. SDL_strlcpy(errbuf, "Failed loading ", SDL_arraysize(errbuf));
  57. SDL_strlcat(errbuf, name, SDL_arraysize(errbuf));
  58. WIN_SetError(errbuf);
  59. }
  60. return symbol;
  61. }
  62. void SDL_UnloadObject(void *handle)
  63. {
  64. if (handle != NULL) {
  65. FreeLibrary((HMODULE)handle);
  66. }
  67. }
  68. #endif /* SDL_LOADSO_WINDOWS */