Mercurial > sdl-ios-xcode
comparison src/loadso/win32/SDL_sysloadso.c @ 1361:19418e4422cb
New configure-based build system. Still work in progress, but much improved
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 16 Feb 2006 10:11:48 +0000 |
parents | |
children | c0a74f199ecf |
comparison
equal
deleted
inserted
replaced
1360:70a9cfb4cf1b | 1361:19418e4422cb |
---|---|
1 /* | |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997-2006 Sam Lantinga | |
4 | |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Lesser General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2.1 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Lesser General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Lesser General Public | |
16 License along with this library; if not, write to the Free Software | |
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
18 | |
19 Sam Lantinga | |
20 slouken@libsdl.org | |
21 */ | |
22 | |
23 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
24 /* System dependent library loading routines */ | |
25 | |
26 #include "SDL_windows.h" | |
27 | |
28 #include "SDL_loadso.h" | |
29 | |
30 void *SDL_LoadObject(const char *sofile) | |
31 { | |
32 void *handle = NULL; | |
33 const char *loaderror = "Unknown error"; | |
34 | |
35 #if defined(_WIN32_WCE) | |
36 char errbuf[512]; | |
37 | |
38 wchar_t *errbuf_t = SDL_malloc(512 * sizeof(wchar_t)); | |
39 wchar_t *sofile_t = SDL_malloc((MAX_PATH+1) * sizeof(wchar_t)); | |
40 | |
41 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, sofile, -1, sofile_t, MAX_PATH); | |
42 handle = (void *)LoadLibrary(sofile_t); | |
43 | |
44 /* Generate an error message if all loads failed */ | |
45 if ( handle == NULL ) { | |
46 FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS | | |
47 FORMAT_MESSAGE_FROM_SYSTEM), | |
48 NULL, GetLastError(), | |
49 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), | |
50 errbuf_t, SDL_TABLESIZE(errbuf), NULL); | |
51 WideCharToMultiByte(CP_ACP, 0, errbuf_t, -1, errbuf, 511, NULL, NULL); | |
52 loaderror = errbuf; | |
53 } | |
54 | |
55 SDL_free(sofile_t); | |
56 SDL_free(errbuf_t); | |
57 | |
58 #else /*if defined(WIN32)*/ | |
59 char errbuf[512]; | |
60 | |
61 handle = (void *)LoadLibrary(sofile); | |
62 | |
63 /* Generate an error message if all loads failed */ | |
64 if ( handle == NULL ) { | |
65 FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS | | |
66 FORMAT_MESSAGE_FROM_SYSTEM), | |
67 NULL, GetLastError(), | |
68 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), | |
69 errbuf, SDL_TABLESIZE(errbuf), NULL); | |
70 loaderror = errbuf; | |
71 } | |
72 #endif | |
73 | |
74 if ( handle == NULL ) { | |
75 SDL_SetError("Failed loading %s: %s", sofile, loaderror); | |
76 } | |
77 return(handle); | |
78 } | |
79 | |
80 void *SDL_LoadFunction(void *handle, const char *name) | |
81 { | |
82 void *symbol = NULL; | |
83 const char *loaderror = "Unknown error"; | |
84 | |
85 #if defined(_WIN32_WCE) | |
86 char errbuf[512]; | |
87 int length = SDL_strlen(name); | |
88 | |
89 wchar_t *name_t = SDL_malloc((length + 1) * sizeof(wchar_t)); | |
90 wchar_t *errbuf_t = SDL_malloc(512 * sizeof(wchar_t)); | |
91 | |
92 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, name, -1, name_t, length); | |
93 | |
94 symbol = (void *)GetProcAddress((HMODULE)handle, name_t); | |
95 if ( symbol == NULL ) { | |
96 FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS | | |
97 FORMAT_MESSAGE_FROM_SYSTEM), | |
98 NULL, GetLastError(), | |
99 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), | |
100 errbuf_t, SDL_TABLESIZE(errbuf), NULL); | |
101 WideCharToMultiByte(CP_ACP, 0, errbuf_t, -1, errbuf, 511, NULL, NULL); | |
102 loaderror = errbuf; | |
103 } | |
104 | |
105 SDL_free(name_t); | |
106 SDL_free(errbuf_t); | |
107 | |
108 #else /*if defined(WIN32)*/ | |
109 char errbuf[512]; | |
110 | |
111 symbol = (void *)GetProcAddress((HMODULE)handle, name); | |
112 if ( symbol == NULL ) { | |
113 FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS | | |
114 FORMAT_MESSAGE_FROM_SYSTEM), | |
115 NULL, GetLastError(), | |
116 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), | |
117 errbuf, SDL_TABLESIZE(errbuf), NULL); | |
118 loaderror = errbuf; | |
119 } | |
120 #endif | |
121 | |
122 if ( symbol == NULL ) { | |
123 SDL_SetError("Failed loading %s: %s", name, loaderror); | |
124 } | |
125 return(symbol); | |
126 } | |
127 | |
128 void SDL_UnloadObject(void *handle) | |
129 { | |
130 if ( handle != NULL ) { | |
131 FreeLibrary((HMODULE)handle); | |
132 } | |
133 } | |
134 |