Mercurial > sdl-ios-xcode
comparison src/loadso/windows/SDL_sysloadso.c @ 5131:2c500f37abcf
merged: might need to check main.c in the iOS template to make sure no changes were abandoned.
author | Eric Wing <ewing . public |-at-| gmail . com> |
---|---|
date | Tue, 01 Feb 2011 00:37:02 -0800 |
parents | 327f181542f1 |
children | b530ef003506 |
comparison
equal
deleted
inserted
replaced
5078:067973aec4d8 | 5131:2c500f37abcf |
---|---|
24 #ifdef SDL_LOADSO_WINDOWS | 24 #ifdef SDL_LOADSO_WINDOWS |
25 | 25 |
26 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | 26 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
27 /* System dependent library loading routines */ | 27 /* System dependent library loading routines */ |
28 | 28 |
29 #define WIN32_LEAN_AND_MEAN | 29 #include "../../core/windows/SDL_windows.h" |
30 #include <windows.h> | |
31 | 30 |
32 #include "SDL_loadso.h" | 31 #include "SDL_loadso.h" |
33 | 32 |
34 void * | 33 void * |
35 SDL_LoadObject(const char *sofile) | 34 SDL_LoadObject(const char *sofile) |
36 { | 35 { |
37 void *handle = NULL; | 36 LPTSTR tstr = WIN_UTF8ToString(sofile); |
38 const char *loaderror = "Unknown error"; | 37 void *handle = (void *) LoadLibrary(tstr); |
39 | 38 SDL_free(tstr); |
40 #if defined(_WIN32_WCE) | |
41 char errbuf[512]; | |
42 | |
43 wchar_t *errbuf_t = SDL_malloc(512 * sizeof(wchar_t)); | |
44 wchar_t *sofile_t = SDL_malloc((MAX_PATH + 1) * sizeof(wchar_t)); | |
45 | |
46 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, sofile, -1, sofile_t, | |
47 MAX_PATH); | |
48 handle = (void *) LoadLibrary(sofile_t); | |
49 | 39 |
50 /* Generate an error message if all loads failed */ | 40 /* Generate an error message if all loads failed */ |
51 if (handle == NULL) { | 41 if (handle == NULL) { |
52 FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS | | 42 char errbuf[512]; |
53 FORMAT_MESSAGE_FROM_SYSTEM), | 43 SDL_strlcpy(errbuf, "Failed loading ", SDL_arraysize(errbuf)); |
54 NULL, GetLastError(), | 44 SDL_strlcat(errbuf, sofile, SDL_arraysize(errbuf)); |
55 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), | 45 WIN_SetError(errbuf); |
56 errbuf_t, SDL_arraysize(errbuf), NULL); | |
57 WideCharToMultiByte(CP_ACP, 0, errbuf_t, -1, errbuf, 511, NULL, NULL); | |
58 loaderror = errbuf; | |
59 } | 46 } |
60 | 47 return handle; |
61 SDL_free(sofile_t); | |
62 SDL_free(errbuf_t); | |
63 | |
64 #else /*if defined(__WINDOWS__) */ | |
65 char errbuf[512]; | |
66 | |
67 handle = (void *) LoadLibrary(sofile); | |
68 | |
69 /* Generate an error message if all loads failed */ | |
70 if (handle == NULL) { | |
71 FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS | | |
72 FORMAT_MESSAGE_FROM_SYSTEM), | |
73 NULL, GetLastError(), | |
74 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), | |
75 errbuf, SDL_arraysize(errbuf), NULL); | |
76 loaderror = errbuf; | |
77 } | |
78 #endif | |
79 | |
80 if (handle == NULL) { | |
81 SDL_SetError("Failed loading %s: %s", sofile, loaderror); | |
82 } | |
83 return (handle); | |
84 } | 48 } |
85 | 49 |
86 void * | 50 void * |
87 SDL_LoadFunction(void *handle, const char *name) | 51 SDL_LoadFunction(void *handle, const char *name) |
88 { | 52 { |
89 void *symbol = NULL; | 53 #ifdef _WIN32_WCE |
90 const char *loaderror = "Unknown error"; | 54 LPTSTR tstr = WIN_UTF8ToString(name); |
91 | 55 void *symbol = (void *) GetProcAddress((HMODULE) handle, tstr); |
92 #if defined(_WIN32_WCE) | 56 SDL_free(tstr); |
93 char errbuf[512]; | 57 #else |
94 int length = SDL_strlen(name); | 58 void *symbol = (void *) GetProcAddress((HMODULE) handle, name); |
95 | |
96 wchar_t *name_t = SDL_malloc((length + 1) * sizeof(wchar_t)); | |
97 wchar_t *errbuf_t = SDL_malloc(512 * sizeof(wchar_t)); | |
98 | |
99 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, name, -1, name_t, length + 1); | |
100 | |
101 symbol = (void *) GetProcAddress((HMODULE) handle, name_t); | |
102 if (symbol == NULL) { | |
103 FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS | | |
104 FORMAT_MESSAGE_FROM_SYSTEM), | |
105 NULL, GetLastError(), | |
106 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), | |
107 errbuf_t, SDL_arraysize(errbuf), NULL); | |
108 WideCharToMultiByte(CP_ACP, 0, errbuf_t, -1, errbuf, 511, NULL, NULL); | |
109 loaderror = errbuf; | |
110 } | |
111 | |
112 SDL_free(name_t); | |
113 SDL_free(errbuf_t); | |
114 | |
115 #else /*if defined(WIN32) */ | |
116 char errbuf[512]; | |
117 | |
118 symbol = (void *) GetProcAddress((HMODULE) handle, name); | |
119 if (symbol == NULL) { | |
120 FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS | | |
121 FORMAT_MESSAGE_FROM_SYSTEM), | |
122 NULL, GetLastError(), | |
123 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), | |
124 errbuf, SDL_arraysize(errbuf), NULL); | |
125 loaderror = errbuf; | |
126 } | |
127 #endif | 59 #endif |
128 | 60 |
129 if (symbol == NULL) { | 61 if (symbol == NULL) { |
130 SDL_SetError("Failed loading %s: %s", name, loaderror); | 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); | |
131 } | 66 } |
132 return (symbol); | 67 return symbol; |
133 } | 68 } |
134 | 69 |
135 void | 70 void |
136 SDL_UnloadObject(void *handle) | 71 SDL_UnloadObject(void *handle) |
137 { | 72 { |