SDL  2.0
SDL_sysloadso.c
Go to the documentation of this file.
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 *
33 SDL_LoadObject(const char *sofile)
34 {
35  void *handle;
36  LPTSTR tstr;
37 
38  if (!sofile) {
39  SDL_SetError("NULL sofile");
40  return NULL;
41  }
42  tstr = WIN_UTF8ToString(sofile);
43 #ifdef __WINRT__
44  /* WinRT only publically supports LoadPackagedLibrary() for loading .dll
45  files. LoadLibrary() is a private API, and not available for apps
46  (that can be published to MS' Windows Store.)
47  */
48  handle = (void *) LoadPackagedLibrary(tstr, 0);
49 #else
50  handle = (void *) LoadLibrary(tstr);
51 #endif
52  SDL_free(tstr);
53 
54  /* Generate an error message if all loads failed */
55  if (handle == NULL) {
56  char errbuf[512];
57  SDL_strlcpy(errbuf, "Failed loading ", SDL_arraysize(errbuf));
58  SDL_strlcat(errbuf, sofile, SDL_arraysize(errbuf));
59  WIN_SetError(errbuf);
60  }
61  return handle;
62 }
63 
64 void *
65 SDL_LoadFunction(void *handle, const char *name)
66 {
67  void *symbol = (void *) GetProcAddress((HMODULE) handle, name);
68  if (symbol == NULL) {
69  char errbuf[512];
70  SDL_strlcpy(errbuf, "Failed loading ", SDL_arraysize(errbuf));
71  SDL_strlcat(errbuf, name, SDL_arraysize(errbuf));
72  WIN_SetError(errbuf);
73  }
74  return symbol;
75 }
76 
77 void
79 {
80  if (handle != NULL) {
81  FreeLibrary((HMODULE) handle);
82  }
83 }
84 
85 #endif /* SDL_LOADSO_WINDOWS */
86 
87 /* vi: set ts=4 sw=4 expandtab: */
#define SDL_SetError
#define SDL_strlcat
#define SDL_LoadObject
#define SDL_UnloadObject
#define SDL_strlcpy
#define SDL_free
void * SDL_LoadFunction(void *handle, const char *name)
GLuint const GLchar * name
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:121
#define WIN_UTF8ToString(S)
Definition: SDL_windows.h:47
int WIN_SetError(const char *prefix)
#define NULL
Definition: begin_code.h:163
EGLImageKHR EGLint EGLint * handle
Definition: eglext.h:937