From 6b41c2c5262f2c5c5310c9854df501a6210af023 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 24 Jan 2011 21:20:30 -0800 Subject: [PATCH] Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share. I think this also fixes the bug relating to non-latin characters in filenames, since UNICODE wasn't defined in SDL_rwops.c --- Android.mk | 23 +++--- VisualC/SDL/SDL_VS2008.vcproj | 24 ++++-- VisualC/SDL/SDL_VS2010.vcxproj | 4 +- VisualCE/SDL/SDL.vcproj | 8 ++ src/SDL.c | 3 +- src/SDL_assert.c | 9 +- src/atomic/SDL_spinlock.c | 11 +-- src/audio/android/SDL_androidaudio.c | 2 +- src/audio/windib/SDL_dibaudio.c | 10 +-- src/audio/windx5/SDL_dx5audio.c | 18 ++-- src/audio/windx5/directx.h | 3 +- src/{ => core/android}/SDL_android.cpp | 0 src/{ => core/android}/SDL_android.h | 0 src/core/windows/SDL_windows.c | 41 +++++++++ src/core/windows/SDL_windows.h | 53 ++++++++++++ src/cpuinfo/SDL_cpuinfo.c | 3 +- src/file/SDL_rwops.c | 33 +++----- src/haptic/windows/SDL_syshaptic.c | 15 +++- src/joystick/android/SDL_sysjoystick.c | 2 +- src/joystick/windows/SDL_dxjoystick.c | 14 +++- src/joystick/windows/SDL_dxjoystick_c.h | 3 +- src/joystick/windows/SDL_mmjoystick.c | 3 +- src/loadso/windows/SDL_sysloadso.c | 105 +++++------------------- src/power/windows/SDL_syspower.c | 3 +- src/stdlib/SDL_getenv.c | 11 ++- src/thread/windows/SDL_sysmutex.c | 3 +- src/thread/windows/SDL_syssem.c | 3 +- src/thread/windows/SDL_systhread_c.h | 3 +- src/thread/windows/win_ce_semaphore.c | 3 +- src/timer/wince/SDL_systimer.c | 3 +- src/timer/windows/SDL_systimer.c | 3 +- src/video/android/SDL_androidgl.c | 2 +- src/video/windows/SDL_gapirender.c | 26 +++--- src/video/windows/SDL_windowskeyboard.c | 20 ++--- src/video/windows/SDL_windowsopengl.c | 2 +- src/video/windows/SDL_windowsvideo.c | 47 ++++------- src/video/windows/SDL_windowsvideo.h | 29 ++----- 37 files changed, 273 insertions(+), 272 deletions(-) rename src/{ => core/android}/SDL_android.cpp (100%) rename src/{ => core/android}/SDL_android.h (100%) create mode 100644 src/core/windows/SDL_windows.c create mode 100644 src/core/windows/SDL_windows.h diff --git a/Android.mk b/Android.mk index 12f683b3d..984050699 100755 --- a/Android.mk +++ b/Android.mk @@ -12,30 +12,31 @@ LOCAL_MODULE := SDL LOCAL_C_INCLUDES := $(LOCAL_PATH)/include -LOCAL_SRC_FILES := src/SDL_android.cpp \ +LOCAL_SRC_FILES := \ $(subst $(LOCAL_PATH)/,, \ $(wildcard $(LOCAL_PATH)/src/*.c) \ $(wildcard $(LOCAL_PATH)/src/audio/*.c) \ + $(wildcard $(LOCAL_PATH)/src/audio/android/*.c) \ + $(wildcard $(LOCAL_PATH)/src/audio/dummy/*.c) \ $(LOCAL_PATH)/src/atomic/SDL_atomic.c \ $(LOCAL_PATH)/src/atomic/SDL_spinlock.c.arm \ + $(wildcard $(LOCAL_PATH)/src/core/android/*.cpp) \ $(wildcard $(LOCAL_PATH)/src/cpuinfo/*.c) \ $(wildcard $(LOCAL_PATH)/src/events/*.c) \ $(wildcard $(LOCAL_PATH)/src/file/*.c) \ - $(wildcard $(LOCAL_PATH)/src/joystick/*.c) \ $(wildcard $(LOCAL_PATH)/src/haptic/*.c) \ + $(wildcard $(LOCAL_PATH)/src/haptic/dummy/*.c) \ + $(wildcard $(LOCAL_PATH)/src/joystick/*.c) \ + $(wildcard $(LOCAL_PATH)/src/joystick/android/*.c) \ + $(wildcard $(LOCAL_PATH)/src/loadso/dlopen/*.c)) \ + $(wildcard $(LOCAL_PATH)/src/power/*.c) \ $(wildcard $(LOCAL_PATH)/src/stdlib/*.c) \ $(wildcard $(LOCAL_PATH)/src/thread/*.c) \ - $(wildcard $(LOCAL_PATH)/src/timer/*.c) \ - $(wildcard $(LOCAL_PATH)/src/video/*.c) \ - $(wildcard $(LOCAL_PATH)/src/power/*.c) \ - $(wildcard $(LOCAL_PATH)/src/audio/android/*.c) \ - $(wildcard $(LOCAL_PATH)/src/audio/dummy/*.c) \ - $(wildcard $(LOCAL_PATH)/src/video/android/*.c) \ - $(wildcard $(LOCAL_PATH)/src/joystick/android/*.c) \ - $(wildcard $(LOCAL_PATH)/src/haptic/dummy/*.c) \ $(wildcard $(LOCAL_PATH)/src/thread/pthread/*.c) \ + $(wildcard $(LOCAL_PATH)/src/timer/*.c) \ $(wildcard $(LOCAL_PATH)/src/timer/unix/*.c) \ - $(wildcard $(LOCAL_PATH)/src/loadso/dlopen/*.c)) + $(wildcard $(LOCAL_PATH)/src/video/*.c) \ + $(wildcard $(LOCAL_PATH)/src/video/android/*.c) LOCAL_LDLIBS := -ldl -lGLESv1_CM -llog diff --git a/VisualC/SDL/SDL_VS2008.vcproj b/VisualC/SDL/SDL_VS2008.vcproj index 35fdbc306..71608ed98 100644 --- a/VisualC/SDL/SDL_VS2008.vcproj +++ b/VisualC/SDL/SDL_VS2008.vcproj @@ -1150,6 +1150,22 @@ RelativePath="..\..\src\audio\SDL_wave.h" > + + + + + + + + @@ -1230,14 +1246,6 @@ RelativePath="..\..\src\video\windows\SDL_windowswindow.h" > - - - - diff --git a/VisualC/SDL/SDL_VS2010.vcxproj b/VisualC/SDL/SDL_VS2010.vcxproj index cf3a604cc..d0bd7263f 100644 --- a/VisualC/SDL/SDL_VS2010.vcxproj +++ b/VisualC/SDL/SDL_VS2010.vcxproj @@ -272,6 +272,7 @@ echo #define SDL_REVISION 0 >"$(ProjectDir)\..\..\include\SDL_revision.h" + @@ -345,6 +346,7 @@ echo #define SDL_REVISION 0 >"$(ProjectDir)\..\..\include\SDL_revision.h" + @@ -460,4 +462,4 @@ echo #define SDL_REVISION 0 >"$(ProjectDir)\..\..\include\SDL_revision.h" - + \ No newline at end of file diff --git a/VisualCE/SDL/SDL.vcproj b/VisualCE/SDL/SDL.vcproj index ca83d77ac..3e6c09e2d 100644 --- a/VisualCE/SDL/SDL.vcproj +++ b/VisualCE/SDL/SDL.vcproj @@ -1053,6 +1053,10 @@ RelativePath="..\..\src\events\SDL_windowevents.c" > + + @@ -1358,6 +1362,10 @@ RelativePath="..\..\src\events\SDL_windowevents_c.h" > + + diff --git a/src/SDL.c b/src/SDL.c index 49620a8e1..cfd73f792 100644 --- a/src/SDL.c +++ b/src/SDL.c @@ -329,8 +329,7 @@ SDL_GetPlatform() #if !defined(HAVE_LIBC) || (defined(__WATCOMC__) && defined(BUILD_DLL)) /* Need to include DllMain() on Watcom C for some reason.. */ -#define WIN32_LEAN_AND_MEAN -#include +#include "core/windows/SDL_windows.h" BOOL APIENTRY _DllMainCRTStartup(HANDLE hModule, diff --git a/src/SDL_assert.c b/src/SDL_assert.c index 38ee92560..4af552908 100644 --- a/src/SDL_assert.c +++ b/src/SDL_assert.c @@ -27,18 +27,11 @@ #include "video/SDL_sysvideo.h" #ifdef __WIN32__ -#define WIN32_LEAN_AND_MEAN -#include +#include "core/windows/SDL_windows.h" #ifndef WS_OVERLAPPEDWINDOW #define WS_OVERLAPPEDWINDOW 0 #endif - -#ifdef UNICODE -#define WIN_UTF8ToString(S) (WCHAR *)SDL_iconv_string("UCS-2", "UTF-8", (char *)S, SDL_strlen(S)+1) -#else -#define WIN_UTF8ToString(S) SDL_iconv_string("ASCII", "UTF-8", (char *)S, SDL_strlen(S)+1) -#endif #else /* fprintf, _exit(), etc. */ #include #include diff --git a/src/atomic/SDL_spinlock.c b/src/atomic/SDL_spinlock.c index 9d9a136d9..b28b696ae 100644 --- a/src/atomic/SDL_spinlock.c +++ b/src/atomic/SDL_spinlock.c @@ -25,14 +25,7 @@ #include "SDL_timer.h" /* Don't do the check for Visual Studio 2005, it's safe here */ -#if defined(_MSC_VER) -#ifdef _WIN32_WCE -#define WIN32_LEAN_AND_MEAN -#include -#else -#include -#endif -#endif /* _MSC_VER */ +#include "../core/windows/SDL_windows.h" /* This function is where all the magic happens... */ SDL_bool @@ -40,7 +33,7 @@ SDL_AtomicTryLock(SDL_SpinLock *lock) { #if defined(_MSC_VER) SDL_COMPILE_TIME_ASSERT(locksize, sizeof(*lock) == sizeof(long)); - return (_InterlockedExchange((long*)lock, 1) == 0); + return (InterlockedExchange((long*)lock, 1) == 0); #elif defined(__MACOSX__) return OSAtomicCompareAndSwap32Barrier(0, 1, lock); diff --git a/src/audio/android/SDL_androidaudio.c b/src/audio/android/SDL_androidaudio.c index 5f62339da..cdb39eb0d 100644 --- a/src/audio/android/SDL_androidaudio.c +++ b/src/audio/android/SDL_androidaudio.c @@ -27,7 +27,7 @@ #include "../SDL_audio_c.h" #include "SDL_androidaudio.h" -#include "../../SDL_android.h" +#include "../../core/android/SDL_android.h" #include diff --git a/src/audio/windib/SDL_dibaudio.c b/src/audio/windib/SDL_dibaudio.c index 7640c5eee..aee271213 100644 --- a/src/audio/windib/SDL_dibaudio.c +++ b/src/audio/windib/SDL_dibaudio.c @@ -23,8 +23,7 @@ /* Allow access to a raw mixing buffer */ -#define WIN32_LEAN_AND_MEAN -#include +#include "../../core/windows/SDL_windows.h" #include #include "SDL_timer.h" @@ -67,21 +66,14 @@ SetMMerror(char *function, MMRESULT code) { size_t len; char errbuf[MAXERRORLENGTH]; -#ifdef _WIN32_WCE wchar_t werrbuf[MAXERRORLENGTH]; -#endif SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: ", function); len = SDL_strlen(errbuf); -#ifdef _WIN32_WCE - /* UNICODE version */ waveOutGetErrorText(code, werrbuf, MAXERRORLENGTH - len); WideCharToMultiByte(CP_ACP, 0, werrbuf, -1, errbuf + len, MAXERRORLENGTH - len, NULL, NULL); -#else - waveOutGetErrorText(code, errbuf + len, (UINT) (MAXERRORLENGTH - len)); -#endif SDL_SetError("%s", errbuf); } diff --git a/src/audio/windx5/SDL_dx5audio.c b/src/audio/windx5/SDL_dx5audio.c index c583b3e63..7066d82eb 100644 --- a/src/audio/windx5/SDL_dx5audio.c +++ b/src/audio/windx5/SDL_dx5audio.c @@ -24,6 +24,7 @@ /* Allow access to a raw mixing buffer */ #include "SDL_timer.h" +#include "SDL_loadso.h" #include "SDL_audio.h" #include "../SDL_audio_c.h" #include "SDL_dx5audio.h" @@ -38,19 +39,19 @@ #endif /* DirectX function pointers for audio */ -static HINSTANCE DSoundDLL = NULL; +static void* DSoundDLL = NULL; static HRESULT(WINAPI * DSoundCreate) (LPGUID, LPDIRECTSOUND *, LPUNKNOWN) = NULL; static void DSOUND_Unload(void) { + DSoundCreate = NULL; + if (DSoundDLL != NULL) { - FreeLibrary(DSoundDLL); + SDL_UnloadObject(DSoundDLL); + DSoundDLL = NULL; } - - DSoundCreate = NULL; - DSoundDLL = NULL; } @@ -61,17 +62,16 @@ DSOUND_Load(void) DSOUND_Unload(); - DSoundDLL = LoadLibrary(TEXT("DSOUND.DLL")); + DSoundDLL = SDL_LoadObject("DSOUND.DLL"); if (DSoundDLL == NULL) { SDL_SetError("DirectSound: failed to load DSOUND.DLL"); } else { /* Now make sure we have DirectX 5 or better... */ /* (DirectSoundCaptureCreate was added in DX5) */ - if (!GetProcAddress(DSoundDLL, TEXT("DirectSoundCaptureCreate"))) { + if (!SDL_LoadFunction(DSoundDLL, "DirectSoundCaptureCreate")) { SDL_SetError("DirectSound: System doesn't appear to have DX5."); } else { - DSoundCreate = (void *) GetProcAddress(DSoundDLL, - TEXT("DirectSoundCreate")); + DSoundCreate = SDL_LoadFunction(DSoundDLL, "DirectSoundCreate"); } if (!DSoundCreate) { diff --git a/src/audio/windx5/directx.h b/src/audio/windx5/directx.h index c283f6bc4..1c371f953 100644 --- a/src/audio/windx5/directx.h +++ b/src/audio/windx5/directx.h @@ -4,8 +4,7 @@ /* Include all of the DirectX 5.0 headers and adds any necessary tweaks */ -#define WIN32_LEAN_AND_MEAN -#include +#include "../../core/windows/SDL_windows.h" #include #ifndef WIN32 #define WIN32 diff --git a/src/SDL_android.cpp b/src/core/android/SDL_android.cpp similarity index 100% rename from src/SDL_android.cpp rename to src/core/android/SDL_android.cpp diff --git a/src/SDL_android.h b/src/core/android/SDL_android.h similarity index 100% rename from src/SDL_android.h rename to src/core/android/SDL_android.h diff --git a/src/core/windows/SDL_windows.c b/src/core/windows/SDL_windows.c new file mode 100644 index 000000000..cadf9ce97 --- /dev/null +++ b/src/core/windows/SDL_windows.c @@ -0,0 +1,41 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2010 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#include "SDL_error.h" +#include "SDL_windows.h" + + +/* Sets an error message based on GetLastError() */ +void +WIN_SetError(const char *prefix) +{ + TCHAR buffer[1024]; + char *message; + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, + buffer, SDL_arraysize(buffer), NULL); + message = WIN_StringToUTF8(buffer); + SDL_SetError("%s%s%s", prefix ? prefix : "", prefix ? ": " : "", message); + SDL_free(message); +} + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/core/windows/SDL_windows.h b/src/core/windows/SDL_windows.h new file mode 100644 index 000000000..601fc5b11 --- /dev/null +++ b/src/core/windows/SDL_windows.h @@ -0,0 +1,53 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2010 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/* This is an include file for windows.h with the SDL build settings */ + +#ifndef _INCLUDED_WINDOWS_H +#define _INCLUDED_WINDOWS_H + +#define WIN32_LEAN_AND_MEAN +#define STRICT +#ifndef UNICODE +#define UNICODE 1 +#endif +#undef WINVER +#define WINVER 0x500 /* Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices() */ + +#include + + +/* Routines to convert from UTF8 to native Windows text */ +#if UNICODE +#define WIN_StringToUTF8(S) SDL_iconv_string("UTF-8", "UCS-2", (char *)(S), (SDL_wcslen(S)+1)*sizeof(WCHAR)) +#define WIN_UTF8ToString(S) (WCHAR *)SDL_iconv_string("UCS-2", "UTF-8", (char *)(S), SDL_strlen(S)+1) +#else +#define WIN_StringToUTF8(S) SDL_iconv_string("UTF-8", "ASCII", (char *)(S), (SDL_strlen(S)+1)) +#define WIN_UTF8ToString(S) SDL_iconv_string("ASCII", "UTF-8", (char *)(S), SDL_strlen(S)+1) +#endif + +/* Sets an error message based on GetLastError() */ +extern void WIN_SetError(const char *prefix); + +#endif /* _INCLUDED_WINDOWS_H */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/cpuinfo/SDL_cpuinfo.c b/src/cpuinfo/SDL_cpuinfo.c index 7fa382818..3444f2fad 100644 --- a/src/cpuinfo/SDL_cpuinfo.c +++ b/src/cpuinfo/SDL_cpuinfo.c @@ -39,8 +39,7 @@ #include #endif #ifdef __WIN32__ -#define WIN32_LEAN_AND_MEAN -#include +#include "../core/windows/SDL_windows.h" #endif #define CPU_HAS_RDTSC 0x00000001 diff --git a/src/file/SDL_rwops.c b/src/file/SDL_rwops.c index 6548403f0..5ea6bc753 100644 --- a/src/file/SDL_rwops.c +++ b/src/file/SDL_rwops.c @@ -44,8 +44,7 @@ faster, and all stdio functions anyway are embedded in coredll.dll - the main wince dll*/ -#define WINDOWS_LEAN_AND_MEAN -#include +#include "../core/windows/SDL_windows.h" #ifndef INVALID_SET_FILE_POINTER #define INVALID_SET_FILE_POINTER 0xFFFFFFFF @@ -98,34 +97,28 @@ windows_file_open(SDL_RWops * context, const char *filename, const char *mode) } #ifdef _WIN32_WCE { - size_t size = SDL_strlen(filename) + 1; - wchar_t *filenameW = SDL_stack_alloc(wchar_t, size); - - if (MultiByteToWideChar(CP_UTF8, 0, filename, -1, filenameW, size) == - 0) { - SDL_stack_free(filenameW); - SDL_free(context->hidden.windowsio.buffer.data); - context->hidden.windowsio.buffer.data = NULL; - SDL_SetError("Unable to convert filename to Unicode"); - return -1; - } - h = CreateFile(filenameW, (w_right | r_right), + LPTSTR tstr = WIN_UTF8ToString(filename); + h = CreateFile(tstr, (w_right | r_right), (w_right) ? 0 : FILE_SHARE_READ, NULL, (must_exist | truncate | a_mode), FILE_ATTRIBUTE_NORMAL, NULL); - SDL_stack_free(filenameW); + SDL_free(tstr); } #else /* Do not open a dialog box if failure */ old_error_mode = SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS); - h = CreateFile(filename, (w_right | r_right), - (w_right) ? 0 : FILE_SHARE_READ, NULL, - (must_exist | truncate | a_mode), FILE_ATTRIBUTE_NORMAL, - NULL); + { + LPTSTR tstr = WIN_UTF8ToString(filename); + h = CreateFile(tstr, (w_right | r_right), + (w_right) ? 0 : FILE_SHARE_READ, NULL, + (must_exist | truncate | a_mode), + FILE_ATTRIBUTE_NORMAL, NULL); + SDL_free(tstr); + } - /* restore old behaviour */ + /* restore old behavior */ SetErrorMode(old_error_mode); #endif /* _WIN32_WCE */ diff --git a/src/haptic/windows/SDL_syshaptic.c b/src/haptic/windows/SDL_syshaptic.c index 504479acf..a41f684b2 100644 --- a/src/haptic/windows/SDL_syshaptic.c +++ b/src/haptic/windows/SDL_syshaptic.c @@ -39,6 +39,7 @@ static struct { DIDEVICEINSTANCE instance; + char *name; SDL_Haptic *haptic; DIDEVCAPS capabilities; } SDL_hapticlist[MAX_HAPTICS]; @@ -220,6 +221,9 @@ EnumHapticsCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext) return DIENUM_CONTINUE; } + /* Copy the name */ + SDL_hapticlist[SDL_numhaptics].name = WIN_StringToUTF8(SDL_hapticlist[SDL_numhaptics].instance.tszProductName); + /* Close up device and count it. */ IDirectInputDevice_Release(device); SDL_numhaptics++; @@ -238,7 +242,7 @@ EnumHapticsCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext) const char * SDL_SYS_HapticName(int index) { - return SDL_hapticlist[index].instance.tszProductName; + return SDL_hapticlist[index].name; } @@ -630,6 +634,15 @@ SDL_SYS_HapticClose(SDL_Haptic * haptic) void SDL_SYS_HapticQuit(void) { + int i; + + for (i = 0; i < SDL_arraysize(SDL_hapticlist); ++i) { + if (SDL_hapticlist[i].name) { + SDL_free(SDL_hapticlist[i].name); + SDL_hapticlist[i].name = NULL; + } + } + IDirectInput_Release(dinput); dinput = NULL; } diff --git a/src/joystick/android/SDL_sysjoystick.c b/src/joystick/android/SDL_sysjoystick.c index 58d346243..578449286 100644 --- a/src/joystick/android/SDL_sysjoystick.c +++ b/src/joystick/android/SDL_sysjoystick.c @@ -32,7 +32,7 @@ #include "SDL_joystick.h" #include "../SDL_sysjoystick.h" #include "../SDL_joystick_c.h" -#include "../../SDL_android.h" +#include "../../core/android/SDL_android.h" static const char *accelerometerName = "Android accelerometer"; diff --git a/src/joystick/windows/SDL_dxjoystick.c b/src/joystick/windows/SDL_dxjoystick.c index d9ddaa3b2..995fb6e2d 100644 --- a/src/joystick/windows/SDL_dxjoystick.c +++ b/src/joystick/windows/SDL_dxjoystick.c @@ -63,6 +63,7 @@ extern HRESULT(WINAPI * DInputCreate) (HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUT * ppDI, LPUNKNOWN punkOuter); static DIDEVICEINSTANCE SYS_Joystick[MAX_JOYSTICKS]; /* array to hold joystick ID values */ +static char *SYS_JoystickNames[MAX_JOYSTICKS]; static int SYS_NumJoysticks; static HINSTANCE DInputDLL = NULL; @@ -326,6 +327,7 @@ EnumJoysticksCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext) { SDL_memcpy(&SYS_Joystick[SYS_NumJoysticks], pdidInstance, sizeof(DIDEVICEINSTANCE)); + SYS_JoystickNames[SYS_NumJoysticks] = WIN_StringToUTF8(pdidInstance->tszProductName); SYS_NumJoysticks++; if (SYS_NumJoysticks >= MAX_JOYSTICKS) @@ -338,8 +340,7 @@ EnumJoysticksCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext) const char * SDL_SYS_JoystickName(int index) { - /***-> test for invalid index ? */ - return (SYS_Joystick[index].tszProductName); + return SYS_JoystickNames[index]; } /* Function to open a joystick for use. @@ -793,6 +794,15 @@ SDL_SYS_JoystickClose(SDL_Joystick * joystick) void SDL_SYS_JoystickQuit(void) { + int i; + + for (i = 0; i < SDL_arraysize(SYS_JoystickNames); ++i) { + if (SYS_JoystickNames[i]) { + SDL_free(SYS_JoystickNames[i]); + SYS_JoystickNames[i] = NULL; + } + } + IDirectInput_Release(dinput); dinput = NULL; } diff --git a/src/joystick/windows/SDL_dxjoystick_c.h b/src/joystick/windows/SDL_dxjoystick_c.h index 847b168b6..039cf825d 100644 --- a/src/joystick/windows/SDL_dxjoystick_c.h +++ b/src/joystick/windows/SDL_dxjoystick_c.h @@ -33,8 +33,7 @@ * with polled devices, and it's fine to call IDirectInputDevice2_GetDeviceData and * let it return 0 events. */ -#define WIN32_LEAN_AND_MEAN -#include +#include "../../core/windows/SDL_windows.h" #define DIRECTINPUT_VERSION 0x0700 /* Need version 7 for force feedback. */ #include diff --git a/src/joystick/windows/SDL_mmjoystick.c b/src/joystick/windows/SDL_mmjoystick.c index bcfc83f69..570e91ada 100644 --- a/src/joystick/windows/SDL_mmjoystick.c +++ b/src/joystick/windows/SDL_mmjoystick.c @@ -25,8 +25,7 @@ /* Win32 MultiMedia Joystick driver, contributed by Andrei de A. Formiga */ -#define WIN32_LEAN_AND_MEAN -#include +#include "../../core/windows/SDL_windows.h" #include #include diff --git a/src/loadso/windows/SDL_sysloadso.c b/src/loadso/windows/SDL_sysloadso.c index 061243429..e8ec3337e 100644 --- a/src/loadso/windows/SDL_sysloadso.c +++ b/src/loadso/windows/SDL_sysloadso.c @@ -26,110 +26,45 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* System dependent library loading routines */ -#define WIN32_LEAN_AND_MEAN -#include +#include "../../core/windows/SDL_windows.h" #include "SDL_loadso.h" void * SDL_LoadObject(const char *sofile) { - void *handle = NULL; - const char *loaderror = "Unknown error"; - -#if defined(_WIN32_WCE) - char errbuf[512]; - - wchar_t *errbuf_t = SDL_malloc(512 * sizeof(wchar_t)); - wchar_t *sofile_t = SDL_malloc((MAX_PATH + 1) * sizeof(wchar_t)); - - MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, sofile, -1, sofile_t, - MAX_PATH); - handle = (void *) LoadLibrary(sofile_t); + LPTSTR tstr = WIN_UTF8ToString(sofile); + void *handle = (void *) LoadLibrary(tstr); + SDL_free(tstr); /* Generate an error message if all loads failed */ if (handle == NULL) { - FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS | - FORMAT_MESSAGE_FROM_SYSTEM), - NULL, GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - errbuf_t, SDL_arraysize(errbuf), NULL); - WideCharToMultiByte(CP_ACP, 0, errbuf_t, -1, errbuf, 511, NULL, NULL); - loaderror = errbuf; + char errbuf[512]; + SDL_strlcpy(errbuf, "Failed loading ", SDL_arraysize(errbuf)); + SDL_strlcat(errbuf, sofile, SDL_arraysize(errbuf)); + WIN_SetError(errbuf); } - - SDL_free(sofile_t); - SDL_free(errbuf_t); - -#else /*if defined(__WIN32__) */ - char errbuf[512]; - - handle = (void *) LoadLibrary(sofile); - - /* Generate an error message if all loads failed */ - if (handle == NULL) { - FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS | - FORMAT_MESSAGE_FROM_SYSTEM), - NULL, GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - errbuf, SDL_arraysize(errbuf), NULL); - loaderror = errbuf; - } -#endif - - if (handle == NULL) { - SDL_SetError("Failed loading %s: %s", sofile, loaderror); - } - return (handle); + return handle; } void * SDL_LoadFunction(void *handle, const char *name) { - void *symbol = NULL; - const char *loaderror = "Unknown error"; - -#if defined(_WIN32_WCE) - char errbuf[512]; - int length = SDL_strlen(name); - - wchar_t *name_t = SDL_malloc((length + 1) * sizeof(wchar_t)); - wchar_t *errbuf_t = SDL_malloc(512 * sizeof(wchar_t)); - - MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, name, -1, name_t, length + 1); - - symbol = (void *) GetProcAddress((HMODULE) handle, name_t); - if (symbol == NULL) { - FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS | - FORMAT_MESSAGE_FROM_SYSTEM), - NULL, GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - errbuf_t, SDL_arraysize(errbuf), NULL); - WideCharToMultiByte(CP_ACP, 0, errbuf_t, -1, errbuf, 511, NULL, NULL); - loaderror = errbuf; - } - - SDL_free(name_t); - SDL_free(errbuf_t); - -#else /*if defined(WIN32) */ - char errbuf[512]; - - symbol = (void *) GetProcAddress((HMODULE) handle, name); - if (symbol == NULL) { - FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS | - FORMAT_MESSAGE_FROM_SYSTEM), - NULL, GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - errbuf, SDL_arraysize(errbuf), NULL); - loaderror = errbuf; - } +#ifdef _WIN32_WCE + LPTSTR tstr = WIN_UTF8ToString(name); + void *symbol = (void *) GetProcAddress((HMODULE) handle, tstr); + SDL_free(tstr); +#else + void *symbol = (void *) GetProcAddress((HMODULE) handle, name); #endif if (symbol == NULL) { - SDL_SetError("Failed loading %s: %s", name, loaderror); + char errbuf[512]; + SDL_strlcpy(errbuf, "Failed loading ", SDL_arraysize(errbuf)); + SDL_strlcat(errbuf, name, SDL_arraysize(errbuf)); + WIN_SetError(errbuf); } - return (symbol); + return symbol; } void diff --git a/src/power/windows/SDL_syspower.c b/src/power/windows/SDL_syspower.c index a5e23e7fa..e85243522 100644 --- a/src/power/windows/SDL_syspower.c +++ b/src/power/windows/SDL_syspower.c @@ -24,8 +24,7 @@ #ifndef SDL_POWER_DISABLED #ifdef SDL_POWER_WINDOWS -#define WIN32_LEAN_AND_MEAN -#include +#include "../../core/windows/SDL_windows.h" #include "SDL_power.h" diff --git a/src/stdlib/SDL_getenv.c b/src/stdlib/SDL_getenv.c index 387531a88..851673032 100644 --- a/src/stdlib/SDL_getenv.c +++ b/src/stdlib/SDL_getenv.c @@ -27,8 +27,7 @@ #if defined(__WIN32__) && !defined(_WIN32_WCE) -#define WIN32_LEAN_AND_MEAN -#include +#include "../core/windows/SDL_windows.h" /* Note this isn't thread-safe! */ @@ -41,12 +40,12 @@ SDL_setenv(const char *name, const char *value, int overwrite) { if (!overwrite) { char ch = 0; - const size_t len = GetEnvironmentVariable(name, &ch, sizeof (ch)); + const size_t len = GetEnvironmentVariableA(name, &ch, sizeof (ch)); if (len > 0) { return 0; /* asked not to overwrite existing value. */ } } - if (!SetEnvironmentVariable(name, *value ? value : NULL)) { + if (!SetEnvironmentVariableA(name, *value ? value : NULL)) { return -1; } return 0; @@ -59,7 +58,7 @@ SDL_getenv(const char *name) size_t bufferlen; bufferlen = - GetEnvironmentVariable(name, SDL_envmem, (DWORD) SDL_envmemlen); + GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen); if (bufferlen == 0) { return NULL; } @@ -70,7 +69,7 @@ SDL_getenv(const char *name) } SDL_envmem = newmem; SDL_envmemlen = bufferlen; - GetEnvironmentVariable(name, SDL_envmem, (DWORD) SDL_envmemlen); + GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen); } return SDL_envmem; } diff --git a/src/thread/windows/SDL_sysmutex.c b/src/thread/windows/SDL_sysmutex.c index d0f1c8556..820390359 100644 --- a/src/thread/windows/SDL_sysmutex.c +++ b/src/thread/windows/SDL_sysmutex.c @@ -23,8 +23,7 @@ /* Mutex functions using the Win32 API */ -#define WIN32_LEAN_AND_MEAN -#include +#include "../../core/windows/SDL_windows.h" #include "SDL_mutex.h" diff --git a/src/thread/windows/SDL_syssem.c b/src/thread/windows/SDL_syssem.c index 9673ee898..799dac04b 100644 --- a/src/thread/windows/SDL_syssem.c +++ b/src/thread/windows/SDL_syssem.c @@ -23,8 +23,7 @@ /* Semaphore functions using the Win32 API */ -#define WIN32_LEAN_AND_MEAN -#include +#include "../../core/windows/SDL_windows.h" #include "SDL_thread.h" #if defined(_WIN32_WCE) && (_WIN32_WCE < 300) diff --git a/src/thread/windows/SDL_systhread_c.h b/src/thread/windows/SDL_systhread_c.h index 675e821c9..1a9a554a2 100644 --- a/src/thread/windows/SDL_systhread_c.h +++ b/src/thread/windows/SDL_systhread_c.h @@ -21,8 +21,7 @@ */ #include "SDL_config.h" -#define WIN32_LEAN_AND_MEAN -#include +#include "../../core/windows/SDL_windows.h" typedef HANDLE SYS_ThreadHandle; diff --git a/src/thread/windows/win_ce_semaphore.c b/src/thread/windows/win_ce_semaphore.c index a44fc34f5..62072f562 100644 --- a/src/thread/windows/win_ce_semaphore.c +++ b/src/thread/windows/win_ce_semaphore.c @@ -28,8 +28,7 @@ and it is not clear how to handle a mixture of WCE semaphores and normal events and mutexes. */ -#define WIN32_LEAN_AND_MEAN -#include +#include "../../core/windows/SDL_windows.h" #include "win_ce_semaphore.h" diff --git a/src/timer/wince/SDL_systimer.c b/src/timer/wince/SDL_systimer.c index 8ecb71416..5abbaa587 100644 --- a/src/timer/wince/SDL_systimer.c +++ b/src/timer/wince/SDL_systimer.c @@ -23,8 +23,7 @@ #ifdef SDL_TIMER_WINCE -#define WIN32_LEAN_AND_MEAN -#include +#include "../../core/windows/SDL_windows.h" #include #include "SDL_thread.h" diff --git a/src/timer/windows/SDL_systimer.c b/src/timer/windows/SDL_systimer.c index 083a88040..0ae01da10 100644 --- a/src/timer/windows/SDL_systimer.c +++ b/src/timer/windows/SDL_systimer.c @@ -23,8 +23,7 @@ #ifdef SDL_TIMER_WINDOWS -#define WIN32_LEAN_AND_MEAN -#include +#include "../../core/windows/SDL_windows.h" #include #include "SDL_timer.h" diff --git a/src/video/android/SDL_androidgl.c b/src/video/android/SDL_androidgl.c index 27f1665d5..715d12123 100644 --- a/src/video/android/SDL_androidgl.c +++ b/src/video/android/SDL_androidgl.c @@ -26,7 +26,7 @@ #include "SDL_video.h" #include "SDL_androidvideo.h" -#include "../../SDL_android.h" +#include "../../core/android/SDL_android.h" #include diff --git a/src/video/windows/SDL_gapirender.c b/src/video/windows/SDL_gapirender.c index a0485aea6..456f3e37f 100644 --- a/src/video/windows/SDL_gapirender.c +++ b/src/video/windows/SDL_gapirender.c @@ -78,7 +78,7 @@ typedef int (*PFNGXResume)(); typedef struct { // gx.dll - HMODULE hGapiLib; + void* hGapiLib; PFNGXOpenDisplay GXOpenDisplay; PFNGXCloseDisplay GXCloseDisplay; PFNGXBeginDraw GXBeginDraw; @@ -251,7 +251,7 @@ SDL_RenderDriver RAW_RenderDriver = { int WINCE_Available(void) { - HMODULE render_gapi; + void* render_gapi; const char* preferably = SDL_getenv("SDL_VIDEO_RENDERER"); // raw check @@ -267,10 +267,10 @@ int WINCE_Available(void) if(preferably && 0 == SDL_strcasecmp(preferably, RAW_RENDER_NAME)) return 0 != render_raw; // gapi check - render_gapi = LoadLibrary(TEXT("\\Windows\\gx.dll")); + render_gapi = SDL_LoadObject("\\Windows\\gx.dll"); if(0 == render_gapi) - render_gapi = LoadLibrary(TEXT("gx.dll")); - FreeLibrary(render_gapi); + render_gapi = SDL_LoadObject("gx.dll"); + SDL_UnloadObject(render_gapi); if(preferably && 0 == SDL_strcasecmp(preferably, GAPI_RENDER_NAME)) return 0 != render_gapi; @@ -280,7 +280,7 @@ int WINCE_Available(void) void WINCE_AddRenderDriver(_THIS) { HDC hdc; - HMODULE render_gapi; + void* render_gapi; int render_raw, ii; const char* preferably = SDL_getenv("SDL_VIDEO_RENDERER"); @@ -295,12 +295,12 @@ void WINCE_AddRenderDriver(_THIS) render_raw = 1; // gapi check - render_gapi = LoadLibrary(TEXT("\\Windows\\gx.dll")); + render_gapi = SDL_LoadObject("\\Windows\\gx.dll"); if(0 == render_gapi) - render_gapi = LoadLibrary(TEXT("gx.dll")); + render_gapi = SDL_LoadObject("gx.dll"); if(render_gapi) - FreeLibrary(render_gapi); + SDL_UnloadObject(render_gapi); for(ii = 0; ii < _this->num_displays; ++ii) { @@ -885,15 +885,15 @@ int GAPI_Init(WINCE_RenderData* data, HWND hwnd) return 0; } - data->gapi->hGapiLib = LoadLibrary(TEXT("\\Windows\\gx.dll")); + data->gapi->hGapiLib = SDL_LoadObject("\\Windows\\gx.dll"); if(0 == data->gapi->hGapiLib) { - data->gapi->hGapiLib = LoadLibrary(TEXT("gx.dll")); + data->gapi->hGapiLib = SDL_LoadObject("gx.dll"); if(0 == data->gapi->hGapiLib) return 0; } // load gapi library -#define LINK(type,name,import) name=(PFN##type)GetProcAddress(data->gapi->hGapiLib,TEXT(import)) +#define LINK(type,name,import) name=(PFN##type)SDL_LoadFunction(data->gapi->hGapiLib,import) LINK(GXOpenDisplay, data->gapi->GXOpenDisplay, "?GXOpenDisplay@@YAHPAUHWND__@@K@Z"); LINK(GXCloseDisplay, data->gapi->GXCloseDisplay, "?GXCloseDisplay@@YAHXZ"); LINK(GXBeginDraw, data->gapi->GXBeginDraw, "?GXBeginDraw@@YAPAXXZ"); @@ -1005,7 +1005,7 @@ void GAPI_Quit(WINCE_RenderData* data) if(data->gapi) { if(data->gapi->GXCloseDisplay) data->gapi->GXCloseDisplay(); - if(data->gapi->hGapiLib) FreeLibrary(data->gapi->hGapiLib); + if(data->gapi->hGapiLib) SDL_UnloadObject(data->gapi->hGapiLib); SDL_free(data->gapi); data->gapi = NULL; diff --git a/src/video/windows/SDL_windowskeyboard.c b/src/video/windows/SDL_windowskeyboard.c index 45fd8284e..d82696520 100644 --- a/src/video/windows/SDL_windowskeyboard.c +++ b/src/video/windows/SDL_windowskeyboard.c @@ -312,15 +312,15 @@ IME_Init(SDL_VideoData *videodata, HWND hwnd) CoCreateInstance(&CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, &IID_ITfThreadMgr, (LPVOID *)&videodata->ime_threadmgr); } videodata->ime_initialized = SDL_TRUE; - videodata->ime_himm32 = LoadLibraryA("imm32.dll"); + videodata->ime_himm32 = SDL_LoadObject("imm32.dll"); if (!videodata->ime_himm32) { videodata->ime_available = SDL_FALSE; return; } - videodata->ImmLockIMC = (LPINPUTCONTEXT2 (WINAPI *)(HIMC))GetProcAddress(videodata->ime_himm32, "ImmLockIMC"); - videodata->ImmUnlockIMC = (BOOL (WINAPI *)(HIMC))GetProcAddress(videodata->ime_himm32, "ImmUnlockIMC"); - videodata->ImmLockIMCC = (LPVOID (WINAPI *)(HIMCC))GetProcAddress(videodata->ime_himm32, "ImmLockIMCC"); - videodata->ImmUnlockIMCC = (BOOL (WINAPI *)(HIMCC))GetProcAddress(videodata->ime_himm32, "ImmUnlockIMCC"); + videodata->ImmLockIMC = (LPINPUTCONTEXT2 (WINAPI *)(HIMC))SDL_LoadFunction(videodata->ime_himm32, "ImmLockIMC"); + videodata->ImmUnlockIMC = (BOOL (WINAPI *)(HIMC))SDL_LoadFunction(videodata->ime_himm32, "ImmUnlockIMC"); + videodata->ImmLockIMCC = (LPVOID (WINAPI *)(HIMCC))SDL_LoadFunction(videodata->ime_himm32, "ImmLockIMCC"); + videodata->ImmUnlockIMCC = (BOOL (WINAPI *)(HIMCC))SDL_LoadFunction(videodata->ime_himm32, "ImmUnlockIMCC"); IME_SetWindow(videodata, hwnd); videodata->ime_himc = ImmGetContext(hwnd); @@ -383,7 +383,7 @@ IME_Quit(SDL_VideoData *videodata) videodata->ime_hwnd_main = 0; videodata->ime_himc = 0; if (videodata->ime_himm32) { - FreeLibrary(videodata->ime_himm32); + SDL_UnloadObject(videodata->ime_himm32); videodata->ime_himm32 = 0; } if (videodata->ime_threadmgr) { @@ -606,7 +606,7 @@ static void IME_SetupAPI(SDL_VideoData *videodata) { char ime_file[MAX_PATH + 1]; - HMODULE hime = 0; + void* hime = 0; HKL hkl = 0; videodata->GetReadingString = 0; videodata->ShowReadingWindow = 0; @@ -617,14 +617,14 @@ IME_SetupAPI(SDL_VideoData *videodata) if (ImmGetIMEFileNameA(hkl, ime_file, sizeof(ime_file) - 1) <= 0) return; - hime = LoadLibraryA(ime_file); + hime = SDL_LoadObject(ime_file); if (!hime) return; videodata->GetReadingString = (UINT (WINAPI *)(HIMC, UINT, LPWSTR, PINT, BOOL*, PUINT)) - GetProcAddress(hime, "GetReadingString"); + SDL_LoadFunction(hime, "GetReadingString"); videodata->ShowReadingWindow = (BOOL (WINAPI *)(HIMC, BOOL)) - GetProcAddress(hime, "ShowReadingWindow"); + SDL_LoadFunction(hime, "ShowReadingWindow"); if (videodata->ShowReadingWindow) { HIMC himc = ImmGetContext(videodata->ime_hwnd_current); diff --git a/src/video/windows/SDL_windowsopengl.c b/src/video/windows/SDL_windowsopengl.c index 0de7414be..950c35a4b 100644 --- a/src/video/windows/SDL_windowsopengl.c +++ b/src/video/windows/SDL_windowsopengl.c @@ -101,7 +101,7 @@ WIN_GL_LoadLibrary(_THIS, const char *path) !_this->gl_data->wglDeleteContext || !_this->gl_data->wglMakeCurrent) { SDL_SetError("Could not retrieve OpenGL functions"); - FreeLibrary(handle); + SDL_UnloadObject(handle); return -1; } diff --git a/src/video/windows/SDL_windowsvideo.c b/src/video/windows/SDL_windowsvideo.c index 193f2d166..0cc2fc8bc 100644 --- a/src/video/windows/SDL_windowsvideo.c +++ b/src/video/windows/SDL_windowsvideo.c @@ -37,19 +37,6 @@ static int WIN_VideoInit(_THIS); static void WIN_VideoQuit(_THIS); -/* Sets an error message based on GetLastError() */ -void -WIN_SetError(const char *prefix) -{ - TCHAR buffer[1024]; - char *message; - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, - buffer, SDL_arraysize(buffer), NULL); - message = WIN_StringToUTF8(buffer); - SDL_SetError("%s%s%s", prefix ? prefix : "", prefix ? ": " : "", message); - SDL_free(message); -} - /* Windows driver bootstrap functions */ @@ -68,22 +55,22 @@ WIN_DeleteDevice(SDL_VideoDevice * device) #if SDL_VIDEO_RENDER_D3D if (data->d3d) { IDirect3D9_Release(data->d3d); - FreeLibrary(data->d3dDLL); + SDL_UnloadObject(data->d3dDLL); } #endif #if SDL_VIDEO_RENDER_DDRAW if (data->ddraw) { data->ddraw->lpVtbl->Release(data->ddraw); - FreeLibrary(data->ddrawDLL); + SDL_UnloadObject(data->ddrawDLL); } #endif #ifdef _WIN32_WCE if(data->hAygShell) { - FreeLibrary(data->hAygShell); + SDL_UnloadObject(data->hAygShell); } #endif if (data->userDLL) { - FreeLibrary(data->userDLL); + SDL_UnloadObject(data->userDLL); } SDL_free(device->driverdata); @@ -115,24 +102,24 @@ WIN_CreateDevice(int devindex) device->driverdata = data; #if SDL_VIDEO_RENDER_D3D - data->d3dDLL = LoadLibrary(TEXT("D3D9.DLL")); + data->d3dDLL = SDL_LoadObject("D3D9.DLL"); if (data->d3dDLL) { IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion); D3DCreate = - (IDirect3D9 * (WINAPI *) (UINT)) GetProcAddress(data->d3dDLL, + (IDirect3D9 * (WINAPI *) (UINT)) SDL_LoadFunction(data->d3dDLL, "Direct3DCreate9"); if (D3DCreate) { data->d3d = D3DCreate(D3D_SDK_VERSION); } if (!data->d3d) { - FreeLibrary(data->d3dDLL); + SDL_UnloadObject(data->d3dDLL); data->d3dDLL = NULL; } } #endif /* SDL_VIDEO_RENDER_D3D */ #if SDL_VIDEO_RENDER_DDRAW - data->ddrawDLL = LoadLibrary(TEXT("ddraw.dll")); + data->ddrawDLL = SDL_LoadObject("ddraw.dll"); if (data->ddrawDLL) { IDirectDraw *(WINAPI * DDCreate) (GUID FAR * lpGUID, LPDIRECTDRAW FAR * lplpDD, @@ -141,9 +128,9 @@ WIN_CreateDevice(int devindex) DDCreate = (IDirectDraw * (WINAPI *) (GUID FAR *, LPDIRECTDRAW FAR *, IUnknown FAR *)) - GetProcAddress(data->ddrawDLL, TEXT("DirectDrawCreate")); + SDL_LoadFunction(data->ddrawDLL, "DirectDrawCreate"); if (!DDCreate || DDCreate(NULL, &data->ddraw, NULL) != DD_OK) { - FreeLibrary(data->ddrawDLL); + SDL_UnloadObject(data->ddrawDLL); data->ddrawDLL = NULL; data->ddraw = NULL; } @@ -151,19 +138,19 @@ WIN_CreateDevice(int devindex) #endif /* SDL_VIDEO_RENDER_DDRAW */ #ifdef _WIN32_WCE - data->hAygShell = LoadLibrary(TEXT("\\windows\\aygshell.dll")); + data->hAygShell = SDL_LoadObject("\\windows\\aygshell.dll"); if(0 == data->hAygShell) - data->hAygShell = LoadLibrary(TEXT("aygshell.dll")); + data->hAygShell = SDL_LoadObject("aygshell.dll"); data->SHFullScreen = (0 != data->hAygShell ? - (PFNSHFullScreen) GetProcAddress(data->hAygShell, TEXT("SHFullScreen")) : 0); + (PFNSHFullScreen) SDL_LoadFunction(data->hAygShell, "SHFullScreen") : 0); data->CoordTransform = NULL; #endif - data->userDLL = LoadLibrary(TEXT("USER32.DLL")); + data->userDLL = SDL_LoadObject("USER32.DLL"); if (data->userDLL) { - data->CloseTouchInputHandle = (BOOL (WINAPI *)( HTOUCHINPUT )) GetProcAddress(data->userDLL, TEXT("CloseTouchInputHandle")); - data->GetTouchInputInfo = (BOOL (WINAPI *)( HTOUCHINPUT, UINT, PTOUCHINPUT, int )) GetProcAddress(data->userDLL, TEXT("GetTouchInputInfo")); - data->RegisterTouchWindow = (BOOL (WINAPI *)( HWND, ULONG )) GetProcAddress(data->userDLL, TEXT("RegisterTouchWindow")); + data->CloseTouchInputHandle = (BOOL (WINAPI *)( HTOUCHINPUT )) SDL_LoadFunction(data->userDLL, "CloseTouchInputHandle"); + data->GetTouchInputInfo = (BOOL (WINAPI *)( HTOUCHINPUT, UINT, PTOUCHINPUT, int )) SDL_LoadFunction(data->userDLL, "GetTouchInputInfo"); + data->RegisterTouchWindow = (BOOL (WINAPI *)( HWND, ULONG )) SDL_LoadFunction(data->userDLL, "RegisterTouchWindow"); } /* Set the function pointers */ diff --git a/src/video/windows/SDL_windowsvideo.h b/src/video/windows/SDL_windowsvideo.h index 895aa08c0..c43776f97 100644 --- a/src/video/windows/SDL_windowsvideo.h +++ b/src/video/windows/SDL_windowsvideo.h @@ -26,15 +26,7 @@ #include "../SDL_sysvideo.h" -#define WIN32_LEAN_AND_MEAN -#define STRICT -#ifndef UNICODE -#define UNICODE -#endif -#undef WINVER -#define WINVER 0x500 /* Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices() */ - -#include +#include "../../core/windows/SDL_windows.h" #if defined(_MSC_VER) && !defined(_WIN32_WCE) #include @@ -68,15 +60,8 @@ #include "SDL_windowsopengl.h" #include "SDL_windowswindow.h" #include "SDL_events.h" +#include "SDL_loadso.h" -#ifdef UNICODE -#define WIN_StringToUTF8(S) SDL_iconv_string("UTF-8", "UCS-2", (char *)S, (SDL_wcslen(S)+1)*sizeof(WCHAR)) -#define WIN_UTF8ToString(S) (WCHAR *)SDL_iconv_string("UCS-2", "UTF-8", (char *)S, SDL_strlen(S)+1) -#else -#define WIN_StringToUTF8(S) SDL_iconv_string("UTF-8", "ASCII", (char *)S, (SDL_strlen(S)+1)) -#define WIN_UTF8ToString(S) SDL_iconv_string("ASCII", "UTF-8", (char *)S, SDL_strlen(S)+1) -#endif -extern void WIN_SetError(const char *prefix); enum { RENDER_NONE, RENDER_D3D, RENDER_DDRAW, RENDER_GDI, RENDER_GAPI, RENDER_RAW }; @@ -147,15 +132,15 @@ typedef struct SDL_VideoData int render; #if SDL_VIDEO_RENDER_D3D - HANDLE d3dDLL; + void* d3dDLL; IDirect3D9 *d3d; #endif #if SDL_VIDEO_RENDER_DDRAW - HANDLE ddrawDLL; + void* ddrawDLL; IDirectDraw *ddraw; #endif #ifdef _WIN32_WCE - HMODULE hAygShell; + void* hAygShell; PFNSHFullScreen SHFullScreen; PFCoordTransform CoordTransform; #endif @@ -164,7 +149,7 @@ typedef struct SDL_VideoData DWORD clipboard_count; /* Touch input functions */ - HANDLE userDLL; + void* userDLL; BOOL (WINAPI *CloseTouchInputHandle)( HTOUCHINPUT ); BOOL (WINAPI *GetTouchInputInfo)( HTOUCHINPUT, UINT, PTOUCHINPUT, int ); BOOL (WINAPI *RegisterTouchWindow)( HWND, ULONG ); @@ -199,7 +184,7 @@ typedef struct SDL_VideoData int ime_winheight; HKL ime_hkl; - HMODULE ime_himm32; + void* ime_himm32; UINT (WINAPI *GetReadingString)(HIMC himc, UINT uReadingBufLen, LPWSTR lpwReadingBuf, PINT pnErrorIndex, BOOL *pfIsVertical, PUINT puMaxReadingLen); BOOL (WINAPI *ShowReadingWindow)(HIMC himc, BOOL bShow); LPINPUTCONTEXT2 (WINAPI *ImmLockIMC)(HIMC himc);