2015-06-21 10:33:46 -05:00
|
|
|
/*
|
|
|
|
Simple DirectMedia Layer
|
2023-01-09 11:41:41 -06:00
|
|
|
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
2015-06-21 10:33:46 -05:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
2022-11-29 20:34:15 -06:00
|
|
|
#include "SDL_internal.h"
|
2015-06-21 10:33:46 -05:00
|
|
|
|
|
|
|
#ifdef SDL_LOADSO_WINDOWS
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
/* System dependent library loading routines */
|
|
|
|
|
|
|
|
#include "../../core/windows/SDL_windows.h"
|
|
|
|
|
2023-01-09 16:55:12 -06:00
|
|
|
void *SDL_LoadObject(const char *sofile)
|
2015-06-21 10:33:46 -05:00
|
|
|
{
|
2020-12-13 09:25:02 -06:00
|
|
|
void *handle;
|
2020-12-13 08:37:50 -06:00
|
|
|
LPTSTR tstr;
|
|
|
|
|
2022-11-27 10:38:43 -06:00
|
|
|
if (sofile == NULL) {
|
2022-01-17 09:26:02 -06:00
|
|
|
SDL_InvalidParamError("sofile");
|
2020-12-13 08:37:50 -06:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
tstr = WIN_UTF8ToString(sofile);
|
2022-11-23 12:41:43 -06:00
|
|
|
#ifdef __WINRT__
|
|
|
|
/* WinRT only publicly supports LoadPackagedLibrary() for loading .dll
|
|
|
|
files. LoadLibrary() is a private API, and not available for apps
|
|
|
|
(that can be published to MS' Windows Store.)
|
|
|
|
*/
|
2022-11-30 14:51:59 -06:00
|
|
|
handle = (void *)LoadPackagedLibrary(tstr, 0);
|
2022-11-23 12:41:43 -06:00
|
|
|
#else
|
2022-11-30 14:51:59 -06:00
|
|
|
handle = (void *)LoadLibrary(tstr);
|
2022-11-23 12:41:43 -06:00
|
|
|
#endif
|
2015-06-21 10:33:46 -05:00
|
|
|
SDL_free(tstr);
|
|
|
|
|
|
|
|
/* Generate an error message if all loads failed */
|
|
|
|
if (handle == NULL) {
|
|
|
|
char errbuf[512];
|
|
|
|
SDL_strlcpy(errbuf, "Failed loading ", SDL_arraysize(errbuf));
|
|
|
|
SDL_strlcat(errbuf, sofile, SDL_arraysize(errbuf));
|
|
|
|
WIN_SetError(errbuf);
|
|
|
|
}
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
2023-01-09 16:55:12 -06:00
|
|
|
SDL_FunctionPointer SDL_LoadFunction(void *handle, const char *name)
|
2015-06-21 10:33:46 -05:00
|
|
|
{
|
2022-11-30 14:51:59 -06:00
|
|
|
void *symbol = (void *)GetProcAddress((HMODULE)handle, name);
|
2015-06-21 10:33:46 -05:00
|
|
|
if (symbol == NULL) {
|
|
|
|
char errbuf[512];
|
|
|
|
SDL_strlcpy(errbuf, "Failed loading ", SDL_arraysize(errbuf));
|
|
|
|
SDL_strlcat(errbuf, name, SDL_arraysize(errbuf));
|
|
|
|
WIN_SetError(errbuf);
|
|
|
|
}
|
|
|
|
return symbol;
|
|
|
|
}
|
|
|
|
|
2022-11-30 14:51:59 -06:00
|
|
|
void SDL_UnloadObject(void *handle)
|
2015-06-21 10:33:46 -05:00
|
|
|
{
|
|
|
|
if (handle != NULL) {
|
2022-11-30 14:51:59 -06:00
|
|
|
FreeLibrary((HMODULE)handle);
|
2015-06-21 10:33:46 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* SDL_LOADSO_WINDOWS */
|