SDL_sysloadso.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #include "SDL_internal.h"
  19. #ifdef SDL_LOADSO_WINDOWS
  20. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  21. // System dependent library loading routines
  22. #include "../../core/windows/SDL_windows.h"
  23. SDL_SharedObject *SDL_LoadObject(const char *sofile)
  24. {
  25. if (!sofile) {
  26. SDL_InvalidParamError("sofile");
  27. return NULL;
  28. }
  29. LPWSTR wstr = WIN_UTF8ToStringW(sofile);
  30. HMODULE handle = LoadLibraryW(wstr);
  31. SDL_free(wstr);
  32. // Generate an error message if all loads failed
  33. if (!handle) {
  34. char errbuf[512];
  35. SDL_snprintf(errbuf, sizeof (errbuf), "Failed loading %s", sofile);
  36. WIN_SetError(errbuf);
  37. }
  38. return (SDL_SharedObject *) handle;
  39. }
  40. SDL_FunctionPointer SDL_LoadFunction(SDL_SharedObject *handle, const char *name)
  41. {
  42. SDL_FunctionPointer symbol = (SDL_FunctionPointer)GetProcAddress((HMODULE)handle, name);
  43. if (!symbol) {
  44. char errbuf[512];
  45. SDL_snprintf(errbuf, sizeof (errbuf), "Failed loading %s", name);
  46. WIN_SetError(errbuf);
  47. }
  48. return symbol;
  49. }
  50. void SDL_UnloadObject(SDL_SharedObject *handle)
  51. {
  52. if (handle) {
  53. FreeLibrary((HMODULE)handle);
  54. }
  55. }
  56. #endif // SDL_LOADSO_WINDOWS