SDL_sysloadso.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2014 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. #include "SDL_loadso.h"
  24. void *
  25. SDL_LoadObject(const char *sofile)
  26. {
  27. LPTSTR tstr = WIN_UTF8ToString(sofile);
  28. void *handle = (void *) LoadLibrary(tstr);
  29. SDL_free(tstr);
  30. /* Generate an error message if all loads failed */
  31. if (handle == NULL) {
  32. char errbuf[512];
  33. SDL_strlcpy(errbuf, "Failed loading ", SDL_arraysize(errbuf));
  34. SDL_strlcat(errbuf, sofile, SDL_arraysize(errbuf));
  35. WIN_SetError(errbuf);
  36. }
  37. return handle;
  38. }
  39. void *
  40. SDL_GetLoadedObject(const char *sofile)
  41. {
  42. LPTSTR tstr = WIN_UTF8ToString(sofile);
  43. void *handle = (void *) GetModuleHandle(tstr);
  44. /* if we got a handle, call LoadLibrary to get
  45. * it again with the ref count incremented.
  46. * We do this to match the dlopen version of this function */
  47. handle = (void *)LoadLibrary( tstr );
  48. SDL_free(tstr);
  49. return handle;
  50. }
  51. void *
  52. SDL_LoadFunction(void *handle, const char *name)
  53. {
  54. void *symbol = (void *) GetProcAddress((HMODULE) handle, name);
  55. if (symbol == NULL) {
  56. char errbuf[512];
  57. SDL_strlcpy(errbuf, "Failed loading ", SDL_arraysize(errbuf));
  58. SDL_strlcat(errbuf, name, SDL_arraysize(errbuf));
  59. WIN_SetError(errbuf);
  60. }
  61. return symbol;
  62. }
  63. void
  64. SDL_UnloadObject(void *handle)
  65. {
  66. if (handle != NULL) {
  67. FreeLibrary((HMODULE) handle);
  68. }
  69. }
  70. #endif /* SDL_LOADSO_WINDOWS */
  71. /* vi: set ts=4 sw=4 expandtab: */