Mercurial > sdl-ios-xcode
comparison src/loadso/win32/SDL_sysloadso.c @ 1895:c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 10 Jul 2006 21:04:37 +0000 |
parents | 92947e3a18db |
children | 3e42ad69f4a3 |
comparison
equal
deleted
inserted
replaced
1894:c69cee13dd76 | 1895:c121d94672cb |
---|---|
29 #define WIN32_LEAN_AND_MEAN | 29 #define WIN32_LEAN_AND_MEAN |
30 #include <windows.h> | 30 #include <windows.h> |
31 | 31 |
32 #include "SDL_loadso.h" | 32 #include "SDL_loadso.h" |
33 | 33 |
34 void *SDL_LoadObject(const char *sofile) | 34 void * |
35 SDL_LoadObject(const char *sofile) | |
35 { | 36 { |
36 void *handle = NULL; | 37 void *handle = NULL; |
37 const char *loaderror = "Unknown error"; | 38 const char *loaderror = "Unknown error"; |
38 | 39 |
39 #if defined(_WIN32_WCE) | 40 #if defined(_WIN32_WCE) |
40 char errbuf[512]; | 41 char errbuf[512]; |
41 | 42 |
42 wchar_t *errbuf_t = SDL_malloc(512 * sizeof(wchar_t)); | 43 wchar_t *errbuf_t = SDL_malloc(512 * sizeof(wchar_t)); |
43 wchar_t *sofile_t = SDL_malloc((MAX_PATH+1) * sizeof(wchar_t)); | 44 wchar_t *sofile_t = SDL_malloc((MAX_PATH + 1) * sizeof(wchar_t)); |
44 | 45 |
45 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, sofile, -1, sofile_t, MAX_PATH); | 46 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, sofile, -1, sofile_t, |
46 handle = (void *)LoadLibrary(sofile_t); | 47 MAX_PATH); |
48 handle = (void *) LoadLibrary(sofile_t); | |
47 | 49 |
48 /* Generate an error message if all loads failed */ | 50 /* Generate an error message if all loads failed */ |
49 if ( handle == NULL ) { | 51 if (handle == NULL) { |
50 FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS | | 52 FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS | |
51 FORMAT_MESSAGE_FROM_SYSTEM), | 53 FORMAT_MESSAGE_FROM_SYSTEM), |
52 NULL, GetLastError(), | 54 NULL, GetLastError(), |
53 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), | 55 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
54 errbuf_t, SDL_arraysize(errbuf), NULL); | 56 errbuf_t, SDL_arraysize(errbuf), NULL); |
55 WideCharToMultiByte(CP_ACP, 0, errbuf_t, -1, errbuf, 511, NULL, NULL); | 57 WideCharToMultiByte(CP_ACP, 0, errbuf_t, -1, errbuf, 511, NULL, NULL); |
56 loaderror = errbuf; | 58 loaderror = errbuf; |
57 } | 59 } |
58 | 60 |
59 SDL_free(sofile_t); | 61 SDL_free(sofile_t); |
60 SDL_free(errbuf_t); | 62 SDL_free(errbuf_t); |
61 | 63 |
62 #else /*if defined(__WIN32__)*/ | 64 #else /*if defined(__WIN32__) */ |
63 char errbuf[512]; | 65 char errbuf[512]; |
64 | 66 |
65 handle = (void *)LoadLibrary(sofile); | 67 handle = (void *) LoadLibrary(sofile); |
66 | 68 |
67 /* Generate an error message if all loads failed */ | 69 /* Generate an error message if all loads failed */ |
68 if ( handle == NULL ) { | 70 if (handle == NULL) { |
69 FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS | | 71 FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS | |
70 FORMAT_MESSAGE_FROM_SYSTEM), | 72 FORMAT_MESSAGE_FROM_SYSTEM), |
71 NULL, GetLastError(), | 73 NULL, GetLastError(), |
72 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), | 74 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
73 errbuf, SDL_arraysize(errbuf), NULL); | 75 errbuf, SDL_arraysize(errbuf), NULL); |
74 loaderror = errbuf; | 76 loaderror = errbuf; |
75 } | 77 } |
76 #endif | 78 #endif |
77 | 79 |
78 if ( handle == NULL ) { | 80 if (handle == NULL) { |
79 SDL_SetError("Failed loading %s: %s", sofile, loaderror); | 81 SDL_SetError("Failed loading %s: %s", sofile, loaderror); |
80 } | 82 } |
81 return(handle); | 83 return (handle); |
82 } | 84 } |
83 | 85 |
84 void *SDL_LoadFunction(void *handle, const char *name) | 86 void * |
87 SDL_LoadFunction(void *handle, const char *name) | |
85 { | 88 { |
86 void *symbol = NULL; | 89 void *symbol = NULL; |
87 const char *loaderror = "Unknown error"; | 90 const char *loaderror = "Unknown error"; |
88 | 91 |
89 #if defined(_WIN32_WCE) | 92 #if defined(_WIN32_WCE) |
90 char errbuf[512]; | 93 char errbuf[512]; |
91 int length = SDL_strlen(name); | 94 int length = SDL_strlen(name); |
92 | 95 |
93 wchar_t *name_t = SDL_malloc((length + 1) * sizeof(wchar_t)); | 96 wchar_t *name_t = SDL_malloc((length + 1) * sizeof(wchar_t)); |
94 wchar_t *errbuf_t = SDL_malloc(512 * sizeof(wchar_t)); | 97 wchar_t *errbuf_t = SDL_malloc(512 * sizeof(wchar_t)); |
95 | 98 |
96 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, name, -1, name_t, length); | 99 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, name, -1, name_t, length); |
97 | 100 |
98 symbol = (void *)GetProcAddress((HMODULE)handle, name_t); | 101 symbol = (void *) GetProcAddress((HMODULE) handle, name_t); |
99 if ( symbol == NULL ) { | 102 if (symbol == NULL) { |
100 FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS | | 103 FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS | |
101 FORMAT_MESSAGE_FROM_SYSTEM), | 104 FORMAT_MESSAGE_FROM_SYSTEM), |
102 NULL, GetLastError(), | 105 NULL, GetLastError(), |
103 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), | 106 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
104 errbuf_t, SDL_arraysize(errbuf), NULL); | 107 errbuf_t, SDL_arraysize(errbuf), NULL); |
105 WideCharToMultiByte(CP_ACP, 0, errbuf_t, -1, errbuf, 511, NULL, NULL); | 108 WideCharToMultiByte(CP_ACP, 0, errbuf_t, -1, errbuf, 511, NULL, NULL); |
106 loaderror = errbuf; | 109 loaderror = errbuf; |
107 } | 110 } |
108 | 111 |
109 SDL_free(name_t); | 112 SDL_free(name_t); |
110 SDL_free(errbuf_t); | 113 SDL_free(errbuf_t); |
111 | 114 |
112 #else /*if defined(WIN32)*/ | 115 #else /*if defined(WIN32) */ |
113 char errbuf[512]; | 116 char errbuf[512]; |
114 | 117 |
115 symbol = (void *)GetProcAddress((HMODULE)handle, name); | 118 symbol = (void *) GetProcAddress((HMODULE) handle, name); |
116 if ( symbol == NULL ) { | 119 if (symbol == NULL) { |
117 FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS | | 120 FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS | |
118 FORMAT_MESSAGE_FROM_SYSTEM), | 121 FORMAT_MESSAGE_FROM_SYSTEM), |
119 NULL, GetLastError(), | 122 NULL, GetLastError(), |
120 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), | 123 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
121 errbuf, SDL_arraysize(errbuf), NULL); | 124 errbuf, SDL_arraysize(errbuf), NULL); |
122 loaderror = errbuf; | 125 loaderror = errbuf; |
123 } | 126 } |
124 #endif | 127 #endif |
125 | 128 |
126 if ( symbol == NULL ) { | 129 if (symbol == NULL) { |
127 SDL_SetError("Failed loading %s: %s", name, loaderror); | 130 SDL_SetError("Failed loading %s: %s", name, loaderror); |
128 } | 131 } |
129 return(symbol); | 132 return (symbol); |
130 } | 133 } |
131 | 134 |
132 void SDL_UnloadObject(void *handle) | 135 void |
136 SDL_UnloadObject(void *handle) | |
133 { | 137 { |
134 if ( handle != NULL ) { | 138 if (handle != NULL) { |
135 FreeLibrary((HMODULE)handle); | 139 FreeLibrary((HMODULE) handle); |
136 } | 140 } |
137 } | 141 } |
138 | 142 |
139 #endif /* SDL_LOADSO_WIN32 */ | 143 #endif /* SDL_LOADSO_WIN32 */ |
144 /* vi: set ts=4 sw=4 expandtab: */ |