1 /*
2   Simple DirectMedia Layer
3   Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
4 
5   This software is provided 'as-is', without any express or implied
6   warranty.  In no event will the authors be held liable for any damages
7   arising from the use of this software.
8 
9   Permission is granted to anyone to use this software for any purpose,
10   including commercial applications, and to alter it and redistribute it
11   freely, subject to the following restrictions:
12 
13   1. The origin of this software must not be misrepresented; you must not
14      claim that you wrote the original software. If you use this software
15      in a product, an acknowledgment in the product documentation would be
16      appreciated but is not required.
17   2. Altered source versions must be plainly marked as such, and must not be
18      misrepresented as being the original software.
19   3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "../../SDL_internal.h"
22 
23 #ifdef SDL_LOADSO_WINDOWS
24 
25 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
26 /* System dependent library loading routines                           */
27 
28 #include "../../core/windows/SDL_windows.h"
29 
30 #include "SDL_loadso.h"
31 
32 void *
SDL_LoadObject(const char * sofile)33 SDL_LoadObject(const char *sofile)
34 {
35     LPTSTR tstr = WIN_UTF8ToString(sofile);
36 #ifdef __WINRT__
37     /* WinRT only publically supports LoadPackagedLibrary() for loading .dll
38        files.  LoadLibrary() is a private API, and not available for apps
39        (that can be published to MS' Windows Store.)
40     */
41     void *handle = (void *) LoadPackagedLibrary(tstr, 0);
42 #else
43     void *handle = (void *) LoadLibrary(tstr);
44 #endif
45     SDL_free(tstr);
46 
47     /* Generate an error message if all loads failed */
48     if (handle == NULL) {
49         char errbuf[512];
50         SDL_strlcpy(errbuf, "Failed loading ", SDL_arraysize(errbuf));
51         SDL_strlcat(errbuf, sofile, SDL_arraysize(errbuf));
52         WIN_SetError(errbuf);
53     }
54     return handle;
55 }
56 
57 void *
SDL_LoadFunction(void * handle,const char * name)58 SDL_LoadFunction(void *handle, const char *name)
59 {
60     void *symbol = (void *) GetProcAddress((HMODULE) handle, name);
61     if (symbol == NULL) {
62         char errbuf[512];
63         SDL_strlcpy(errbuf, "Failed loading ", SDL_arraysize(errbuf));
64         SDL_strlcat(errbuf, name, SDL_arraysize(errbuf));
65         WIN_SetError(errbuf);
66     }
67     return symbol;
68 }
69 
70 void
SDL_UnloadObject(void * handle)71 SDL_UnloadObject(void *handle)
72 {
73     if (handle != NULL) {
74         FreeLibrary((HMODULE) handle);
75     }
76 }
77 
78 #endif /* SDL_LOADSO_WINDOWS */
79 
80 /* vi: set ts=4 sw=4 expandtab: */
81