Commit b4497865 authored by Sam Lantinga's avatar Sam Lantinga

Include windows.h in a single point in the source, so we can be consistent...

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

--HG--
rename : src/SDL_android.cpp => src/core/android/SDL_android.cpp
rename : src/SDL_android.h => src/core/android/SDL_android.h
parent 1775cf40
...@@ -12,30 +12,31 @@ LOCAL_MODULE := SDL ...@@ -12,30 +12,31 @@ LOCAL_MODULE := SDL
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_SRC_FILES := src/SDL_android.cpp \ LOCAL_SRC_FILES := \
$(subst $(LOCAL_PATH)/,, \ $(subst $(LOCAL_PATH)/,, \
$(wildcard $(LOCAL_PATH)/src/*.c) \ $(wildcard $(LOCAL_PATH)/src/*.c) \
$(wildcard $(LOCAL_PATH)/src/audio/*.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_atomic.c \
$(LOCAL_PATH)/src/atomic/SDL_spinlock.c.arm \ $(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/cpuinfo/*.c) \
$(wildcard $(LOCAL_PATH)/src/events/*.c) \ $(wildcard $(LOCAL_PATH)/src/events/*.c) \
$(wildcard $(LOCAL_PATH)/src/file/*.c) \ $(wildcard $(LOCAL_PATH)/src/file/*.c) \
$(wildcard $(LOCAL_PATH)/src/joystick/*.c) \
$(wildcard $(LOCAL_PATH)/src/haptic/*.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/stdlib/*.c) \
$(wildcard $(LOCAL_PATH)/src/thread/*.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/thread/pthread/*.c) \
$(wildcard $(LOCAL_PATH)/src/timer/*.c) \
$(wildcard $(LOCAL_PATH)/src/timer/unix/*.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 LOCAL_LDLIBS := -ldl -lGLESv1_CM -llog
......
...@@ -1150,6 +1150,22 @@ ...@@ -1150,6 +1150,22 @@
RelativePath="..\..\src\audio\SDL_wave.h" RelativePath="..\..\src\audio\SDL_wave.h"
> >
</File> </File>
<File
RelativePath="..\..\src\events\SDL_windowevents.c"
>
</File>
<File
RelativePath="..\..\src\events\SDL_windowevents_c.h"
>
</File>
<File
RelativePath="..\..\src\core\windows\SDL_windows.c"
>
</File>
<File
RelativePath="..\..\src\core\windows\SDL_windows.h"
>
</File>
<File <File
RelativePath="..\..\src\video\windows\SDL_windowsclipboard.c" RelativePath="..\..\src\video\windows\SDL_windowsclipboard.c"
> >
...@@ -1230,14 +1246,6 @@ ...@@ -1230,14 +1246,6 @@
RelativePath="..\..\src\video\windows\SDL_windowswindow.h" RelativePath="..\..\src\video\windows\SDL_windowswindow.h"
> >
</File> </File>
<File
RelativePath="..\..\src\events\SDL_windowevents.c"
>
</File>
<File
RelativePath="..\..\src\events\SDL_windowevents_c.h"
>
</File>
<File <File
RelativePath="..\..\src\video\SDL_yuv_mmx.c" RelativePath="..\..\src\video\SDL_yuv_mmx.c"
> >
......
...@@ -272,6 +272,7 @@ echo #define SDL_REVISION 0 &gt;"$(ProjectDir)\..\..\include\SDL_revision.h" ...@@ -272,6 +272,7 @@ echo #define SDL_REVISION 0 &gt;"$(ProjectDir)\..\..\include\SDL_revision.h"
<ClInclude Include="..\..\include\SDL_types.h" /> <ClInclude Include="..\..\include\SDL_types.h" />
<ClInclude Include="..\..\include\SDL_version.h" /> <ClInclude Include="..\..\include\SDL_version.h" />
<ClInclude Include="..\..\include\SDL_video.h" /> <ClInclude Include="..\..\include\SDL_video.h" />
<ClInclude Include="..\..\src\core\windows\SDL_windows.h" />
<ClInclude Include="..\..\src\events\blank_cursor.h" /> <ClInclude Include="..\..\src\events\blank_cursor.h" />
<ClInclude Include="..\..\src\events\default_cursor.h" /> <ClInclude Include="..\..\src\events\default_cursor.h" />
<ClInclude Include="..\..\src\audio\windx5\directx.h" /> <ClInclude Include="..\..\src\audio\windx5\directx.h" />
...@@ -345,6 +346,7 @@ echo #define SDL_REVISION 0 &gt;"$(ProjectDir)\..\..\include\SDL_revision.h" ...@@ -345,6 +346,7 @@ echo #define SDL_REVISION 0 &gt;"$(ProjectDir)\..\..\include\SDL_revision.h"
<ClInclude Include="..\..\src\video\windows\wmmsg.h" /> <ClInclude Include="..\..\src\video\windows\wmmsg.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\src\core\windows\SDL_windows.c" />
<ClCompile Include="..\..\src\events\SDL_clipboardevents.c" /> <ClCompile Include="..\..\src\events\SDL_clipboardevents.c" />
<ClCompile Include="..\..\src\events\SDL_gesture.c" /> <ClCompile Include="..\..\src\events\SDL_gesture.c" />
<ClCompile Include="..\..\src\events\SDL_touch.c" /> <ClCompile Include="..\..\src\events\SDL_touch.c" />
......
...@@ -1053,6 +1053,10 @@ ...@@ -1053,6 +1053,10 @@
RelativePath="..\..\src\events\SDL_windowevents.c" RelativePath="..\..\src\events\SDL_windowevents.c"
> >
</File> </File>
<File
RelativePath="..\..\src\core\windows\SDL_windows.c"
>
</File>
<File <File
RelativePath="..\..\src\video\windows\SDL_windowsclipboard.c" RelativePath="..\..\src\video\windows\SDL_windowsclipboard.c"
> >
...@@ -1358,6 +1362,10 @@ ...@@ -1358,6 +1362,10 @@
RelativePath="..\..\src\events\SDL_windowevents_c.h" RelativePath="..\..\src\events\SDL_windowevents_c.h"
> >
</File> </File>
<File
RelativePath="..\..\src\core\windows\SDL_windows.h"
>
</File>
<File <File
RelativePath="..\..\src\video\windows\SDL_windowsclipboard.h" RelativePath="..\..\src\video\windows\SDL_windowsclipboard.h"
> >
......
...@@ -329,8 +329,7 @@ SDL_GetPlatform() ...@@ -329,8 +329,7 @@ SDL_GetPlatform()
#if !defined(HAVE_LIBC) || (defined(__WATCOMC__) && defined(BUILD_DLL)) #if !defined(HAVE_LIBC) || (defined(__WATCOMC__) && defined(BUILD_DLL))
/* Need to include DllMain() on Watcom C for some reason.. */ /* Need to include DllMain() on Watcom C for some reason.. */
#define WIN32_LEAN_AND_MEAN #include "core/windows/SDL_windows.h"
#include <windows.h>
BOOL APIENTRY BOOL APIENTRY
_DllMainCRTStartup(HANDLE hModule, _DllMainCRTStartup(HANDLE hModule,
......
...@@ -27,18 +27,11 @@ ...@@ -27,18 +27,11 @@
#include "video/SDL_sysvideo.h" #include "video/SDL_sysvideo.h"
#ifdef __WIN32__ #ifdef __WIN32__
#define WIN32_LEAN_AND_MEAN #include "core/windows/SDL_windows.h"
#include <windows.h>
#ifndef WS_OVERLAPPEDWINDOW #ifndef WS_OVERLAPPEDWINDOW
#define WS_OVERLAPPEDWINDOW 0 #define WS_OVERLAPPEDWINDOW 0
#endif #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. */ #else /* fprintf, _exit(), etc. */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
......
...@@ -25,14 +25,7 @@ ...@@ -25,14 +25,7 @@
#include "SDL_timer.h" #include "SDL_timer.h"
/* Don't do the check for Visual Studio 2005, it's safe here */ /* Don't do the check for Visual Studio 2005, it's safe here */
#if defined(_MSC_VER) #include "../core/windows/SDL_windows.h"
#ifdef _WIN32_WCE
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#else
#include <intrin.h>
#endif
#endif /* _MSC_VER */
/* This function is where all the magic happens... */ /* This function is where all the magic happens... */
SDL_bool SDL_bool
...@@ -40,7 +33,7 @@ SDL_AtomicTryLock(SDL_SpinLock *lock) ...@@ -40,7 +33,7 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
{ {
#if defined(_MSC_VER) #if defined(_MSC_VER)
SDL_COMPILE_TIME_ASSERT(locksize, sizeof(*lock) == sizeof(long)); SDL_COMPILE_TIME_ASSERT(locksize, sizeof(*lock) == sizeof(long));
return (_InterlockedExchange((long*)lock, 1) == 0); return (InterlockedExchange((long*)lock, 1) == 0);
#elif defined(__MACOSX__) #elif defined(__MACOSX__)
return OSAtomicCompareAndSwap32Barrier(0, 1, lock); return OSAtomicCompareAndSwap32Barrier(0, 1, lock);
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include "../SDL_audio_c.h" #include "../SDL_audio_c.h"
#include "SDL_androidaudio.h" #include "SDL_androidaudio.h"
#include "../../SDL_android.h" #include "../../core/android/SDL_android.h"
#include <android/log.h> #include <android/log.h>
......
...@@ -23,8 +23,7 @@ ...@@ -23,8 +23,7 @@
/* Allow access to a raw mixing buffer */ /* Allow access to a raw mixing buffer */
#define WIN32_LEAN_AND_MEAN #include "../../core/windows/SDL_windows.h"
#include <windows.h>
#include <mmsystem.h> #include <mmsystem.h>
#include "SDL_timer.h" #include "SDL_timer.h"
...@@ -67,21 +66,14 @@ SetMMerror(char *function, MMRESULT code) ...@@ -67,21 +66,14 @@ SetMMerror(char *function, MMRESULT code)
{ {
size_t len; size_t len;
char errbuf[MAXERRORLENGTH]; char errbuf[MAXERRORLENGTH];
#ifdef _WIN32_WCE
wchar_t werrbuf[MAXERRORLENGTH]; wchar_t werrbuf[MAXERRORLENGTH];
#endif
SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: ", function); SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: ", function);
len = SDL_strlen(errbuf); len = SDL_strlen(errbuf);
#ifdef _WIN32_WCE
/* UNICODE version */
waveOutGetErrorText(code, werrbuf, MAXERRORLENGTH - len); waveOutGetErrorText(code, werrbuf, MAXERRORLENGTH - len);
WideCharToMultiByte(CP_ACP, 0, werrbuf, -1, errbuf + len, WideCharToMultiByte(CP_ACP, 0, werrbuf, -1, errbuf + len,
MAXERRORLENGTH - len, NULL, NULL); MAXERRORLENGTH - len, NULL, NULL);
#else
waveOutGetErrorText(code, errbuf + len, (UINT) (MAXERRORLENGTH - len));
#endif
SDL_SetError("%s", errbuf); SDL_SetError("%s", errbuf);
} }
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
/* Allow access to a raw mixing buffer */ /* Allow access to a raw mixing buffer */
#include "SDL_timer.h" #include "SDL_timer.h"
#include "SDL_loadso.h"
#include "SDL_audio.h" #include "SDL_audio.h"
#include "../SDL_audio_c.h" #include "../SDL_audio_c.h"
#include "SDL_dx5audio.h" #include "SDL_dx5audio.h"
...@@ -38,19 +39,19 @@ ...@@ -38,19 +39,19 @@
#endif #endif
/* DirectX function pointers for audio */ /* DirectX function pointers for audio */
static HINSTANCE DSoundDLL = NULL; static void* DSoundDLL = NULL;
static HRESULT(WINAPI * DSoundCreate) (LPGUID, LPDIRECTSOUND *, LPUNKNOWN) = static HRESULT(WINAPI * DSoundCreate) (LPGUID, LPDIRECTSOUND *, LPUNKNOWN) =
NULL; NULL;
static void static void
DSOUND_Unload(void) DSOUND_Unload(void)
{ {
if (DSoundDLL != NULL) {
FreeLibrary(DSoundDLL);
}
DSoundCreate = NULL; DSoundCreate = NULL;
if (DSoundDLL != NULL) {
SDL_UnloadObject(DSoundDLL);
DSoundDLL = NULL; DSoundDLL = NULL;
}
} }
...@@ -61,17 +62,16 @@ DSOUND_Load(void) ...@@ -61,17 +62,16 @@ DSOUND_Load(void)
DSOUND_Unload(); DSOUND_Unload();
DSoundDLL = LoadLibrary(TEXT("DSOUND.DLL")); DSoundDLL = SDL_LoadObject("DSOUND.DLL");
if (DSoundDLL == NULL) { if (DSoundDLL == NULL) {
SDL_SetError("DirectSound: failed to load DSOUND.DLL"); SDL_SetError("DirectSound: failed to load DSOUND.DLL");
} else { } else {
/* Now make sure we have DirectX 5 or better... */ /* Now make sure we have DirectX 5 or better... */
/* (DirectSoundCaptureCreate was added in DX5) */ /* (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."); SDL_SetError("DirectSound: System doesn't appear to have DX5.");
} else { } else {
DSoundCreate = (void *) GetProcAddress(DSoundDLL, DSoundCreate = SDL_LoadFunction(DSoundDLL, "DirectSoundCreate");
TEXT("DirectSoundCreate"));
} }
if (!DSoundCreate) { if (!DSoundCreate) {
......
...@@ -4,8 +4,7 @@ ...@@ -4,8 +4,7 @@
/* Include all of the DirectX 5.0 headers and adds any necessary tweaks */ /* Include all of the DirectX 5.0 headers and adds any necessary tweaks */
#define WIN32_LEAN_AND_MEAN #include "../../core/windows/SDL_windows.h"
#include <windows.h>
#include <mmsystem.h> #include <mmsystem.h>
#ifndef WIN32 #ifndef WIN32
#define WIN32 #define WIN32
......
/*
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: */
/*
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 <windows.h>
/* 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: */
...@@ -39,8 +39,7 @@ ...@@ -39,8 +39,7 @@
#include <setjmp.h> #include <setjmp.h>
#endif #endif
#ifdef __WIN32__ #ifdef __WIN32__
#define WIN32_LEAN_AND_MEAN #include "../core/windows/SDL_windows.h"
#include <windows.h>
#endif #endif
#define CPU_HAS_RDTSC 0x00000001 #define CPU_HAS_RDTSC 0x00000001
......
...@@ -44,8 +44,7 @@ ...@@ -44,8 +44,7 @@
faster, and all stdio functions anyway are embedded in coredll.dll - faster, and all stdio functions anyway are embedded in coredll.dll -
the main wince dll*/ the main wince dll*/
#define WINDOWS_LEAN_AND_MEAN #include "../core/windows/SDL_windows.h"
#include <windows.h>
#ifndef INVALID_SET_FILE_POINTER #ifndef INVALID_SET_FILE_POINTER
#define INVALID_SET_FILE_POINTER 0xFFFFFFFF #define INVALID_SET_FILE_POINTER 0xFFFFFFFF
...@@ -98,34 +97,28 @@ windows_file_open(SDL_RWops * context, const char *filename, const char *mode) ...@@ -98,34 +97,28 @@ windows_file_open(SDL_RWops * context, const char *filename, const char *mode)
} }
#ifdef _WIN32_WCE #ifdef _WIN32_WCE
{ {
size_t size = SDL_strlen(filename) + 1; LPTSTR tstr = WIN_UTF8ToString(filename);
wchar_t *filenameW = SDL_stack_alloc(wchar_t, size); h = CreateFile(tstr, (w_right | r_right),
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),
(w_right) ? 0 : FILE_SHARE_READ, NULL, (w_right) ? 0 : FILE_SHARE_READ, NULL,
(must_exist | truncate | a_mode), (must_exist | truncate | a_mode),
FILE_ATTRIBUTE_NORMAL, NULL); FILE_ATTRIBUTE_NORMAL, NULL);
SDL_stack_free(filenameW); SDL_free(tstr);
} }
#else #else
/* Do not open a dialog box if failure */ /* Do not open a dialog box if failure */
old_error_mode = old_error_mode =
SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS); SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS);
h = CreateFile(filename, (w_right | r_right), {
LPTSTR tstr = WIN_UTF8ToString(filename);
h = CreateFile(tstr, (w_right | r_right),
(w_right) ? 0 : FILE_SHARE_READ, NULL, (w_right) ? 0 : FILE_SHARE_READ, NULL,
(must_exist | truncate | a_mode), FILE_ATTRIBUTE_NORMAL, (must_exist | truncate | a_mode),
NULL); FILE_ATTRIBUTE_NORMAL, NULL);
SDL_free(tstr);
}
/* restore old behaviour */ /* restore old behavior */
SetErrorMode(old_error_mode); SetErrorMode(old_error_mode);
#endif /* _WIN32_WCE */ #endif /* _WIN32_WCE */
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
static struct static struct
{ {
DIDEVICEINSTANCE instance; DIDEVICEINSTANCE instance;
char *name;
SDL_Haptic *haptic; SDL_Haptic *haptic;
DIDEVCAPS capabilities; DIDEVCAPS capabilities;
} SDL_hapticlist[MAX_HAPTICS]; } SDL_hapticlist[MAX_HAPTICS];
...@@ -220,6 +221,9 @@ EnumHapticsCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext) ...@@ -220,6 +221,9 @@ EnumHapticsCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext)
return DIENUM_CONTINUE; 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. */ /* Close up device and count it. */
IDirectInputDevice_Release(device); IDirectInputDevice_Release(device);
SDL_numhaptics++; SDL_numhaptics++;
...@@ -238,7 +242,7 @@ EnumHapticsCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext) ...@@ -238,7 +242,7 @@ EnumHapticsCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext)
const char * const char *
SDL_SYS_HapticName(int index) 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) ...@@ -630,6 +634,15 @@ SDL_SYS_HapticClose(SDL_Haptic * haptic)
void void
SDL_SYS_HapticQuit(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); IDirectInput_Release(dinput);
dinput = NULL; dinput = NULL;
} }
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#include "SDL_joystick.h" #include "SDL_joystick.h"
#include "../SDL_sysjoystick.h" #include "../SDL_sysjoystick.h"
#include "../SDL_joystick_c.h" #include "../SDL_joystick_c.h"
#include "../../SDL_android.h" #include "../../core/android/SDL_android.h"
static const char *accelerometerName = "Android accelerometer"; static const char *accelerometerName = "Android accelerometer";
......
...@@ -63,6 +63,7 @@ extern HRESULT(WINAPI * DInputCreate) (HINSTANCE hinst, DWORD dwVersion, ...@@ -63,6 +63,7 @@ extern HRESULT(WINAPI * DInputCreate) (HINSTANCE hinst, DWORD dwVersion,
LPDIRECTINPUT * ppDI, LPDIRECTINPUT * ppDI,
LPUNKNOWN punkOuter); LPUNKNOWN punkOuter);
static DIDEVICEINSTANCE SYS_Joystick[MAX_JOYSTICKS]; /* array to hold joystick ID values */ static DIDEVICEINSTANCE SYS_Joystick[MAX_JOYSTICKS]; /* array to hold joystick ID values */
static char *SYS_JoystickNames[MAX_JOYSTICKS];
static int SYS_NumJoysticks; static int SYS_NumJoysticks;
static HINSTANCE DInputDLL = NULL; static HINSTANCE DInputDLL = NULL;
...@@ -326,6 +327,7 @@ EnumJoysticksCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext) ...@@ -326,6 +327,7 @@ EnumJoysticksCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext)
{ {
SDL_memcpy(&SYS_Joystick[SYS_NumJoysticks], pdidInstance, SDL_memcpy(&SYS_Joystick[SYS_NumJoysticks], pdidInstance,
sizeof(DIDEVICEINSTANCE)); sizeof(DIDEVICEINSTANCE));
SYS_JoystickNames[SYS_NumJoysticks] = WIN_StringToUTF8(pdidInstance->tszProductName);
SYS_NumJoysticks++; SYS_NumJoysticks++;
if (SYS_NumJoysticks >= MAX_JOYSTICKS) if (SYS_NumJoysticks >= MAX_JOYSTICKS)
...@@ -338,8 +340,7 @@ EnumJoysticksCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext) ...@@ -338,8 +340,7 @@ EnumJoysticksCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext)
const char * const char *
SDL_SYS_JoystickName(int index) SDL_SYS_JoystickName(int index)
{ {
/***-> test for invalid index ? */ return SYS_JoystickNames[index];
return (SYS_Joystick[index].tszProductName);
} }
/* Function to open a joystick for use. /* Function to open a joystick for use.
...@@ -793,6 +794,15 @@ SDL_SYS_JoystickClose(SDL_Joystick * joystick) ...@@ -793,6 +794,15 @@ SDL_SYS_JoystickClose(SDL_Joystick * joystick)
void void
SDL_SYS_JoystickQuit(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); IDirectInput_Release(dinput);
dinput = NULL; dinput = NULL;
} }
......
...@@ -33,8 +33,7 @@ ...@@ -33,8 +33,7 @@
* with polled devices, and it's fine to call IDirectInputDevice2_GetDeviceData and * with polled devices, and it's fine to call IDirectInputDevice2_GetDeviceData and
* let it return 0 events. */ * let it return 0 events. */
#define WIN32_LEAN_AND_MEAN #include "../../core/windows/SDL_windows.h"
#include <windows.h>
#define DIRECTINPUT_VERSION 0x0700 /* Need version 7 for force feedback. */ #define DIRECTINPUT_VERSION 0x0700 /* Need version 7 for force feedback. */
#include <dinput.h> #include <dinput.h>
......
...@@ -25,8 +25,7 @@ ...@@ -25,8 +25,7 @@
/* Win32 MultiMedia Joystick driver, contributed by Andrei de A. Formiga */ /* Win32 MultiMedia Joystick driver, contributed by Andrei de A. Formiga */
#define WIN32_LEAN_AND_MEAN #include "../../core/windows/SDL_windows.h"
#include <windows.h>
#include <mmsystem.h> #include <mmsystem.h>
#include <regstr.h> #include <regstr.h>
......
...@@ -26,110 +26,45 @@ ...@@ -26,110 +26,45 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* System dependent library loading routines */ /* System dependent library loading routines */
#define WIN32_LEAN_AND_MEAN #include "../../core/windows/SDL_windows.h"
#include <windows.h>
#include "SDL_loadso.h" #include "SDL_loadso.h"
void * void *
SDL_LoadObject(const char *sofile) SDL_LoadObject(const char *sofile)
{ {
void *handle = NULL; LPTSTR tstr = WIN_UTF8ToString(sofile);
const char *loaderror = "Unknown error"; void *handle = (void *) LoadLibrary(tstr);
SDL_free(tstr);
#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);
/* Generate an error message if all loads failed */ /* Generate an error message if all loads failed */
if (handle == NULL) { 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;
}
SDL_free(sofile_t);
SDL_free(errbuf_t);
#else /*if defined(__WIN32__) */
char errbuf[512]; char errbuf[512];
SDL_strlcpy(errbuf, "Failed loading ", SDL_arraysize(errbuf));
handle = (void *) LoadLibrary(sofile); SDL_strlcat(errbuf, sofile, SDL_arraysize(errbuf));
WIN_SetError(errbuf);
/* 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 * void *
SDL_LoadFunction(void *handle, const char *name) SDL_LoadFunction(void *handle, const char *name)
{ {
void *symbol = NULL; #ifdef _WIN32_WCE
const char *loaderror = "Unknown error"; LPTSTR tstr = WIN_UTF8ToString(name);
void *symbol = (void *) GetProcAddress((HMODULE) handle, tstr);
#if defined(_WIN32_WCE) SDL_free(tstr);
char errbuf[512]; #else
int length = SDL_strlen(name); void *symbol = (void *) GetProcAddress((HMODULE) handle, 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;
}
#endif #endif
if (symbol == NULL) { 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 void
......
...@@ -24,8 +24,7 @@ ...@@ -24,8 +24,7 @@
#ifndef SDL_POWER_DISABLED #ifndef SDL_POWER_DISABLED
#ifdef SDL_POWER_WINDOWS #ifdef SDL_POWER_WINDOWS
#define WIN32_LEAN_AND_MEAN #include "../../core/windows/SDL_windows.h"
#include <windows.h>
#include "SDL_power.h" #include "SDL_power.h"
......
...@@ -27,8 +27,7 @@ ...@@ -27,8 +27,7 @@
#if defined(__WIN32__) && !defined(_WIN32_WCE) #if defined(__WIN32__) && !defined(_WIN32_WCE)
#define WIN32_LEAN_AND_MEAN #include "../core/windows/SDL_windows.h"
#include <windows.h>
/* Note this isn't thread-safe! */ /* Note this isn't thread-safe! */
...@@ -41,12 +40,12 @@ SDL_setenv(const char *name, const char *value, int overwrite) ...@@ -41,12 +40,12 @@ SDL_setenv(const char *name, const char *value, int overwrite)
{ {
if (!overwrite) { if (!overwrite) {
char ch = 0; char ch = 0;
const size_t len = GetEnvironmentVariable(name, &ch, sizeof (ch)); const size_t len = GetEnvironmentVariableA(name, &ch, sizeof (ch));
if (len > 0) { if (len > 0) {
return 0; /* asked not to overwrite existing value. */ return 0; /* asked not to overwrite existing value. */
} }
} }
if (!SetEnvironmentVariable(name, *value ? value : NULL)) { if (!SetEnvironmentVariableA(name, *value ? value : NULL)) {
return -1; return -1;
} }
return 0; return 0;
...@@ -59,7 +58,7 @@ SDL_getenv(const char *name) ...@@ -59,7 +58,7 @@ SDL_getenv(const char *name)
size_t bufferlen; size_t bufferlen;
bufferlen = bufferlen =
GetEnvironmentVariable(name, SDL_envmem, (DWORD) SDL_envmemlen); GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen);
if (bufferlen == 0) { if (bufferlen == 0) {
return NULL; return NULL;
} }
...@@ -70,7 +69,7 @@ SDL_getenv(const char *name) ...@@ -70,7 +69,7 @@ SDL_getenv(const char *name)
} }
SDL_envmem = newmem; SDL_envmem = newmem;
SDL_envmemlen = bufferlen; SDL_envmemlen = bufferlen;
GetEnvironmentVariable(name, SDL_envmem, (DWORD) SDL_envmemlen); GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen);
} }
return SDL_envmem; return SDL_envmem;
} }
......
...@@ -23,8 +23,7 @@ ...@@ -23,8 +23,7 @@
/* Mutex functions using the Win32 API */ /* Mutex functions using the Win32 API */
#define WIN32_LEAN_AND_MEAN #include "../../core/windows/SDL_windows.h"
#include <windows.h>
#include "SDL_mutex.h" #include "SDL_mutex.h"
......
...@@ -23,8 +23,7 @@ ...@@ -23,8 +23,7 @@
/* Semaphore functions using the Win32 API */ /* Semaphore functions using the Win32 API */
#define WIN32_LEAN_AND_MEAN #include "../../core/windows/SDL_windows.h"
#include <windows.h>
#include "SDL_thread.h" #include "SDL_thread.h"
#if defined(_WIN32_WCE) && (_WIN32_WCE < 300) #if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
......
...@@ -21,8 +21,7 @@ ...@@ -21,8 +21,7 @@
*/ */
#include "SDL_config.h" #include "SDL_config.h"
#define WIN32_LEAN_AND_MEAN #include "../../core/windows/SDL_windows.h"
#include <windows.h>
typedef HANDLE SYS_ThreadHandle; typedef HANDLE SYS_ThreadHandle;
......
...@@ -28,8 +28,7 @@ ...@@ -28,8 +28,7 @@
and it is not clear how to handle a mixture of WCE semaphores and normal and it is not clear how to handle a mixture of WCE semaphores and normal
events and mutexes. */ events and mutexes. */
#define WIN32_LEAN_AND_MEAN #include "../../core/windows/SDL_windows.h"
#include <windows.h>
#include "win_ce_semaphore.h" #include "win_ce_semaphore.h"
......
...@@ -23,8 +23,7 @@ ...@@ -23,8 +23,7 @@
#ifdef SDL_TIMER_WINCE #ifdef SDL_TIMER_WINCE
#define WIN32_LEAN_AND_MEAN #include "../../core/windows/SDL_windows.h"
#include <windows.h>
#include <mmsystem.h> #include <mmsystem.h>
#include "SDL_thread.h" #include "SDL_thread.h"
......
...@@ -23,8 +23,7 @@ ...@@ -23,8 +23,7 @@
#ifdef SDL_TIMER_WINDOWS #ifdef SDL_TIMER_WINDOWS
#define WIN32_LEAN_AND_MEAN #include "../../core/windows/SDL_windows.h"
#include <windows.h>
#include <mmsystem.h> #include <mmsystem.h>
#include "SDL_timer.h" #include "SDL_timer.h"
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include "SDL_video.h" #include "SDL_video.h"
#include "SDL_androidvideo.h" #include "SDL_androidvideo.h"
#include "../../SDL_android.h" #include "../../core/android/SDL_android.h"
#include <android/log.h> #include <android/log.h>
......
...@@ -78,7 +78,7 @@ typedef int (*PFNGXResume)(); ...@@ -78,7 +78,7 @@ typedef int (*PFNGXResume)();
typedef struct typedef struct
{ {
// gx.dll // gx.dll
HMODULE hGapiLib; void* hGapiLib;
PFNGXOpenDisplay GXOpenDisplay; PFNGXOpenDisplay GXOpenDisplay;
PFNGXCloseDisplay GXCloseDisplay; PFNGXCloseDisplay GXCloseDisplay;
PFNGXBeginDraw GXBeginDraw; PFNGXBeginDraw GXBeginDraw;
...@@ -251,7 +251,7 @@ SDL_RenderDriver RAW_RenderDriver = { ...@@ -251,7 +251,7 @@ SDL_RenderDriver RAW_RenderDriver = {
int WINCE_Available(void) int WINCE_Available(void)
{ {
HMODULE render_gapi; void* render_gapi;
const char* preferably = SDL_getenv("SDL_VIDEO_RENDERER"); const char* preferably = SDL_getenv("SDL_VIDEO_RENDERER");
// raw check // raw check
...@@ -267,10 +267,10 @@ int WINCE_Available(void) ...@@ -267,10 +267,10 @@ int WINCE_Available(void)
if(preferably && 0 == SDL_strcasecmp(preferably, RAW_RENDER_NAME)) return 0 != render_raw; if(preferably && 0 == SDL_strcasecmp(preferably, RAW_RENDER_NAME)) return 0 != render_raw;
// gapi check // gapi check
render_gapi = LoadLibrary(TEXT("\\Windows\\gx.dll")); render_gapi = SDL_LoadObject("\\Windows\\gx.dll");
if(0 == render_gapi) if(0 == render_gapi)
render_gapi = LoadLibrary(TEXT("gx.dll")); render_gapi = SDL_LoadObject("gx.dll");
FreeLibrary(render_gapi); SDL_UnloadObject(render_gapi);
if(preferably && 0 == SDL_strcasecmp(preferably, GAPI_RENDER_NAME)) return 0 != render_gapi; if(preferably && 0 == SDL_strcasecmp(preferably, GAPI_RENDER_NAME)) return 0 != render_gapi;
...@@ -280,7 +280,7 @@ int WINCE_Available(void) ...@@ -280,7 +280,7 @@ int WINCE_Available(void)
void WINCE_AddRenderDriver(_THIS) void WINCE_AddRenderDriver(_THIS)
{ {
HDC hdc; HDC hdc;
HMODULE render_gapi; void* render_gapi;
int render_raw, ii; int render_raw, ii;
const char* preferably = SDL_getenv("SDL_VIDEO_RENDERER"); const char* preferably = SDL_getenv("SDL_VIDEO_RENDERER");
...@@ -295,12 +295,12 @@ void WINCE_AddRenderDriver(_THIS) ...@@ -295,12 +295,12 @@ void WINCE_AddRenderDriver(_THIS)
render_raw = 1; render_raw = 1;
// gapi check // gapi check
render_gapi = LoadLibrary(TEXT("\\Windows\\gx.dll")); render_gapi = SDL_LoadObject("\\Windows\\gx.dll");
if(0 == render_gapi) if(0 == render_gapi)
render_gapi = LoadLibrary(TEXT("gx.dll")); render_gapi = SDL_LoadObject("gx.dll");
if(render_gapi) if(render_gapi)
FreeLibrary(render_gapi); SDL_UnloadObject(render_gapi);
for(ii = 0; ii < _this->num_displays; ++ii) for(ii = 0; ii < _this->num_displays; ++ii)
{ {
...@@ -885,15 +885,15 @@ int GAPI_Init(WINCE_RenderData* data, HWND hwnd) ...@@ -885,15 +885,15 @@ int GAPI_Init(WINCE_RenderData* data, HWND hwnd)
return 0; return 0;
} }
data->gapi->hGapiLib = LoadLibrary(TEXT("\\Windows\\gx.dll")); data->gapi->hGapiLib = SDL_LoadObject("\\Windows\\gx.dll");
if(0 == data->gapi->hGapiLib) 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; if(0 == data->gapi->hGapiLib) return 0;
} }
// load gapi library // 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(GXOpenDisplay, data->gapi->GXOpenDisplay, "?GXOpenDisplay@@YAHPAUHWND__@@K@Z");
LINK(GXCloseDisplay, data->gapi->GXCloseDisplay, "?GXCloseDisplay@@YAHXZ"); LINK(GXCloseDisplay, data->gapi->GXCloseDisplay, "?GXCloseDisplay@@YAHXZ");
LINK(GXBeginDraw, data->gapi->GXBeginDraw, "?GXBeginDraw@@YAPAXXZ"); LINK(GXBeginDraw, data->gapi->GXBeginDraw, "?GXBeginDraw@@YAPAXXZ");
...@@ -1005,7 +1005,7 @@ void GAPI_Quit(WINCE_RenderData* data) ...@@ -1005,7 +1005,7 @@ void GAPI_Quit(WINCE_RenderData* data)
if(data->gapi) if(data->gapi)
{ {
if(data->gapi->GXCloseDisplay) data->gapi->GXCloseDisplay(); 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); SDL_free(data->gapi);
data->gapi = NULL; data->gapi = NULL;
......
...@@ -312,15 +312,15 @@ IME_Init(SDL_VideoData *videodata, HWND hwnd) ...@@ -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); CoCreateInstance(&CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, &IID_ITfThreadMgr, (LPVOID *)&videodata->ime_threadmgr);
} }
videodata->ime_initialized = SDL_TRUE; videodata->ime_initialized = SDL_TRUE;
videodata->ime_himm32 = LoadLibraryA("imm32.dll"); videodata->ime_himm32 = SDL_LoadObject("imm32.dll");
if (!videodata->ime_himm32) { if (!videodata->ime_himm32) {
videodata->ime_available = SDL_FALSE; videodata->ime_available = SDL_FALSE;
return; return;
} }
videodata->ImmLockIMC = (LPINPUTCONTEXT2 (WINAPI *)(HIMC))GetProcAddress(videodata->ime_himm32, "ImmLockIMC"); videodata->ImmLockIMC = (LPINPUTCONTEXT2 (WINAPI *)(HIMC))SDL_LoadFunction(videodata->ime_himm32, "ImmLockIMC");
videodata->ImmUnlockIMC = (BOOL (WINAPI *)(HIMC))GetProcAddress(videodata->ime_himm32, "ImmUnlockIMC"); videodata->ImmUnlockIMC = (BOOL (WINAPI *)(HIMC))SDL_LoadFunction(videodata->ime_himm32, "ImmUnlockIMC");
videodata->ImmLockIMCC = (LPVOID (WINAPI *)(HIMCC))GetProcAddress(videodata->ime_himm32, "ImmLockIMCC"); videodata->ImmLockIMCC = (LPVOID (WINAPI *)(HIMCC))SDL_LoadFunction(videodata->ime_himm32, "ImmLockIMCC");
videodata->ImmUnlockIMCC = (BOOL (WINAPI *)(HIMCC))GetProcAddress(videodata->ime_himm32, "ImmUnlockIMCC"); videodata->ImmUnlockIMCC = (BOOL (WINAPI *)(HIMCC))SDL_LoadFunction(videodata->ime_himm32, "ImmUnlockIMCC");
IME_SetWindow(videodata, hwnd); IME_SetWindow(videodata, hwnd);
videodata->ime_himc = ImmGetContext(hwnd); videodata->ime_himc = ImmGetContext(hwnd);
...@@ -383,7 +383,7 @@ IME_Quit(SDL_VideoData *videodata) ...@@ -383,7 +383,7 @@ IME_Quit(SDL_VideoData *videodata)
videodata->ime_hwnd_main = 0; videodata->ime_hwnd_main = 0;
videodata->ime_himc = 0; videodata->ime_himc = 0;
if (videodata->ime_himm32) { if (videodata->ime_himm32) {
FreeLibrary(videodata->ime_himm32); SDL_UnloadObject(videodata->ime_himm32);
videodata->ime_himm32 = 0; videodata->ime_himm32 = 0;
} }
if (videodata->ime_threadmgr) { if (videodata->ime_threadmgr) {
...@@ -606,7 +606,7 @@ static void ...@@ -606,7 +606,7 @@ static void
IME_SetupAPI(SDL_VideoData *videodata) IME_SetupAPI(SDL_VideoData *videodata)
{ {
char ime_file[MAX_PATH + 1]; char ime_file[MAX_PATH + 1];
HMODULE hime = 0; void* hime = 0;
HKL hkl = 0; HKL hkl = 0;
videodata->GetReadingString = 0; videodata->GetReadingString = 0;
videodata->ShowReadingWindow = 0; videodata->ShowReadingWindow = 0;
...@@ -617,14 +617,14 @@ IME_SetupAPI(SDL_VideoData *videodata) ...@@ -617,14 +617,14 @@ IME_SetupAPI(SDL_VideoData *videodata)
if (ImmGetIMEFileNameA(hkl, ime_file, sizeof(ime_file) - 1) <= 0) if (ImmGetIMEFileNameA(hkl, ime_file, sizeof(ime_file) - 1) <= 0)
return; return;
hime = LoadLibraryA(ime_file); hime = SDL_LoadObject(ime_file);
if (!hime) if (!hime)
return; return;
videodata->GetReadingString = (UINT (WINAPI *)(HIMC, UINT, LPWSTR, PINT, BOOL*, PUINT)) videodata->GetReadingString = (UINT (WINAPI *)(HIMC, UINT, LPWSTR, PINT, BOOL*, PUINT))
GetProcAddress(hime, "GetReadingString"); SDL_LoadFunction(hime, "GetReadingString");
videodata->ShowReadingWindow = (BOOL (WINAPI *)(HIMC, BOOL)) videodata->ShowReadingWindow = (BOOL (WINAPI *)(HIMC, BOOL))
GetProcAddress(hime, "ShowReadingWindow"); SDL_LoadFunction(hime, "ShowReadingWindow");
if (videodata->ShowReadingWindow) { if (videodata->ShowReadingWindow) {
HIMC himc = ImmGetContext(videodata->ime_hwnd_current); HIMC himc = ImmGetContext(videodata->ime_hwnd_current);
......
...@@ -101,7 +101,7 @@ WIN_GL_LoadLibrary(_THIS, const char *path) ...@@ -101,7 +101,7 @@ WIN_GL_LoadLibrary(_THIS, const char *path)
!_this->gl_data->wglDeleteContext || !_this->gl_data->wglDeleteContext ||
!_this->gl_data->wglMakeCurrent) { !_this->gl_data->wglMakeCurrent) {
SDL_SetError("Could not retrieve OpenGL functions"); SDL_SetError("Could not retrieve OpenGL functions");
FreeLibrary(handle); SDL_UnloadObject(handle);
return -1; return -1;
} }
......
...@@ -37,19 +37,6 @@ ...@@ -37,19 +37,6 @@
static int WIN_VideoInit(_THIS); static int WIN_VideoInit(_THIS);
static void WIN_VideoQuit(_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 */ /* Windows driver bootstrap functions */
...@@ -68,22 +55,22 @@ WIN_DeleteDevice(SDL_VideoDevice * device) ...@@ -68,22 +55,22 @@ WIN_DeleteDevice(SDL_VideoDevice * device)
#if SDL_VIDEO_RENDER_D3D #if SDL_VIDEO_RENDER_D3D
if (data->d3d) { if (data->d3d) {
IDirect3D9_Release(data->d3d); IDirect3D9_Release(data->d3d);
FreeLibrary(data->d3dDLL); SDL_UnloadObject(data->d3dDLL);
} }
#endif #endif
#if SDL_VIDEO_RENDER_DDRAW #if SDL_VIDEO_RENDER_DDRAW
if (data->ddraw) { if (data->ddraw) {
data->ddraw->lpVtbl->Release(data->ddraw); data->ddraw->lpVtbl->Release(data->ddraw);
FreeLibrary(data->ddrawDLL); SDL_UnloadObject(data->ddrawDLL);
} }
#endif #endif
#ifdef _WIN32_WCE #ifdef _WIN32_WCE
if(data->hAygShell) { if(data->hAygShell) {
FreeLibrary(data->hAygShell); SDL_UnloadObject(data->hAygShell);
} }
#endif #endif
if (data->userDLL) { if (data->userDLL) {
FreeLibrary(data->userDLL); SDL_UnloadObject(data->userDLL);
} }
SDL_free(device->driverdata); SDL_free(device->driverdata);
...@@ -115,24 +102,24 @@ WIN_CreateDevice(int devindex) ...@@ -115,24 +102,24 @@ WIN_CreateDevice(int devindex)
device->driverdata = data; device->driverdata = data;
#if SDL_VIDEO_RENDER_D3D #if SDL_VIDEO_RENDER_D3D
data->d3dDLL = LoadLibrary(TEXT("D3D9.DLL")); data->d3dDLL = SDL_LoadObject("D3D9.DLL");
if (data->d3dDLL) { if (data->d3dDLL) {
IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion); IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion);
D3DCreate = D3DCreate =
(IDirect3D9 * (WINAPI *) (UINT)) GetProcAddress(data->d3dDLL, (IDirect3D9 * (WINAPI *) (UINT)) SDL_LoadFunction(data->d3dDLL,
"Direct3DCreate9"); "Direct3DCreate9");
if (D3DCreate) { if (D3DCreate) {
data->d3d = D3DCreate(D3D_SDK_VERSION); data->d3d = D3DCreate(D3D_SDK_VERSION);
} }
if (!data->d3d) { if (!data->d3d) {
FreeLibrary(data->d3dDLL); SDL_UnloadObject(data->d3dDLL);
data->d3dDLL = NULL; data->d3dDLL = NULL;
} }
} }
#endif /* SDL_VIDEO_RENDER_D3D */ #endif /* SDL_VIDEO_RENDER_D3D */
#if SDL_VIDEO_RENDER_DDRAW #if SDL_VIDEO_RENDER_DDRAW
data->ddrawDLL = LoadLibrary(TEXT("ddraw.dll")); data->ddrawDLL = SDL_LoadObject("ddraw.dll");
if (data->ddrawDLL) { if (data->ddrawDLL) {
IDirectDraw *(WINAPI * DDCreate) (GUID FAR * lpGUID, IDirectDraw *(WINAPI * DDCreate) (GUID FAR * lpGUID,
LPDIRECTDRAW FAR * lplpDD, LPDIRECTDRAW FAR * lplpDD,
...@@ -141,9 +128,9 @@ WIN_CreateDevice(int devindex) ...@@ -141,9 +128,9 @@ WIN_CreateDevice(int devindex)
DDCreate = DDCreate =
(IDirectDraw * (IDirectDraw *
(WINAPI *) (GUID FAR *, LPDIRECTDRAW FAR *, IUnknown FAR *)) (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) { if (!DDCreate || DDCreate(NULL, &data->ddraw, NULL) != DD_OK) {
FreeLibrary(data->ddrawDLL); SDL_UnloadObject(data->ddrawDLL);
data->ddrawDLL = NULL; data->ddrawDLL = NULL;
data->ddraw = NULL; data->ddraw = NULL;
} }
...@@ -151,19 +138,19 @@ WIN_CreateDevice(int devindex) ...@@ -151,19 +138,19 @@ WIN_CreateDevice(int devindex)
#endif /* SDL_VIDEO_RENDER_DDRAW */ #endif /* SDL_VIDEO_RENDER_DDRAW */
#ifdef _WIN32_WCE #ifdef _WIN32_WCE
data->hAygShell = LoadLibrary(TEXT("\\windows\\aygshell.dll")); data->hAygShell = SDL_LoadObject("\\windows\\aygshell.dll");
if(0 == data->hAygShell) if(0 == data->hAygShell)
data->hAygShell = LoadLibrary(TEXT("aygshell.dll")); data->hAygShell = SDL_LoadObject("aygshell.dll");
data->SHFullScreen = (0 != data->hAygShell ? data->SHFullScreen = (0 != data->hAygShell ?
(PFNSHFullScreen) GetProcAddress(data->hAygShell, TEXT("SHFullScreen")) : 0); (PFNSHFullScreen) SDL_LoadFunction(data->hAygShell, "SHFullScreen") : 0);
data->CoordTransform = NULL; data->CoordTransform = NULL;
#endif #endif
data->userDLL = LoadLibrary(TEXT("USER32.DLL")); data->userDLL = SDL_LoadObject("USER32.DLL");
if (data->userDLL) { if (data->userDLL) {
data->CloseTouchInputHandle = (BOOL (WINAPI *)( HTOUCHINPUT )) GetProcAddress(data->userDLL, TEXT("CloseTouchInputHandle")); data->CloseTouchInputHandle = (BOOL (WINAPI *)( HTOUCHINPUT )) SDL_LoadFunction(data->userDLL, "CloseTouchInputHandle");
data->GetTouchInputInfo = (BOOL (WINAPI *)( HTOUCHINPUT, UINT, PTOUCHINPUT, int )) GetProcAddress(data->userDLL, TEXT("GetTouchInputInfo")); data->GetTouchInputInfo = (BOOL (WINAPI *)( HTOUCHINPUT, UINT, PTOUCHINPUT, int )) SDL_LoadFunction(data->userDLL, "GetTouchInputInfo");
data->RegisterTouchWindow = (BOOL (WINAPI *)( HWND, ULONG )) GetProcAddress(data->userDLL, TEXT("RegisterTouchWindow")); data->RegisterTouchWindow = (BOOL (WINAPI *)( HWND, ULONG )) SDL_LoadFunction(data->userDLL, "RegisterTouchWindow");
} }
/* Set the function pointers */ /* Set the function pointers */
......
...@@ -26,15 +26,7 @@ ...@@ -26,15 +26,7 @@
#include "../SDL_sysvideo.h" #include "../SDL_sysvideo.h"
#define WIN32_LEAN_AND_MEAN #include "../../core/windows/SDL_windows.h"
#define STRICT
#ifndef UNICODE
#define UNICODE
#endif
#undef WINVER
#define WINVER 0x500 /* Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices() */
#include <windows.h>
#if defined(_MSC_VER) && !defined(_WIN32_WCE) #if defined(_MSC_VER) && !defined(_WIN32_WCE)
#include <msctf.h> #include <msctf.h>
...@@ -68,15 +60,8 @@ ...@@ -68,15 +60,8 @@
#include "SDL_windowsopengl.h" #include "SDL_windowsopengl.h"
#include "SDL_windowswindow.h" #include "SDL_windowswindow.h"
#include "SDL_events.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 }; enum { RENDER_NONE, RENDER_D3D, RENDER_DDRAW, RENDER_GDI, RENDER_GAPI, RENDER_RAW };
...@@ -147,15 +132,15 @@ typedef struct SDL_VideoData ...@@ -147,15 +132,15 @@ typedef struct SDL_VideoData
int render; int render;
#if SDL_VIDEO_RENDER_D3D #if SDL_VIDEO_RENDER_D3D
HANDLE d3dDLL; void* d3dDLL;
IDirect3D9 *d3d; IDirect3D9 *d3d;
#endif #endif
#if SDL_VIDEO_RENDER_DDRAW #if SDL_VIDEO_RENDER_DDRAW
HANDLE ddrawDLL; void* ddrawDLL;
IDirectDraw *ddraw; IDirectDraw *ddraw;
#endif #endif
#ifdef _WIN32_WCE #ifdef _WIN32_WCE
HMODULE hAygShell; void* hAygShell;
PFNSHFullScreen SHFullScreen; PFNSHFullScreen SHFullScreen;
PFCoordTransform CoordTransform; PFCoordTransform CoordTransform;
#endif #endif
...@@ -164,7 +149,7 @@ typedef struct SDL_VideoData ...@@ -164,7 +149,7 @@ typedef struct SDL_VideoData
DWORD clipboard_count; DWORD clipboard_count;
/* Touch input functions */ /* Touch input functions */
HANDLE userDLL; void* userDLL;
BOOL (WINAPI *CloseTouchInputHandle)( HTOUCHINPUT ); BOOL (WINAPI *CloseTouchInputHandle)( HTOUCHINPUT );
BOOL (WINAPI *GetTouchInputInfo)( HTOUCHINPUT, UINT, PTOUCHINPUT, int ); BOOL (WINAPI *GetTouchInputInfo)( HTOUCHINPUT, UINT, PTOUCHINPUT, int );
BOOL (WINAPI *RegisterTouchWindow)( HWND, ULONG ); BOOL (WINAPI *RegisterTouchWindow)( HWND, ULONG );
...@@ -199,7 +184,7 @@ typedef struct SDL_VideoData ...@@ -199,7 +184,7 @@ typedef struct SDL_VideoData
int ime_winheight; int ime_winheight;
HKL ime_hkl; HKL ime_hkl;
HMODULE ime_himm32; void* ime_himm32;
UINT (WINAPI *GetReadingString)(HIMC himc, UINT uReadingBufLen, LPWSTR lpwReadingBuf, PINT pnErrorIndex, BOOL *pfIsVertical, PUINT puMaxReadingLen); UINT (WINAPI *GetReadingString)(HIMC himc, UINT uReadingBufLen, LPWSTR lpwReadingBuf, PINT pnErrorIndex, BOOL *pfIsVertical, PUINT puMaxReadingLen);
BOOL (WINAPI *ShowReadingWindow)(HIMC himc, BOOL bShow); BOOL (WINAPI *ShowReadingWindow)(HIMC himc, BOOL bShow);
LPINPUTCONTEXT2 (WINAPI *ImmLockIMC)(HIMC himc); LPINPUTCONTEXT2 (WINAPI *ImmLockIMC)(HIMC himc);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment