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.
authorSam Lantinga <slouken@libsdl.org>
Mon, 24 Jan 2011 21:20:30 -0800
changeset 5090327f181542f1
parent 5089 79bd1e289005
child 5091 2164a79b5ca9
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
VisualC/SDL/SDL_VS2008.vcproj
VisualC/SDL/SDL_VS2010.vcxproj
VisualCE/SDL/SDL.vcproj
src/SDL.c
src/SDL_android.cpp
src/SDL_android.h
src/SDL_assert.c
src/atomic/SDL_spinlock.c
src/audio/android/SDL_androidaudio.c
src/audio/windib/SDL_dibaudio.c
src/audio/windx5/SDL_dx5audio.c
src/audio/windx5/directx.h
src/core/android/SDL_android.cpp
src/core/android/SDL_android.h
src/core/windows/SDL_windows.c
src/core/windows/SDL_windows.h
src/cpuinfo/SDL_cpuinfo.c
src/file/SDL_rwops.c
src/haptic/windows/SDL_syshaptic.c
src/joystick/android/SDL_sysjoystick.c
src/joystick/windows/SDL_dxjoystick.c
src/joystick/windows/SDL_dxjoystick_c.h
src/joystick/windows/SDL_mmjoystick.c
src/loadso/windows/SDL_sysloadso.c
src/power/windows/SDL_syspower.c
src/stdlib/SDL_getenv.c
src/thread/windows/SDL_sysmutex.c
src/thread/windows/SDL_syssem.c
src/thread/windows/SDL_systhread_c.h
src/thread/windows/win_ce_semaphore.c
src/timer/wince/SDL_systimer.c
src/timer/windows/SDL_systimer.c
src/video/android/SDL_androidgl.c
src/video/windows/SDL_gapirender.c
src/video/windows/SDL_windowskeyboard.c
src/video/windows/SDL_windowsopengl.c
src/video/windows/SDL_windowsvideo.c
src/video/windows/SDL_windowsvideo.h
     1.1 --- a/Android.mk	Mon Jan 24 17:47:18 2011 -0800
     1.2 +++ b/Android.mk	Mon Jan 24 21:20:30 2011 -0800
     1.3 @@ -12,30 +12,31 @@
     1.4  
     1.5  LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
     1.6  
     1.7 -LOCAL_SRC_FILES := src/SDL_android.cpp \
     1.8 +LOCAL_SRC_FILES := \
     1.9  	$(subst $(LOCAL_PATH)/,, \
    1.10  	$(wildcard $(LOCAL_PATH)/src/*.c) \
    1.11  	$(wildcard $(LOCAL_PATH)/src/audio/*.c) \
    1.12 +	$(wildcard $(LOCAL_PATH)/src/audio/android/*.c) \
    1.13 +	$(wildcard $(LOCAL_PATH)/src/audio/dummy/*.c) \
    1.14  	$(LOCAL_PATH)/src/atomic/SDL_atomic.c \
    1.15  	$(LOCAL_PATH)/src/atomic/SDL_spinlock.c.arm \
    1.16 +	$(wildcard $(LOCAL_PATH)/src/core/android/*.cpp) \
    1.17  	$(wildcard $(LOCAL_PATH)/src/cpuinfo/*.c) \
    1.18  	$(wildcard $(LOCAL_PATH)/src/events/*.c) \
    1.19  	$(wildcard $(LOCAL_PATH)/src/file/*.c) \
    1.20 +	$(wildcard $(LOCAL_PATH)/src/haptic/*.c) \
    1.21 +	$(wildcard $(LOCAL_PATH)/src/haptic/dummy/*.c) \
    1.22  	$(wildcard $(LOCAL_PATH)/src/joystick/*.c) \
    1.23 -	$(wildcard $(LOCAL_PATH)/src/haptic/*.c) \
    1.24 +	$(wildcard $(LOCAL_PATH)/src/joystick/android/*.c) \
    1.25 +	$(wildcard $(LOCAL_PATH)/src/loadso/dlopen/*.c)) \
    1.26 +	$(wildcard $(LOCAL_PATH)/src/power/*.c) \
    1.27  	$(wildcard $(LOCAL_PATH)/src/stdlib/*.c) \
    1.28  	$(wildcard $(LOCAL_PATH)/src/thread/*.c) \
    1.29 +	$(wildcard $(LOCAL_PATH)/src/thread/pthread/*.c) \
    1.30  	$(wildcard $(LOCAL_PATH)/src/timer/*.c) \
    1.31 +	$(wildcard $(LOCAL_PATH)/src/timer/unix/*.c) \
    1.32  	$(wildcard $(LOCAL_PATH)/src/video/*.c) \
    1.33 -	$(wildcard $(LOCAL_PATH)/src/power/*.c) \
    1.34 -	$(wildcard $(LOCAL_PATH)/src/audio/android/*.c) \
    1.35 -	$(wildcard $(LOCAL_PATH)/src/audio/dummy/*.c) \
    1.36 -	$(wildcard $(LOCAL_PATH)/src/video/android/*.c) \
    1.37 -	$(wildcard $(LOCAL_PATH)/src/joystick/android/*.c) \
    1.38 -	$(wildcard $(LOCAL_PATH)/src/haptic/dummy/*.c) \
    1.39 -	$(wildcard $(LOCAL_PATH)/src/thread/pthread/*.c) \
    1.40 -	$(wildcard $(LOCAL_PATH)/src/timer/unix/*.c) \
    1.41 -	$(wildcard $(LOCAL_PATH)/src/loadso/dlopen/*.c))
    1.42 +	$(wildcard $(LOCAL_PATH)/src/video/android/*.c)
    1.43  
    1.44  LOCAL_LDLIBS := -ldl -lGLESv1_CM -llog
    1.45  
     2.1 --- a/VisualC/SDL/SDL_VS2008.vcproj	Mon Jan 24 17:47:18 2011 -0800
     2.2 +++ b/VisualC/SDL/SDL_VS2008.vcproj	Mon Jan 24 21:20:30 2011 -0800
     2.3 @@ -1151,6 +1151,22 @@
     2.4  			>
     2.5  		</File>
     2.6  		<File
     2.7 +			RelativePath="..\..\src\events\SDL_windowevents.c"
     2.8 +			>
     2.9 +		</File>
    2.10 +		<File
    2.11 +			RelativePath="..\..\src\events\SDL_windowevents_c.h"
    2.12 +			>
    2.13 +		</File>
    2.14 +		<File
    2.15 +			RelativePath="..\..\src\core\windows\SDL_windows.c"
    2.16 +			>
    2.17 +		</File>
    2.18 +		<File
    2.19 +			RelativePath="..\..\src\core\windows\SDL_windows.h"
    2.20 +			>
    2.21 +		</File>
    2.22 +		<File
    2.23  			RelativePath="..\..\src\video\windows\SDL_windowsclipboard.c"
    2.24  			>
    2.25  		</File>
    2.26 @@ -1231,14 +1247,6 @@
    2.27  			>
    2.28  		</File>
    2.29  		<File
    2.30 -			RelativePath="..\..\src\events\SDL_windowevents.c"
    2.31 -			>
    2.32 -		</File>
    2.33 -		<File
    2.34 -			RelativePath="..\..\src\events\SDL_windowevents_c.h"
    2.35 -			>
    2.36 -		</File>
    2.37 -		<File
    2.38  			RelativePath="..\..\src\video\SDL_yuv_mmx.c"
    2.39  			>
    2.40  		</File>
     3.1 --- a/VisualC/SDL/SDL_VS2010.vcxproj	Mon Jan 24 17:47:18 2011 -0800
     3.2 +++ b/VisualC/SDL/SDL_VS2010.vcxproj	Mon Jan 24 21:20:30 2011 -0800
     3.3 @@ -272,6 +272,7 @@
     3.4      <ClInclude Include="..\..\include\SDL_types.h" />
     3.5      <ClInclude Include="..\..\include\SDL_version.h" />
     3.6      <ClInclude Include="..\..\include\SDL_video.h" />
     3.7 +    <ClInclude Include="..\..\src\core\windows\SDL_windows.h" />
     3.8      <ClInclude Include="..\..\src\events\blank_cursor.h" />
     3.9      <ClInclude Include="..\..\src\events\default_cursor.h" />
    3.10      <ClInclude Include="..\..\src\audio\windx5\directx.h" />
    3.11 @@ -345,6 +346,7 @@
    3.12      <ClInclude Include="..\..\src\video\windows\wmmsg.h" />
    3.13    </ItemGroup>
    3.14    <ItemGroup>
    3.15 +    <ClCompile Include="..\..\src\core\windows\SDL_windows.c" />
    3.16      <ClCompile Include="..\..\src\events\SDL_clipboardevents.c" />
    3.17      <ClCompile Include="..\..\src\events\SDL_gesture.c" />
    3.18      <ClCompile Include="..\..\src\events\SDL_touch.c" />
    3.19 @@ -460,4 +462,4 @@
    3.20    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
    3.21    <ImportGroup Label="ExtensionTargets">
    3.22    </ImportGroup>
    3.23 -</Project>
    3.24 +</Project>
    3.25 \ No newline at end of file
     4.1 --- a/VisualCE/SDL/SDL.vcproj	Mon Jan 24 17:47:18 2011 -0800
     4.2 +++ b/VisualCE/SDL/SDL.vcproj	Mon Jan 24 21:20:30 2011 -0800
     4.3 @@ -1054,6 +1054,10 @@
     4.4  				>
     4.5  			</File>
     4.6  			<File
     4.7 +				RelativePath="..\..\src\core\windows\SDL_windows.c"
     4.8 +				>
     4.9 +			</File>
    4.10 +			<File
    4.11  				RelativePath="..\..\src\video\windows\SDL_windowsclipboard.c"
    4.12  				>
    4.13  			</File>
    4.14 @@ -1359,6 +1363,10 @@
    4.15  				>
    4.16  			</File>
    4.17  			<File
    4.18 +				RelativePath="..\..\src\core\windows\SDL_windows.h"
    4.19 +				>
    4.20 +			</File>
    4.21 +			<File
    4.22  				RelativePath="..\..\src\video\windows\SDL_windowsclipboard.h"
    4.23  				>
    4.24  			</File>
     5.1 --- a/src/SDL.c	Mon Jan 24 17:47:18 2011 -0800
     5.2 +++ b/src/SDL.c	Mon Jan 24 21:20:30 2011 -0800
     5.3 @@ -329,8 +329,7 @@
     5.4  
     5.5  #if !defined(HAVE_LIBC) || (defined(__WATCOMC__) && defined(BUILD_DLL))
     5.6  /* Need to include DllMain() on Watcom C for some reason.. */
     5.7 -#define WIN32_LEAN_AND_MEAN
     5.8 -#include <windows.h>
     5.9 +#include "core/windows/SDL_windows.h"
    5.10  
    5.11  BOOL APIENTRY
    5.12  _DllMainCRTStartup(HANDLE hModule,
     6.1 --- a/src/SDL_android.cpp	Mon Jan 24 17:47:18 2011 -0800
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,258 +0,0 @@
     6.4 -/*
     6.5 -    SDL - Simple DirectMedia Layer
     6.6 -    Copyright (C) 1997-2010 Sam Lantinga
     6.7 -
     6.8 -    This library is free software; you can redistribute it and/or
     6.9 -    modify it under the terms of the GNU Lesser General Public
    6.10 -    License as published by the Free Software Foundation; either
    6.11 -    version 2.1 of the License, or (at your option) any later version.
    6.12 -
    6.13 -    This library is distributed in the hope that it will be useful,
    6.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    6.16 -    Lesser General Public License for more details.
    6.17 -
    6.18 -    You should have received a copy of the GNU Lesser General Public
    6.19 -    License along with this library; if not, write to the Free Software
    6.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    6.21 -
    6.22 -    Sam Lantinga
    6.23 -    slouken@libsdl.org
    6.24 -*/
    6.25 -#include "SDL_config.h"
    6.26 -
    6.27 -#include "SDL_android.h"
    6.28 -
    6.29 -extern "C" {
    6.30 -#include "events/SDL_events_c.h"
    6.31 -#include "video/android/SDL_androidkeyboard.h"
    6.32 -#include "video/android/SDL_androidtouch.h"
    6.33 -#include "video/android/SDL_androidvideo.h"
    6.34 -
    6.35 -/* Impelemented in audio/android/SDL_androidaudio.c */
    6.36 -extern void Android_RunAudioThread();
    6.37 -} // C
    6.38 -
    6.39 -/*******************************************************************************
    6.40 - This file links the Java side of Android with libsdl
    6.41 -*******************************************************************************/
    6.42 -#include <jni.h>
    6.43 -#include <android/log.h>
    6.44 -
    6.45 -
    6.46 -/*******************************************************************************
    6.47 -                               Globals
    6.48 -*******************************************************************************/
    6.49 -static JNIEnv* mEnv = NULL;
    6.50 -static JNIEnv* mAudioEnv = NULL;
    6.51 -
    6.52 -// Main activity
    6.53 -static jclass mActivityClass;
    6.54 -
    6.55 -// method signatures
    6.56 -static jmethodID midCreateGLContext;
    6.57 -static jmethodID midFlipBuffers;
    6.58 -static jmethodID midAudioInit;
    6.59 -static jmethodID midAudioWriteShortBuffer;
    6.60 -static jmethodID midAudioWriteByteBuffer;
    6.61 -static jmethodID midAudioQuit;
    6.62 -
    6.63 -// Accelerometer data storage
    6.64 -static float fLastAccelerometer[3];
    6.65 -
    6.66 -
    6.67 -/*******************************************************************************
    6.68 -                 Functions called by JNI
    6.69 -*******************************************************************************/
    6.70 -
    6.71 -// Library init
    6.72 -extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
    6.73 -{
    6.74 -    return JNI_VERSION_1_4;
    6.75 -}
    6.76 -
    6.77 -// Called before SDL_main() to initialize JNI bindings
    6.78 -extern "C" void SDL_Android_Init(JNIEnv* env, jclass cls)
    6.79 -{
    6.80 -    __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL_Android_Init()");
    6.81 -
    6.82 -    mEnv = env;
    6.83 -    mActivityClass = cls;
    6.84 -
    6.85 -    midCreateGLContext = mEnv->GetStaticMethodID(mActivityClass,
    6.86 -                                "createGLContext","()V");
    6.87 -    midFlipBuffers = mEnv->GetStaticMethodID(mActivityClass,
    6.88 -                                "flipBuffers","()V");
    6.89 -    midAudioInit = mEnv->GetStaticMethodID(mActivityClass, 
    6.90 -                                "audioInit", "(IZZI)Ljava/lang/Object;");
    6.91 -    midAudioWriteShortBuffer = mEnv->GetStaticMethodID(mActivityClass,
    6.92 -                                "audioWriteShortBuffer", "([S)V");
    6.93 -    midAudioWriteByteBuffer = mEnv->GetStaticMethodID(mActivityClass,
    6.94 -                                "audioWriteByteBuffer", "([B)V");
    6.95 -    midAudioQuit = mEnv->GetStaticMethodID(mActivityClass,
    6.96 -                                "audioQuit", "()V");
    6.97 -
    6.98 -    if(!midCreateGLContext || !midFlipBuffers || !midAudioInit ||
    6.99 -       !midAudioWriteShortBuffer || !midAudioWriteByteBuffer || !midAudioQuit) {
   6.100 -        __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL: Couldn't locate Java callbacks, check that they're named and typed correctly");
   6.101 -    }
   6.102 -}
   6.103 -
   6.104 -// Resize
   6.105 -extern "C" void Java_org_libsdl_app_SDLActivity_onNativeResize(
   6.106 -                                    JNIEnv* env, jclass jcls,
   6.107 -                                    jint width, jint height, jint format)
   6.108 -{
   6.109 -    Android_SetScreenResolution(width, height, format);
   6.110 -}
   6.111 -
   6.112 -// Keydown
   6.113 -extern "C" void Java_org_libsdl_app_SDLActivity_onNativeKeyDown(
   6.114 -                                    JNIEnv* env, jclass jcls, jint keycode)
   6.115 -{
   6.116 -    Android_OnKeyDown(keycode);
   6.117 -}
   6.118 -
   6.119 -// Keyup
   6.120 -extern "C" void Java_org_libsdl_app_SDLActivity_onNativeKeyUp(
   6.121 -                                    JNIEnv* env, jclass jcls, jint keycode)
   6.122 -{
   6.123 -    Android_OnKeyUp(keycode);
   6.124 -}
   6.125 -
   6.126 -// Touch
   6.127 -extern "C" void Java_org_libsdl_app_SDLActivity_onNativeTouch(
   6.128 -                                    JNIEnv* env, jclass jcls,
   6.129 -                                    jint action, jfloat x, jfloat y, jfloat p)
   6.130 -{
   6.131 -    Android_OnTouch(action, x, y, p);
   6.132 -}
   6.133 -
   6.134 -// Accelerometer
   6.135 -extern "C" void Java_org_libsdl_app_SDLActivity_onNativeAccel(
   6.136 -                                    JNIEnv* env, jclass jcls,
   6.137 -                                    jfloat x, jfloat y, jfloat z)
   6.138 -{
   6.139 -    fLastAccelerometer[0] = x;
   6.140 -    fLastAccelerometer[1] = y;
   6.141 -    fLastAccelerometer[2] = z;   
   6.142 -}
   6.143 -
   6.144 -// Quit
   6.145 -extern "C" void Java_org_libsdl_app_SDLActivity_nativeQuit(
   6.146 -                                    JNIEnv* env, jclass cls)
   6.147 -{    
   6.148 -    // Inject a SDL_QUIT event
   6.149 -    SDL_SendQuit();
   6.150 -}
   6.151 -
   6.152 -extern "C" void Java_org_libsdl_app_SDLActivity_nativeRunAudioThread(
   6.153 -                                    JNIEnv* env, jclass cls)
   6.154 -{
   6.155 -    /* This is the audio thread, with a different environment */
   6.156 -    mAudioEnv = env;
   6.157 -
   6.158 -    Android_RunAudioThread();
   6.159 -}
   6.160 -
   6.161 -
   6.162 -/*******************************************************************************
   6.163 -             Functions called by SDL into Java
   6.164 -*******************************************************************************/
   6.165 -extern "C" void Android_JNI_CreateContext()
   6.166 -{
   6.167 -    mEnv->CallStaticVoidMethod(mActivityClass, midCreateGLContext); 
   6.168 -}
   6.169 -
   6.170 -extern "C" void Android_JNI_SwapWindow()
   6.171 -{
   6.172 -    mEnv->CallStaticVoidMethod(mActivityClass, midFlipBuffers); 
   6.173 -}
   6.174 -
   6.175 -extern "C" void Android_JNI_SetActivityTitle(const char *title)
   6.176 -{
   6.177 -    jmethodID mid;
   6.178 -
   6.179 -    mid = mEnv->GetStaticMethodID(mActivityClass,"setActivityTitle","(Ljava/lang/String;)V");
   6.180 -    if (mid) {
   6.181 -        mEnv->CallStaticVoidMethod(mActivityClass, mid, mEnv->NewStringUTF(title));
   6.182 -    }
   6.183 -}
   6.184 -
   6.185 -extern "C" void Android_JNI_GetAccelerometerValues(float values[3])
   6.186 -{
   6.187 -    int i;
   6.188 -    for (i = 0; i < 3; ++i) {
   6.189 -        values[i] = fLastAccelerometer[i];
   6.190 -    }
   6.191 -}
   6.192 -
   6.193 -//
   6.194 -// Audio support
   6.195 -//
   6.196 -static jboolean audioBuffer16Bit = JNI_FALSE;
   6.197 -static jboolean audioBufferStereo = JNI_FALSE;
   6.198 -static jobject audioBuffer = NULL;
   6.199 -static void* audioBufferPinned = NULL;
   6.200 -
   6.201 -extern "C" int Android_JNI_OpenAudioDevice(int sampleRate, int is16Bit, int channelCount, int desiredBufferFrames)
   6.202 -{
   6.203 -    int audioBufferFrames;
   6.204 -
   6.205 -    __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "SDL audio: opening device");
   6.206 -    audioBuffer16Bit = is16Bit;
   6.207 -    audioBufferStereo = channelCount > 1;
   6.208 -
   6.209 -    audioBuffer = mEnv->CallStaticObjectMethod(mActivityClass, midAudioInit, sampleRate, audioBuffer16Bit, audioBufferStereo, desiredBufferFrames);
   6.210 -
   6.211 -    if (audioBuffer == NULL) {
   6.212 -        __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL audio: didn't get back a good audio buffer!");
   6.213 -        return 0;
   6.214 -    }
   6.215 -    audioBuffer = mEnv->NewGlobalRef(audioBuffer);
   6.216 -
   6.217 -    jboolean isCopy = JNI_FALSE;
   6.218 -    if (audioBuffer16Bit) {
   6.219 -        audioBufferPinned = mEnv->GetShortArrayElements((jshortArray)audioBuffer, &isCopy);
   6.220 -        audioBufferFrames = mEnv->GetArrayLength((jshortArray)audioBuffer);
   6.221 -    } else {
   6.222 -        audioBufferPinned = mEnv->GetByteArrayElements((jbyteArray)audioBuffer, &isCopy);
   6.223 -        audioBufferFrames = mEnv->GetArrayLength((jbyteArray)audioBuffer);
   6.224 -    }
   6.225 -    if (audioBufferStereo) {
   6.226 -        audioBufferFrames /= 2;
   6.227 -    }
   6.228 -
   6.229 -    return audioBufferFrames;
   6.230 -}
   6.231 -
   6.232 -extern "C" void * Android_JNI_GetAudioBuffer()
   6.233 -{
   6.234 -    return audioBufferPinned;
   6.235 -}
   6.236 -
   6.237 -extern "C" void Android_JNI_WriteAudioBuffer()
   6.238 -{
   6.239 -    if (audioBuffer16Bit) {
   6.240 -        mAudioEnv->ReleaseShortArrayElements((jshortArray)audioBuffer, (jshort *)audioBufferPinned, JNI_COMMIT);
   6.241 -        mAudioEnv->CallStaticVoidMethod(mActivityClass, midAudioWriteShortBuffer, (jshortArray)audioBuffer);
   6.242 -    } else {
   6.243 -        mAudioEnv->ReleaseByteArrayElements((jbyteArray)audioBuffer, (jbyte *)audioBufferPinned, JNI_COMMIT);
   6.244 -        mAudioEnv->CallStaticVoidMethod(mActivityClass, midAudioWriteByteBuffer, (jbyteArray)audioBuffer);
   6.245 -    }
   6.246 -
   6.247 -    /* JNI_COMMIT means the changes are committed to the VM but the buffer remains pinned */
   6.248 -}
   6.249 -
   6.250 -extern "C" void Android_JNI_CloseAudioDevice()
   6.251 -{
   6.252 -    mEnv->CallStaticVoidMethod(mActivityClass, midAudioQuit); 
   6.253 -
   6.254 -    if (audioBuffer) {
   6.255 -        mEnv->DeleteGlobalRef(audioBuffer);
   6.256 -        audioBuffer = NULL;
   6.257 -        audioBufferPinned = NULL;
   6.258 -    }
   6.259 -}
   6.260 -
   6.261 -/* vi: set ts=4 sw=4 expandtab: */
     7.1 --- a/src/SDL_android.h	Mon Jan 24 17:47:18 2011 -0800
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,50 +0,0 @@
     7.4 -/*
     7.5 -    SDL - Simple DirectMedia Layer
     7.6 -    Copyright (C) 1997-2010 Sam Lantinga
     7.7 -
     7.8 -    This library is free software; you can redistribute it and/or
     7.9 -    modify it under the terms of the GNU Lesser General Public
    7.10 -    License as published by the Free Software Foundation; either
    7.11 -    version 2.1 of the License, or (at your option) any later version.
    7.12 -
    7.13 -    This library is distributed in the hope that it will be useful,
    7.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    7.16 -    Lesser General Public License for more details.
    7.17 -
    7.18 -    You should have received a copy of the GNU Lesser General Public
    7.19 -    License along with this library; if not, write to the Free Software
    7.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    7.21 -
    7.22 -    Sam Lantinga
    7.23 -    slouken@libsdl.org
    7.24 -*/
    7.25 -#include "SDL_config.h"
    7.26 -
    7.27 -/* Set up for C function definitions, even when using C++ */
    7.28 -#ifdef __cplusplus
    7.29 -/* *INDENT-OFF* */
    7.30 -extern "C" {
    7.31 -/* *INDENT-ON* */
    7.32 -#endif
    7.33 -
    7.34 -/* Interface from the SDL library into the Android Java activity */
    7.35 -extern void Android_JNI_CreateContext();
    7.36 -extern void Android_JNI_SwapWindow();
    7.37 -extern void Android_JNI_SetActivityTitle(const char *title);
    7.38 -extern void Android_JNI_GetAccelerometerValues(float values[3]);
    7.39 -
    7.40 -// Audio support
    7.41 -extern int Android_JNI_OpenAudioDevice(int sampleRate, int is16Bit, int channelCount, int desiredBufferFrames);
    7.42 -extern void* Android_JNI_GetAudioBuffer();
    7.43 -extern void Android_JNI_WriteAudioBuffer();
    7.44 -extern void Android_JNI_CloseAudioDevice();
    7.45 -
    7.46 -/* Ends C function definitions when using C++ */
    7.47 -#ifdef __cplusplus
    7.48 -/* *INDENT-OFF* */
    7.49 -}
    7.50 -/* *INDENT-ON* */
    7.51 -#endif
    7.52 -
    7.53 -/* vi: set ts=4 sw=4 expandtab: */
     8.1 --- a/src/SDL_assert.c	Mon Jan 24 17:47:18 2011 -0800
     8.2 +++ b/src/SDL_assert.c	Mon Jan 24 21:20:30 2011 -0800
     8.3 @@ -27,18 +27,11 @@
     8.4  #include "video/SDL_sysvideo.h"
     8.5  
     8.6  #ifdef __WIN32__
     8.7 -#define WIN32_LEAN_AND_MEAN
     8.8 -#include <windows.h>
     8.9 +#include "core/windows/SDL_windows.h"
    8.10  
    8.11  #ifndef WS_OVERLAPPEDWINDOW
    8.12  #define WS_OVERLAPPEDWINDOW 0
    8.13  #endif
    8.14 -
    8.15 -#ifdef UNICODE
    8.16 -#define WIN_UTF8ToString(S) (WCHAR *)SDL_iconv_string("UCS-2", "UTF-8", (char *)S, SDL_strlen(S)+1)
    8.17 -#else
    8.18 -#define WIN_UTF8ToString(S) SDL_iconv_string("ASCII", "UTF-8", (char *)S, SDL_strlen(S)+1)
    8.19 -#endif
    8.20  #else  /* fprintf, _exit(), etc. */
    8.21  #include <stdio.h>
    8.22  #include <stdlib.h>
     9.1 --- a/src/atomic/SDL_spinlock.c	Mon Jan 24 17:47:18 2011 -0800
     9.2 +++ b/src/atomic/SDL_spinlock.c	Mon Jan 24 21:20:30 2011 -0800
     9.3 @@ -25,14 +25,7 @@
     9.4  #include "SDL_timer.h"
     9.5  
     9.6  /* Don't do the check for Visual Studio 2005, it's safe here */
     9.7 -#if defined(_MSC_VER)
     9.8 -#ifdef _WIN32_WCE
     9.9 -#define WIN32_LEAN_AND_MEAN
    9.10 -#include <windows.h>
    9.11 -#else
    9.12 -#include <intrin.h>
    9.13 -#endif
    9.14 -#endif /* _MSC_VER */
    9.15 +#include "../core/windows/SDL_windows.h"
    9.16  
    9.17  /* This function is where all the magic happens... */
    9.18  SDL_bool
    9.19 @@ -40,7 +33,7 @@
    9.20  {
    9.21  #if defined(_MSC_VER)
    9.22      SDL_COMPILE_TIME_ASSERT(locksize, sizeof(*lock) == sizeof(long));
    9.23 -    return (_InterlockedExchange((long*)lock, 1) == 0);
    9.24 +    return (InterlockedExchange((long*)lock, 1) == 0);
    9.25  
    9.26  #elif defined(__MACOSX__)
    9.27      return OSAtomicCompareAndSwap32Barrier(0, 1, lock);
    10.1 --- a/src/audio/android/SDL_androidaudio.c	Mon Jan 24 17:47:18 2011 -0800
    10.2 +++ b/src/audio/android/SDL_androidaudio.c	Mon Jan 24 21:20:30 2011 -0800
    10.3 @@ -27,7 +27,7 @@
    10.4  #include "../SDL_audio_c.h"
    10.5  #include "SDL_androidaudio.h"
    10.6  
    10.7 -#include "../../SDL_android.h"
    10.8 +#include "../../core/android/SDL_android.h"
    10.9  
   10.10  #include <android/log.h>
   10.11  
    11.1 --- a/src/audio/windib/SDL_dibaudio.c	Mon Jan 24 17:47:18 2011 -0800
    11.2 +++ b/src/audio/windib/SDL_dibaudio.c	Mon Jan 24 21:20:30 2011 -0800
    11.3 @@ -23,8 +23,7 @@
    11.4  
    11.5  /* Allow access to a raw mixing buffer */
    11.6  
    11.7 -#define WIN32_LEAN_AND_MEAN
    11.8 -#include <windows.h>
    11.9 +#include "../../core/windows/SDL_windows.h"
   11.10  #include <mmsystem.h>
   11.11  
   11.12  #include "SDL_timer.h"
   11.13 @@ -67,21 +66,14 @@
   11.14  {
   11.15      size_t len;
   11.16      char errbuf[MAXERRORLENGTH];
   11.17 -#ifdef _WIN32_WCE
   11.18      wchar_t werrbuf[MAXERRORLENGTH];
   11.19 -#endif
   11.20  
   11.21      SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: ", function);
   11.22      len = SDL_strlen(errbuf);
   11.23  
   11.24 -#ifdef _WIN32_WCE
   11.25 -    /* UNICODE version */
   11.26      waveOutGetErrorText(code, werrbuf, MAXERRORLENGTH - len);
   11.27      WideCharToMultiByte(CP_ACP, 0, werrbuf, -1, errbuf + len,
   11.28                          MAXERRORLENGTH - len, NULL, NULL);
   11.29 -#else
   11.30 -    waveOutGetErrorText(code, errbuf + len, (UINT) (MAXERRORLENGTH - len));
   11.31 -#endif
   11.32  
   11.33      SDL_SetError("%s", errbuf);
   11.34  }
    12.1 --- a/src/audio/windx5/SDL_dx5audio.c	Mon Jan 24 17:47:18 2011 -0800
    12.2 +++ b/src/audio/windx5/SDL_dx5audio.c	Mon Jan 24 21:20:30 2011 -0800
    12.3 @@ -24,6 +24,7 @@
    12.4  /* Allow access to a raw mixing buffer */
    12.5  
    12.6  #include "SDL_timer.h"
    12.7 +#include "SDL_loadso.h"
    12.8  #include "SDL_audio.h"
    12.9  #include "../SDL_audio_c.h"
   12.10  #include "SDL_dx5audio.h"
   12.11 @@ -38,19 +39,19 @@
   12.12  #endif
   12.13  
   12.14  /* DirectX function pointers for audio */
   12.15 -static HINSTANCE DSoundDLL = NULL;
   12.16 +static void* DSoundDLL = NULL;
   12.17  static HRESULT(WINAPI * DSoundCreate) (LPGUID, LPDIRECTSOUND *, LPUNKNOWN) =
   12.18      NULL;
   12.19  
   12.20  static void
   12.21  DSOUND_Unload(void)
   12.22  {
   12.23 +    DSoundCreate = NULL;
   12.24 +
   12.25      if (DSoundDLL != NULL) {
   12.26 -        FreeLibrary(DSoundDLL);
   12.27 +        SDL_UnloadObject(DSoundDLL);
   12.28 +        DSoundDLL = NULL;
   12.29      }
   12.30 -
   12.31 -    DSoundCreate = NULL;
   12.32 -    DSoundDLL = NULL;
   12.33  }
   12.34  
   12.35  
   12.36 @@ -61,17 +62,16 @@
   12.37  
   12.38      DSOUND_Unload();
   12.39  
   12.40 -    DSoundDLL = LoadLibrary(TEXT("DSOUND.DLL"));
   12.41 +    DSoundDLL = SDL_LoadObject("DSOUND.DLL");
   12.42      if (DSoundDLL == NULL) {
   12.43          SDL_SetError("DirectSound: failed to load DSOUND.DLL");
   12.44      } else {
   12.45          /* Now make sure we have DirectX 5 or better... */
   12.46          /*  (DirectSoundCaptureCreate was added in DX5) */
   12.47 -        if (!GetProcAddress(DSoundDLL, TEXT("DirectSoundCaptureCreate"))) {
   12.48 +        if (!SDL_LoadFunction(DSoundDLL, "DirectSoundCaptureCreate")) {
   12.49              SDL_SetError("DirectSound: System doesn't appear to have DX5.");
   12.50          } else {
   12.51 -            DSoundCreate = (void *) GetProcAddress(DSoundDLL,
   12.52 -                                                   TEXT("DirectSoundCreate"));
   12.53 +            DSoundCreate = SDL_LoadFunction(DSoundDLL, "DirectSoundCreate");
   12.54          }
   12.55  
   12.56          if (!DSoundCreate) {
    13.1 --- a/src/audio/windx5/directx.h	Mon Jan 24 17:47:18 2011 -0800
    13.2 +++ b/src/audio/windx5/directx.h	Mon Jan 24 21:20:30 2011 -0800
    13.3 @@ -4,8 +4,7 @@
    13.4  
    13.5  /* Include all of the DirectX 5.0 headers and adds any necessary tweaks */
    13.6  
    13.7 -#define WIN32_LEAN_AND_MEAN
    13.8 -#include <windows.h>
    13.9 +#include "../../core/windows/SDL_windows.h"
   13.10  #include <mmsystem.h>
   13.11  #ifndef WIN32
   13.12  #define WIN32
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/src/core/android/SDL_android.cpp	Mon Jan 24 21:20:30 2011 -0800
    14.3 @@ -0,0 +1,258 @@
    14.4 +/*
    14.5 +    SDL - Simple DirectMedia Layer
    14.6 +    Copyright (C) 1997-2010 Sam Lantinga
    14.7 +
    14.8 +    This library is free software; you can redistribute it and/or
    14.9 +    modify it under the terms of the GNU Lesser General Public
   14.10 +    License as published by the Free Software Foundation; either
   14.11 +    version 2.1 of the License, or (at your option) any later version.
   14.12 +
   14.13 +    This library is distributed in the hope that it will be useful,
   14.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   14.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   14.16 +    Lesser General Public License for more details.
   14.17 +
   14.18 +    You should have received a copy of the GNU Lesser General Public
   14.19 +    License along with this library; if not, write to the Free Software
   14.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   14.21 +
   14.22 +    Sam Lantinga
   14.23 +    slouken@libsdl.org
   14.24 +*/
   14.25 +#include "SDL_config.h"
   14.26 +
   14.27 +#include "SDL_android.h"
   14.28 +
   14.29 +extern "C" {
   14.30 +#include "events/SDL_events_c.h"
   14.31 +#include "video/android/SDL_androidkeyboard.h"
   14.32 +#include "video/android/SDL_androidtouch.h"
   14.33 +#include "video/android/SDL_androidvideo.h"
   14.34 +
   14.35 +/* Impelemented in audio/android/SDL_androidaudio.c */
   14.36 +extern void Android_RunAudioThread();
   14.37 +} // C
   14.38 +
   14.39 +/*******************************************************************************
   14.40 + This file links the Java side of Android with libsdl
   14.41 +*******************************************************************************/
   14.42 +#include <jni.h>
   14.43 +#include <android/log.h>
   14.44 +
   14.45 +
   14.46 +/*******************************************************************************
   14.47 +                               Globals
   14.48 +*******************************************************************************/
   14.49 +static JNIEnv* mEnv = NULL;
   14.50 +static JNIEnv* mAudioEnv = NULL;
   14.51 +
   14.52 +// Main activity
   14.53 +static jclass mActivityClass;
   14.54 +
   14.55 +// method signatures
   14.56 +static jmethodID midCreateGLContext;
   14.57 +static jmethodID midFlipBuffers;
   14.58 +static jmethodID midAudioInit;
   14.59 +static jmethodID midAudioWriteShortBuffer;
   14.60 +static jmethodID midAudioWriteByteBuffer;
   14.61 +static jmethodID midAudioQuit;
   14.62 +
   14.63 +// Accelerometer data storage
   14.64 +static float fLastAccelerometer[3];
   14.65 +
   14.66 +
   14.67 +/*******************************************************************************
   14.68 +                 Functions called by JNI
   14.69 +*******************************************************************************/
   14.70 +
   14.71 +// Library init
   14.72 +extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
   14.73 +{
   14.74 +    return JNI_VERSION_1_4;
   14.75 +}
   14.76 +
   14.77 +// Called before SDL_main() to initialize JNI bindings
   14.78 +extern "C" void SDL_Android_Init(JNIEnv* env, jclass cls)
   14.79 +{
   14.80 +    __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL_Android_Init()");
   14.81 +
   14.82 +    mEnv = env;
   14.83 +    mActivityClass = cls;
   14.84 +
   14.85 +    midCreateGLContext = mEnv->GetStaticMethodID(mActivityClass,
   14.86 +                                "createGLContext","()V");
   14.87 +    midFlipBuffers = mEnv->GetStaticMethodID(mActivityClass,
   14.88 +                                "flipBuffers","()V");
   14.89 +    midAudioInit = mEnv->GetStaticMethodID(mActivityClass, 
   14.90 +                                "audioInit", "(IZZI)Ljava/lang/Object;");
   14.91 +    midAudioWriteShortBuffer = mEnv->GetStaticMethodID(mActivityClass,
   14.92 +                                "audioWriteShortBuffer", "([S)V");
   14.93 +    midAudioWriteByteBuffer = mEnv->GetStaticMethodID(mActivityClass,
   14.94 +                                "audioWriteByteBuffer", "([B)V");
   14.95 +    midAudioQuit = mEnv->GetStaticMethodID(mActivityClass,
   14.96 +                                "audioQuit", "()V");
   14.97 +
   14.98 +    if(!midCreateGLContext || !midFlipBuffers || !midAudioInit ||
   14.99 +       !midAudioWriteShortBuffer || !midAudioWriteByteBuffer || !midAudioQuit) {
  14.100 +        __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL: Couldn't locate Java callbacks, check that they're named and typed correctly");
  14.101 +    }
  14.102 +}
  14.103 +
  14.104 +// Resize
  14.105 +extern "C" void Java_org_libsdl_app_SDLActivity_onNativeResize(
  14.106 +                                    JNIEnv* env, jclass jcls,
  14.107 +                                    jint width, jint height, jint format)
  14.108 +{
  14.109 +    Android_SetScreenResolution(width, height, format);
  14.110 +}
  14.111 +
  14.112 +// Keydown
  14.113 +extern "C" void Java_org_libsdl_app_SDLActivity_onNativeKeyDown(
  14.114 +                                    JNIEnv* env, jclass jcls, jint keycode)
  14.115 +{
  14.116 +    Android_OnKeyDown(keycode);
  14.117 +}
  14.118 +
  14.119 +// Keyup
  14.120 +extern "C" void Java_org_libsdl_app_SDLActivity_onNativeKeyUp(
  14.121 +                                    JNIEnv* env, jclass jcls, jint keycode)
  14.122 +{
  14.123 +    Android_OnKeyUp(keycode);
  14.124 +}
  14.125 +
  14.126 +// Touch
  14.127 +extern "C" void Java_org_libsdl_app_SDLActivity_onNativeTouch(
  14.128 +                                    JNIEnv* env, jclass jcls,
  14.129 +                                    jint action, jfloat x, jfloat y, jfloat p)
  14.130 +{
  14.131 +    Android_OnTouch(action, x, y, p);
  14.132 +}
  14.133 +
  14.134 +// Accelerometer
  14.135 +extern "C" void Java_org_libsdl_app_SDLActivity_onNativeAccel(
  14.136 +                                    JNIEnv* env, jclass jcls,
  14.137 +                                    jfloat x, jfloat y, jfloat z)
  14.138 +{
  14.139 +    fLastAccelerometer[0] = x;
  14.140 +    fLastAccelerometer[1] = y;
  14.141 +    fLastAccelerometer[2] = z;   
  14.142 +}
  14.143 +
  14.144 +// Quit
  14.145 +extern "C" void Java_org_libsdl_app_SDLActivity_nativeQuit(
  14.146 +                                    JNIEnv* env, jclass cls)
  14.147 +{    
  14.148 +    // Inject a SDL_QUIT event
  14.149 +    SDL_SendQuit();
  14.150 +}
  14.151 +
  14.152 +extern "C" void Java_org_libsdl_app_SDLActivity_nativeRunAudioThread(
  14.153 +                                    JNIEnv* env, jclass cls)
  14.154 +{
  14.155 +    /* This is the audio thread, with a different environment */
  14.156 +    mAudioEnv = env;
  14.157 +
  14.158 +    Android_RunAudioThread();
  14.159 +}
  14.160 +
  14.161 +
  14.162 +/*******************************************************************************
  14.163 +             Functions called by SDL into Java
  14.164 +*******************************************************************************/
  14.165 +extern "C" void Android_JNI_CreateContext()
  14.166 +{
  14.167 +    mEnv->CallStaticVoidMethod(mActivityClass, midCreateGLContext); 
  14.168 +}
  14.169 +
  14.170 +extern "C" void Android_JNI_SwapWindow()
  14.171 +{
  14.172 +    mEnv->CallStaticVoidMethod(mActivityClass, midFlipBuffers); 
  14.173 +}
  14.174 +
  14.175 +extern "C" void Android_JNI_SetActivityTitle(const char *title)
  14.176 +{
  14.177 +    jmethodID mid;
  14.178 +
  14.179 +    mid = mEnv->GetStaticMethodID(mActivityClass,"setActivityTitle","(Ljava/lang/String;)V");
  14.180 +    if (mid) {
  14.181 +        mEnv->CallStaticVoidMethod(mActivityClass, mid, mEnv->NewStringUTF(title));
  14.182 +    }
  14.183 +}
  14.184 +
  14.185 +extern "C" void Android_JNI_GetAccelerometerValues(float values[3])
  14.186 +{
  14.187 +    int i;
  14.188 +    for (i = 0; i < 3; ++i) {
  14.189 +        values[i] = fLastAccelerometer[i];
  14.190 +    }
  14.191 +}
  14.192 +
  14.193 +//
  14.194 +// Audio support
  14.195 +//
  14.196 +static jboolean audioBuffer16Bit = JNI_FALSE;
  14.197 +static jboolean audioBufferStereo = JNI_FALSE;
  14.198 +static jobject audioBuffer = NULL;
  14.199 +static void* audioBufferPinned = NULL;
  14.200 +
  14.201 +extern "C" int Android_JNI_OpenAudioDevice(int sampleRate, int is16Bit, int channelCount, int desiredBufferFrames)
  14.202 +{
  14.203 +    int audioBufferFrames;
  14.204 +
  14.205 +    __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "SDL audio: opening device");
  14.206 +    audioBuffer16Bit = is16Bit;
  14.207 +    audioBufferStereo = channelCount > 1;
  14.208 +
  14.209 +    audioBuffer = mEnv->CallStaticObjectMethod(mActivityClass, midAudioInit, sampleRate, audioBuffer16Bit, audioBufferStereo, desiredBufferFrames);
  14.210 +
  14.211 +    if (audioBuffer == NULL) {
  14.212 +        __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL audio: didn't get back a good audio buffer!");
  14.213 +        return 0;
  14.214 +    }
  14.215 +    audioBuffer = mEnv->NewGlobalRef(audioBuffer);
  14.216 +
  14.217 +    jboolean isCopy = JNI_FALSE;
  14.218 +    if (audioBuffer16Bit) {
  14.219 +        audioBufferPinned = mEnv->GetShortArrayElements((jshortArray)audioBuffer, &isCopy);
  14.220 +        audioBufferFrames = mEnv->GetArrayLength((jshortArray)audioBuffer);
  14.221 +    } else {
  14.222 +        audioBufferPinned = mEnv->GetByteArrayElements((jbyteArray)audioBuffer, &isCopy);
  14.223 +        audioBufferFrames = mEnv->GetArrayLength((jbyteArray)audioBuffer);
  14.224 +    }
  14.225 +    if (audioBufferStereo) {
  14.226 +        audioBufferFrames /= 2;
  14.227 +    }
  14.228 +
  14.229 +    return audioBufferFrames;
  14.230 +}
  14.231 +
  14.232 +extern "C" void * Android_JNI_GetAudioBuffer()
  14.233 +{
  14.234 +    return audioBufferPinned;
  14.235 +}
  14.236 +
  14.237 +extern "C" void Android_JNI_WriteAudioBuffer()
  14.238 +{
  14.239 +    if (audioBuffer16Bit) {
  14.240 +        mAudioEnv->ReleaseShortArrayElements((jshortArray)audioBuffer, (jshort *)audioBufferPinned, JNI_COMMIT);
  14.241 +        mAudioEnv->CallStaticVoidMethod(mActivityClass, midAudioWriteShortBuffer, (jshortArray)audioBuffer);
  14.242 +    } else {
  14.243 +        mAudioEnv->ReleaseByteArrayElements((jbyteArray)audioBuffer, (jbyte *)audioBufferPinned, JNI_COMMIT);
  14.244 +        mAudioEnv->CallStaticVoidMethod(mActivityClass, midAudioWriteByteBuffer, (jbyteArray)audioBuffer);
  14.245 +    }
  14.246 +
  14.247 +    /* JNI_COMMIT means the changes are committed to the VM but the buffer remains pinned */
  14.248 +}
  14.249 +
  14.250 +extern "C" void Android_JNI_CloseAudioDevice()
  14.251 +{
  14.252 +    mEnv->CallStaticVoidMethod(mActivityClass, midAudioQuit); 
  14.253 +
  14.254 +    if (audioBuffer) {
  14.255 +        mEnv->DeleteGlobalRef(audioBuffer);
  14.256 +        audioBuffer = NULL;
  14.257 +        audioBufferPinned = NULL;
  14.258 +    }
  14.259 +}
  14.260 +
  14.261 +/* vi: set ts=4 sw=4 expandtab: */
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/src/core/android/SDL_android.h	Mon Jan 24 21:20:30 2011 -0800
    15.3 @@ -0,0 +1,50 @@
    15.4 +/*
    15.5 +    SDL - Simple DirectMedia Layer
    15.6 +    Copyright (C) 1997-2010 Sam Lantinga
    15.7 +
    15.8 +    This library is free software; you can redistribute it and/or
    15.9 +    modify it under the terms of the GNU Lesser General Public
   15.10 +    License as published by the Free Software Foundation; either
   15.11 +    version 2.1 of the License, or (at your option) any later version.
   15.12 +
   15.13 +    This library is distributed in the hope that it will be useful,
   15.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   15.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   15.16 +    Lesser General Public License for more details.
   15.17 +
   15.18 +    You should have received a copy of the GNU Lesser General Public
   15.19 +    License along with this library; if not, write to the Free Software
   15.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   15.21 +
   15.22 +    Sam Lantinga
   15.23 +    slouken@libsdl.org
   15.24 +*/
   15.25 +#include "SDL_config.h"
   15.26 +
   15.27 +/* Set up for C function definitions, even when using C++ */
   15.28 +#ifdef __cplusplus
   15.29 +/* *INDENT-OFF* */
   15.30 +extern "C" {
   15.31 +/* *INDENT-ON* */
   15.32 +#endif
   15.33 +
   15.34 +/* Interface from the SDL library into the Android Java activity */
   15.35 +extern void Android_JNI_CreateContext();
   15.36 +extern void Android_JNI_SwapWindow();
   15.37 +extern void Android_JNI_SetActivityTitle(const char *title);
   15.38 +extern void Android_JNI_GetAccelerometerValues(float values[3]);
   15.39 +
   15.40 +// Audio support
   15.41 +extern int Android_JNI_OpenAudioDevice(int sampleRate, int is16Bit, int channelCount, int desiredBufferFrames);
   15.42 +extern void* Android_JNI_GetAudioBuffer();
   15.43 +extern void Android_JNI_WriteAudioBuffer();
   15.44 +extern void Android_JNI_CloseAudioDevice();
   15.45 +
   15.46 +/* Ends C function definitions when using C++ */
   15.47 +#ifdef __cplusplus
   15.48 +/* *INDENT-OFF* */
   15.49 +}
   15.50 +/* *INDENT-ON* */
   15.51 +#endif
   15.52 +
   15.53 +/* vi: set ts=4 sw=4 expandtab: */
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/src/core/windows/SDL_windows.c	Mon Jan 24 21:20:30 2011 -0800
    16.3 @@ -0,0 +1,41 @@
    16.4 +/*
    16.5 +    SDL - Simple DirectMedia Layer
    16.6 +    Copyright (C) 1997-2010 Sam Lantinga
    16.7 +
    16.8 +    This library is free software; you can redistribute it and/or
    16.9 +    modify it under the terms of the GNU Lesser General Public
   16.10 +    License as published by the Free Software Foundation; either
   16.11 +    version 2.1 of the License, or (at your option) any later version.
   16.12 +
   16.13 +    This library is distributed in the hope that it will be useful,
   16.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   16.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   16.16 +    Lesser General Public License for more details.
   16.17 +
   16.18 +    You should have received a copy of the GNU Lesser General Public
   16.19 +    License along with this library; if not, write to the Free Software
   16.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   16.21 +
   16.22 +    Sam Lantinga
   16.23 +    slouken@libsdl.org
   16.24 +*/
   16.25 +#include "SDL_config.h"
   16.26 +
   16.27 +#include "SDL_error.h"
   16.28 +#include "SDL_windows.h"
   16.29 +
   16.30 +
   16.31 +/* Sets an error message based on GetLastError() */
   16.32 +void
   16.33 +WIN_SetError(const char *prefix)
   16.34 +{
   16.35 +    TCHAR buffer[1024];
   16.36 +    char *message;
   16.37 +    FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0,
   16.38 +                  buffer, SDL_arraysize(buffer), NULL);
   16.39 +    message = WIN_StringToUTF8(buffer);
   16.40 +    SDL_SetError("%s%s%s", prefix ? prefix : "", prefix ? ": " : "", message);
   16.41 +    SDL_free(message);
   16.42 +}
   16.43 +
   16.44 +/* vi: set ts=4 sw=4 expandtab: */
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/src/core/windows/SDL_windows.h	Mon Jan 24 21:20:30 2011 -0800
    17.3 @@ -0,0 +1,53 @@
    17.4 +/*
    17.5 +    SDL - Simple DirectMedia Layer
    17.6 +    Copyright (C) 1997-2010 Sam Lantinga
    17.7 +
    17.8 +    This library is free software; you can redistribute it and/or
    17.9 +    modify it under the terms of the GNU Lesser General Public
   17.10 +    License as published by the Free Software Foundation; either
   17.11 +    version 2.1 of the License, or (at your option) any later version.
   17.12 +
   17.13 +    This library is distributed in the hope that it will be useful,
   17.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   17.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   17.16 +    Lesser General Public License for more details.
   17.17 +
   17.18 +    You should have received a copy of the GNU Lesser General Public
   17.19 +    License along with this library; if not, write to the Free Software
   17.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   17.21 +
   17.22 +    Sam Lantinga
   17.23 +    slouken@libsdl.org
   17.24 +*/
   17.25 +
   17.26 +/* This is an include file for windows.h with the SDL build settings */
   17.27 +
   17.28 +#ifndef _INCLUDED_WINDOWS_H
   17.29 +#define _INCLUDED_WINDOWS_H
   17.30 +
   17.31 +#define WIN32_LEAN_AND_MEAN
   17.32 +#define STRICT
   17.33 +#ifndef UNICODE
   17.34 +#define UNICODE 1
   17.35 +#endif
   17.36 +#undef WINVER
   17.37 +#define WINVER  0x500           /* Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices() */
   17.38 +
   17.39 +#include <windows.h>
   17.40 +
   17.41 +
   17.42 +/* Routines to convert from UTF8 to native Windows text */
   17.43 +#if UNICODE
   17.44 +#define WIN_StringToUTF8(S) SDL_iconv_string("UTF-8", "UCS-2", (char *)(S), (SDL_wcslen(S)+1)*sizeof(WCHAR))
   17.45 +#define WIN_UTF8ToString(S) (WCHAR *)SDL_iconv_string("UCS-2", "UTF-8", (char *)(S), SDL_strlen(S)+1)
   17.46 +#else
   17.47 +#define WIN_StringToUTF8(S) SDL_iconv_string("UTF-8", "ASCII", (char *)(S), (SDL_strlen(S)+1))
   17.48 +#define WIN_UTF8ToString(S) SDL_iconv_string("ASCII", "UTF-8", (char *)(S), SDL_strlen(S)+1)
   17.49 +#endif
   17.50 +
   17.51 +/* Sets an error message based on GetLastError() */
   17.52 +extern void WIN_SetError(const char *prefix);
   17.53 +
   17.54 +#endif /* _INCLUDED_WINDOWS_H */
   17.55 +
   17.56 +/* vi: set ts=4 sw=4 expandtab: */
    18.1 --- a/src/cpuinfo/SDL_cpuinfo.c	Mon Jan 24 17:47:18 2011 -0800
    18.2 +++ b/src/cpuinfo/SDL_cpuinfo.c	Mon Jan 24 21:20:30 2011 -0800
    18.3 @@ -39,8 +39,7 @@
    18.4  #include <setjmp.h>
    18.5  #endif
    18.6  #ifdef __WIN32__
    18.7 -#define WIN32_LEAN_AND_MEAN
    18.8 -#include <windows.h>
    18.9 +#include "../core/windows/SDL_windows.h"
   18.10  #endif
   18.11  
   18.12  #define CPU_HAS_RDTSC   0x00000001
    19.1 --- a/src/file/SDL_rwops.c	Mon Jan 24 17:47:18 2011 -0800
    19.2 +++ b/src/file/SDL_rwops.c	Mon Jan 24 21:20:30 2011 -0800
    19.3 @@ -44,8 +44,7 @@
    19.4     faster, and all stdio functions anyway are embedded in coredll.dll - 
    19.5     the main wince dll*/
    19.6  
    19.7 -#define WINDOWS_LEAN_AND_MEAN
    19.8 -#include <windows.h>
    19.9 +#include "../core/windows/SDL_windows.h"
   19.10  
   19.11  #ifndef INVALID_SET_FILE_POINTER
   19.12  #define INVALID_SET_FILE_POINTER 0xFFFFFFFF
   19.13 @@ -98,34 +97,28 @@
   19.14      }
   19.15  #ifdef _WIN32_WCE
   19.16      {
   19.17 -        size_t size = SDL_strlen(filename) + 1;
   19.18 -        wchar_t *filenameW = SDL_stack_alloc(wchar_t, size);
   19.19 -
   19.20 -        if (MultiByteToWideChar(CP_UTF8, 0, filename, -1, filenameW, size) ==
   19.21 -            0) {
   19.22 -            SDL_stack_free(filenameW);
   19.23 -            SDL_free(context->hidden.windowsio.buffer.data);
   19.24 -            context->hidden.windowsio.buffer.data = NULL;
   19.25 -            SDL_SetError("Unable to convert filename to Unicode");
   19.26 -            return -1;
   19.27 -        }
   19.28 -        h = CreateFile(filenameW, (w_right | r_right),
   19.29 +        LPTSTR tstr = WIN_UTF8ToString(filename);
   19.30 +        h = CreateFile(tstr, (w_right | r_right),
   19.31                         (w_right) ? 0 : FILE_SHARE_READ, NULL,
   19.32                         (must_exist | truncate | a_mode),
   19.33                         FILE_ATTRIBUTE_NORMAL, NULL);
   19.34 -        SDL_stack_free(filenameW);
   19.35 +        SDL_free(tstr);
   19.36      }
   19.37  #else
   19.38      /* Do not open a dialog box if failure */
   19.39      old_error_mode =
   19.40          SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS);
   19.41  
   19.42 -    h = CreateFile(filename, (w_right | r_right),
   19.43 -                   (w_right) ? 0 : FILE_SHARE_READ, NULL,
   19.44 -                   (must_exist | truncate | a_mode), FILE_ATTRIBUTE_NORMAL,
   19.45 -                   NULL);
   19.46 +    {
   19.47 +        LPTSTR tstr = WIN_UTF8ToString(filename);
   19.48 +        h = CreateFile(tstr, (w_right | r_right),
   19.49 +                       (w_right) ? 0 : FILE_SHARE_READ, NULL,
   19.50 +                       (must_exist | truncate | a_mode),
   19.51 +                       FILE_ATTRIBUTE_NORMAL, NULL);
   19.52 +        SDL_free(tstr);
   19.53 +    }
   19.54  
   19.55 -    /* restore old behaviour */
   19.56 +    /* restore old behavior */
   19.57      SetErrorMode(old_error_mode);
   19.58  #endif /* _WIN32_WCE */
   19.59  
    20.1 --- a/src/haptic/windows/SDL_syshaptic.c	Mon Jan 24 17:47:18 2011 -0800
    20.2 +++ b/src/haptic/windows/SDL_syshaptic.c	Mon Jan 24 21:20:30 2011 -0800
    20.3 @@ -39,6 +39,7 @@
    20.4  static struct
    20.5  {
    20.6      DIDEVICEINSTANCE instance;
    20.7 +    char *name;
    20.8      SDL_Haptic *haptic;
    20.9      DIDEVCAPS capabilities;
   20.10  } SDL_hapticlist[MAX_HAPTICS];
   20.11 @@ -220,6 +221,9 @@
   20.12          return DIENUM_CONTINUE;
   20.13      }
   20.14  
   20.15 +    /* Copy the name */
   20.16 +    SDL_hapticlist[SDL_numhaptics].name = WIN_StringToUTF8(SDL_hapticlist[SDL_numhaptics].instance.tszProductName);
   20.17 +
   20.18      /* Close up device and count it. */
   20.19      IDirectInputDevice_Release(device);
   20.20      SDL_numhaptics++;
   20.21 @@ -238,7 +242,7 @@
   20.22  const char *
   20.23  SDL_SYS_HapticName(int index)
   20.24  {
   20.25 -    return SDL_hapticlist[index].instance.tszProductName;
   20.26 +    return SDL_hapticlist[index].name;
   20.27  }
   20.28  
   20.29  
   20.30 @@ -630,6 +634,15 @@
   20.31  void
   20.32  SDL_SYS_HapticQuit(void)
   20.33  {
   20.34 +    int i;
   20.35 +
   20.36 +    for (i = 0; i < SDL_arraysize(SDL_hapticlist); ++i) {
   20.37 +        if (SDL_hapticlist[i].name) {
   20.38 +            SDL_free(SDL_hapticlist[i].name);
   20.39 +            SDL_hapticlist[i].name = NULL;
   20.40 +        }
   20.41 +    }
   20.42 +
   20.43      IDirectInput_Release(dinput);
   20.44      dinput = NULL;
   20.45  }
    21.1 --- a/src/joystick/android/SDL_sysjoystick.c	Mon Jan 24 17:47:18 2011 -0800
    21.2 +++ b/src/joystick/android/SDL_sysjoystick.c	Mon Jan 24 21:20:30 2011 -0800
    21.3 @@ -32,7 +32,7 @@
    21.4  #include "SDL_joystick.h"
    21.5  #include "../SDL_sysjoystick.h"
    21.6  #include "../SDL_joystick_c.h"
    21.7 -#include "../../SDL_android.h"
    21.8 +#include "../../core/android/SDL_android.h"
    21.9  
   21.10  static const char *accelerometerName = "Android accelerometer";
   21.11  
    22.1 --- a/src/joystick/windows/SDL_dxjoystick.c	Mon Jan 24 17:47:18 2011 -0800
    22.2 +++ b/src/joystick/windows/SDL_dxjoystick.c	Mon Jan 24 21:20:30 2011 -0800
    22.3 @@ -63,6 +63,7 @@
    22.4                                         LPDIRECTINPUT * ppDI,
    22.5                                         LPUNKNOWN punkOuter);
    22.6  static DIDEVICEINSTANCE SYS_Joystick[MAX_JOYSTICKS];    /* array to hold joystick ID values */
    22.7 +static char *SYS_JoystickNames[MAX_JOYSTICKS];
    22.8  static int SYS_NumJoysticks;
    22.9  static HINSTANCE DInputDLL = NULL;
   22.10  
   22.11 @@ -326,6 +327,7 @@
   22.12  {
   22.13      SDL_memcpy(&SYS_Joystick[SYS_NumJoysticks], pdidInstance,
   22.14                 sizeof(DIDEVICEINSTANCE));
   22.15 +    SYS_JoystickNames[SYS_NumJoysticks] = WIN_StringToUTF8(pdidInstance->tszProductName);
   22.16      SYS_NumJoysticks++;
   22.17  
   22.18      if (SYS_NumJoysticks >= MAX_JOYSTICKS)
   22.19 @@ -338,8 +340,7 @@
   22.20  const char *
   22.21  SDL_SYS_JoystickName(int index)
   22.22  {
   22.23 -        /***-> test for invalid index ? */
   22.24 -    return (SYS_Joystick[index].tszProductName);
   22.25 +    return SYS_JoystickNames[index];
   22.26  }
   22.27  
   22.28  /* Function to open a joystick for use.
   22.29 @@ -793,6 +794,15 @@
   22.30  void
   22.31  SDL_SYS_JoystickQuit(void)
   22.32  {
   22.33 +    int i;
   22.34 +
   22.35 +    for (i = 0; i < SDL_arraysize(SYS_JoystickNames); ++i) {
   22.36 +        if (SYS_JoystickNames[i]) {
   22.37 +            SDL_free(SYS_JoystickNames[i]);
   22.38 +            SYS_JoystickNames[i] = NULL;
   22.39 +        }
   22.40 +    }
   22.41 +
   22.42      IDirectInput_Release(dinput);
   22.43      dinput = NULL;
   22.44  }
    23.1 --- a/src/joystick/windows/SDL_dxjoystick_c.h	Mon Jan 24 17:47:18 2011 -0800
    23.2 +++ b/src/joystick/windows/SDL_dxjoystick_c.h	Mon Jan 24 21:20:30 2011 -0800
    23.3 @@ -33,8 +33,7 @@
    23.4   * with polled devices, and it's fine to call IDirectInputDevice2_GetDeviceData and
    23.5   * let it return 0 events. */
    23.6  
    23.7 -#define WIN32_LEAN_AND_MEAN
    23.8 -#include <windows.h>
    23.9 +#include "../../core/windows/SDL_windows.h"
   23.10  
   23.11  #define DIRECTINPUT_VERSION 0x0700      /* Need version 7 for force feedback. */
   23.12  #include <dinput.h>
    24.1 --- a/src/joystick/windows/SDL_mmjoystick.c	Mon Jan 24 17:47:18 2011 -0800
    24.2 +++ b/src/joystick/windows/SDL_mmjoystick.c	Mon Jan 24 21:20:30 2011 -0800
    24.3 @@ -25,8 +25,7 @@
    24.4  
    24.5  /* Win32 MultiMedia Joystick driver, contributed by Andrei de A. Formiga */
    24.6  
    24.7 -#define WIN32_LEAN_AND_MEAN
    24.8 -#include <windows.h>
    24.9 +#include "../../core/windows/SDL_windows.h"
   24.10  #include <mmsystem.h>
   24.11  #include <regstr.h>
   24.12  
    25.1 --- a/src/loadso/windows/SDL_sysloadso.c	Mon Jan 24 17:47:18 2011 -0800
    25.2 +++ b/src/loadso/windows/SDL_sysloadso.c	Mon Jan 24 21:20:30 2011 -0800
    25.3 @@ -26,110 +26,45 @@
    25.4  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    25.5  /* System dependent library loading routines                           */
    25.6  
    25.7 -#define WIN32_LEAN_AND_MEAN
    25.8 -#include <windows.h>
    25.9 +#include "../../core/windows/SDL_windows.h"
   25.10  
   25.11  #include "SDL_loadso.h"
   25.12  
   25.13  void *
   25.14  SDL_LoadObject(const char *sofile)
   25.15  {
   25.16 -    void *handle = NULL;
   25.17 -    const char *loaderror = "Unknown error";
   25.18 -
   25.19 -#if defined(_WIN32_WCE)
   25.20 -    char errbuf[512];
   25.21 -
   25.22 -    wchar_t *errbuf_t = SDL_malloc(512 * sizeof(wchar_t));
   25.23 -    wchar_t *sofile_t = SDL_malloc((MAX_PATH + 1) * sizeof(wchar_t));
   25.24 -
   25.25 -    MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, sofile, -1, sofile_t,
   25.26 -                        MAX_PATH);
   25.27 -    handle = (void *) LoadLibrary(sofile_t);
   25.28 +    LPTSTR tstr = WIN_UTF8ToString(sofile);
   25.29 +    void *handle = (void *) LoadLibrary(tstr);
   25.30 +    SDL_free(tstr);
   25.31  
   25.32      /* Generate an error message if all loads failed */
   25.33      if (handle == NULL) {
   25.34 -        FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS |
   25.35 -                       FORMAT_MESSAGE_FROM_SYSTEM),
   25.36 -                      NULL, GetLastError(),
   25.37 -                      MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
   25.38 -                      errbuf_t, SDL_arraysize(errbuf), NULL);
   25.39 -        WideCharToMultiByte(CP_ACP, 0, errbuf_t, -1, errbuf, 511, NULL, NULL);
   25.40 -        loaderror = errbuf;
   25.41 +        char errbuf[512];
   25.42 +        SDL_strlcpy(errbuf, "Failed loading ", SDL_arraysize(errbuf));
   25.43 +        SDL_strlcat(errbuf, sofile, SDL_arraysize(errbuf));
   25.44 +        WIN_SetError(errbuf);
   25.45      }
   25.46 -
   25.47 -    SDL_free(sofile_t);
   25.48 -    SDL_free(errbuf_t);
   25.49 -
   25.50 -#else /*if defined(__WIN32__) */
   25.51 -    char errbuf[512];
   25.52 -
   25.53 -    handle = (void *) LoadLibrary(sofile);
   25.54 -
   25.55 -    /* Generate an error message if all loads failed */
   25.56 -    if (handle == NULL) {
   25.57 -        FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS |
   25.58 -                       FORMAT_MESSAGE_FROM_SYSTEM),
   25.59 -                      NULL, GetLastError(),
   25.60 -                      MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
   25.61 -                      errbuf, SDL_arraysize(errbuf), NULL);
   25.62 -        loaderror = errbuf;
   25.63 -    }
   25.64 -#endif
   25.65 -
   25.66 -    if (handle == NULL) {
   25.67 -        SDL_SetError("Failed loading %s: %s", sofile, loaderror);
   25.68 -    }
   25.69 -    return (handle);
   25.70 +    return handle;
   25.71  }
   25.72  
   25.73  void *
   25.74  SDL_LoadFunction(void *handle, const char *name)
   25.75  {
   25.76 -    void *symbol = NULL;
   25.77 -    const char *loaderror = "Unknown error";
   25.78 -
   25.79 -#if defined(_WIN32_WCE)
   25.80 -    char errbuf[512];
   25.81 -    int length = SDL_strlen(name);
   25.82 -
   25.83 -    wchar_t *name_t = SDL_malloc((length + 1) * sizeof(wchar_t));
   25.84 -    wchar_t *errbuf_t = SDL_malloc(512 * sizeof(wchar_t));
   25.85 -
   25.86 -    MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, name, -1, name_t, length + 1);
   25.87 -
   25.88 -    symbol = (void *) GetProcAddress((HMODULE) handle, name_t);
   25.89 -    if (symbol == NULL) {
   25.90 -        FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS |
   25.91 -                       FORMAT_MESSAGE_FROM_SYSTEM),
   25.92 -                      NULL, GetLastError(),
   25.93 -                      MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
   25.94 -                      errbuf_t, SDL_arraysize(errbuf), NULL);
   25.95 -        WideCharToMultiByte(CP_ACP, 0, errbuf_t, -1, errbuf, 511, NULL, NULL);
   25.96 -        loaderror = errbuf;
   25.97 -    }
   25.98 -
   25.99 -    SDL_free(name_t);
  25.100 -    SDL_free(errbuf_t);
  25.101 -
  25.102 -#else /*if defined(WIN32) */
  25.103 -    char errbuf[512];
  25.104 -
  25.105 -    symbol = (void *) GetProcAddress((HMODULE) handle, name);
  25.106 -    if (symbol == NULL) {
  25.107 -        FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS |
  25.108 -                       FORMAT_MESSAGE_FROM_SYSTEM),
  25.109 -                      NULL, GetLastError(),
  25.110 -                      MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  25.111 -                      errbuf, SDL_arraysize(errbuf), NULL);
  25.112 -        loaderror = errbuf;
  25.113 -    }
  25.114 +#ifdef _WIN32_WCE
  25.115 +    LPTSTR tstr = WIN_UTF8ToString(name);
  25.116 +    void *symbol = (void *) GetProcAddress((HMODULE) handle, tstr);
  25.117 +    SDL_free(tstr);
  25.118 +#else
  25.119 +    void *symbol = (void *) GetProcAddress((HMODULE) handle, name);
  25.120  #endif
  25.121  
  25.122      if (symbol == NULL) {
  25.123 -        SDL_SetError("Failed loading %s: %s", name, loaderror);
  25.124 +        char errbuf[512];
  25.125 +        SDL_strlcpy(errbuf, "Failed loading ", SDL_arraysize(errbuf));
  25.126 +        SDL_strlcat(errbuf, name, SDL_arraysize(errbuf));
  25.127 +        WIN_SetError(errbuf);
  25.128      }
  25.129 -    return (symbol);
  25.130 +    return symbol;
  25.131  }
  25.132  
  25.133  void
    26.1 --- a/src/power/windows/SDL_syspower.c	Mon Jan 24 17:47:18 2011 -0800
    26.2 +++ b/src/power/windows/SDL_syspower.c	Mon Jan 24 21:20:30 2011 -0800
    26.3 @@ -24,8 +24,7 @@
    26.4  #ifndef SDL_POWER_DISABLED
    26.5  #ifdef SDL_POWER_WINDOWS
    26.6  
    26.7 -#define WIN32_LEAN_AND_MEAN
    26.8 -#include <windows.h>
    26.9 +#include "../../core/windows/SDL_windows.h"
   26.10  
   26.11  #include "SDL_power.h"
   26.12  
    27.1 --- a/src/stdlib/SDL_getenv.c	Mon Jan 24 17:47:18 2011 -0800
    27.2 +++ b/src/stdlib/SDL_getenv.c	Mon Jan 24 21:20:30 2011 -0800
    27.3 @@ -27,8 +27,7 @@
    27.4  
    27.5  #if defined(__WIN32__) && !defined(_WIN32_WCE)
    27.6  
    27.7 -#define WIN32_LEAN_AND_MEAN
    27.8 -#include <windows.h>
    27.9 +#include "../core/windows/SDL_windows.h"
   27.10  
   27.11  /* Note this isn't thread-safe! */
   27.12  
   27.13 @@ -41,12 +40,12 @@
   27.14  {
   27.15      if (!overwrite) {
   27.16          char ch = 0;
   27.17 -        const size_t len = GetEnvironmentVariable(name, &ch, sizeof (ch));
   27.18 +        const size_t len = GetEnvironmentVariableA(name, &ch, sizeof (ch));
   27.19          if (len > 0) {
   27.20              return 0;  /* asked not to overwrite existing value. */
   27.21          }
   27.22      }
   27.23 -    if (!SetEnvironmentVariable(name, *value ? value : NULL)) {
   27.24 +    if (!SetEnvironmentVariableA(name, *value ? value : NULL)) {
   27.25          return -1;
   27.26      }
   27.27      return 0;
   27.28 @@ -59,7 +58,7 @@
   27.29      size_t bufferlen;
   27.30  
   27.31      bufferlen =
   27.32 -        GetEnvironmentVariable(name, SDL_envmem, (DWORD) SDL_envmemlen);
   27.33 +        GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen);
   27.34      if (bufferlen == 0) {
   27.35          return NULL;
   27.36      }
   27.37 @@ -70,7 +69,7 @@
   27.38          }
   27.39          SDL_envmem = newmem;
   27.40          SDL_envmemlen = bufferlen;
   27.41 -        GetEnvironmentVariable(name, SDL_envmem, (DWORD) SDL_envmemlen);
   27.42 +        GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen);
   27.43      }
   27.44      return SDL_envmem;
   27.45  }
    28.1 --- a/src/thread/windows/SDL_sysmutex.c	Mon Jan 24 17:47:18 2011 -0800
    28.2 +++ b/src/thread/windows/SDL_sysmutex.c	Mon Jan 24 21:20:30 2011 -0800
    28.3 @@ -23,8 +23,7 @@
    28.4  
    28.5  /* Mutex functions using the Win32 API */
    28.6  
    28.7 -#define WIN32_LEAN_AND_MEAN
    28.8 -#include <windows.h>
    28.9 +#include "../../core/windows/SDL_windows.h"
   28.10  
   28.11  #include "SDL_mutex.h"
   28.12  
    29.1 --- a/src/thread/windows/SDL_syssem.c	Mon Jan 24 17:47:18 2011 -0800
    29.2 +++ b/src/thread/windows/SDL_syssem.c	Mon Jan 24 21:20:30 2011 -0800
    29.3 @@ -23,8 +23,7 @@
    29.4  
    29.5  /* Semaphore functions using the Win32 API */
    29.6  
    29.7 -#define WIN32_LEAN_AND_MEAN
    29.8 -#include <windows.h>
    29.9 +#include "../../core/windows/SDL_windows.h"
   29.10  
   29.11  #include "SDL_thread.h"
   29.12  #if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
    30.1 --- a/src/thread/windows/SDL_systhread_c.h	Mon Jan 24 17:47:18 2011 -0800
    30.2 +++ b/src/thread/windows/SDL_systhread_c.h	Mon Jan 24 21:20:30 2011 -0800
    30.3 @@ -21,8 +21,7 @@
    30.4  */
    30.5  #include "SDL_config.h"
    30.6  
    30.7 -#define WIN32_LEAN_AND_MEAN
    30.8 -#include <windows.h>
    30.9 +#include "../../core/windows/SDL_windows.h"
   30.10  
   30.11  typedef HANDLE SYS_ThreadHandle;
   30.12  
    31.1 --- a/src/thread/windows/win_ce_semaphore.c	Mon Jan 24 17:47:18 2011 -0800
    31.2 +++ b/src/thread/windows/win_ce_semaphore.c	Mon Jan 24 21:20:30 2011 -0800
    31.3 @@ -28,8 +28,7 @@
    31.4        and it is not clear how to handle a mixture of WCE semaphores and normal
    31.5        events and mutexes. */
    31.6  
    31.7 -#define WIN32_LEAN_AND_MEAN
    31.8 -#include <windows.h>
    31.9 +#include "../../core/windows/SDL_windows.h"
   31.10  
   31.11  #include "win_ce_semaphore.h"
   31.12  
    32.1 --- a/src/timer/wince/SDL_systimer.c	Mon Jan 24 17:47:18 2011 -0800
    32.2 +++ b/src/timer/wince/SDL_systimer.c	Mon Jan 24 21:20:30 2011 -0800
    32.3 @@ -23,8 +23,7 @@
    32.4  
    32.5  #ifdef SDL_TIMER_WINCE
    32.6  
    32.7 -#define WIN32_LEAN_AND_MEAN
    32.8 -#include <windows.h>
    32.9 +#include "../../core/windows/SDL_windows.h"
   32.10  #include <mmsystem.h>
   32.11  
   32.12  #include "SDL_thread.h"
    33.1 --- a/src/timer/windows/SDL_systimer.c	Mon Jan 24 17:47:18 2011 -0800
    33.2 +++ b/src/timer/windows/SDL_systimer.c	Mon Jan 24 21:20:30 2011 -0800
    33.3 @@ -23,8 +23,7 @@
    33.4  
    33.5  #ifdef SDL_TIMER_WINDOWS
    33.6  
    33.7 -#define WIN32_LEAN_AND_MEAN
    33.8 -#include <windows.h>
    33.9 +#include "../../core/windows/SDL_windows.h"
   33.10  #include <mmsystem.h>
   33.11  
   33.12  #include "SDL_timer.h"
    34.1 --- a/src/video/android/SDL_androidgl.c	Mon Jan 24 17:47:18 2011 -0800
    34.2 +++ b/src/video/android/SDL_androidgl.c	Mon Jan 24 21:20:30 2011 -0800
    34.3 @@ -26,7 +26,7 @@
    34.4  #include "SDL_video.h"
    34.5  
    34.6  #include "SDL_androidvideo.h"
    34.7 -#include "../../SDL_android.h"
    34.8 +#include "../../core/android/SDL_android.h"
    34.9  
   34.10  #include <android/log.h>
   34.11  
    35.1 --- a/src/video/windows/SDL_gapirender.c	Mon Jan 24 17:47:18 2011 -0800
    35.2 +++ b/src/video/windows/SDL_gapirender.c	Mon Jan 24 21:20:30 2011 -0800
    35.3 @@ -78,7 +78,7 @@
    35.4  typedef struct
    35.5  {
    35.6      // gx.dll
    35.7 -    HMODULE                   hGapiLib;
    35.8 +    void*                     hGapiLib;
    35.9      PFNGXOpenDisplay          GXOpenDisplay;
   35.10      PFNGXCloseDisplay         GXCloseDisplay;
   35.11      PFNGXBeginDraw            GXBeginDraw;
   35.12 @@ -251,7 +251,7 @@
   35.13  
   35.14  int WINCE_Available(void)
   35.15  {
   35.16 -    HMODULE render_gapi;
   35.17 +    void* render_gapi;
   35.18      const char* preferably = SDL_getenv("SDL_VIDEO_RENDERER");
   35.19  
   35.20      // raw check
   35.21 @@ -267,10 +267,10 @@
   35.22      if(preferably && 0 == SDL_strcasecmp(preferably, RAW_RENDER_NAME)) return 0 != render_raw;
   35.23  
   35.24      // gapi check
   35.25 -    render_gapi = LoadLibrary(TEXT("\\Windows\\gx.dll"));
   35.26 +    render_gapi = SDL_LoadObject("\\Windows\\gx.dll");
   35.27      if(0 == render_gapi)
   35.28 -        render_gapi = LoadLibrary(TEXT("gx.dll"));
   35.29 -    FreeLibrary(render_gapi);
   35.30 +        render_gapi = SDL_LoadObject("gx.dll");
   35.31 +    SDL_UnloadObject(render_gapi);
   35.32  
   35.33      if(preferably && 0 == SDL_strcasecmp(preferably, GAPI_RENDER_NAME)) return 0 != render_gapi;
   35.34  
   35.35 @@ -280,7 +280,7 @@
   35.36  void WINCE_AddRenderDriver(_THIS)
   35.37  {
   35.38      HDC hdc;
   35.39 -    HMODULE render_gapi;
   35.40 +    void* render_gapi;
   35.41      int render_raw, ii;
   35.42      const char* preferably = SDL_getenv("SDL_VIDEO_RENDERER");
   35.43  
   35.44 @@ -295,12 +295,12 @@
   35.45              render_raw = 1;
   35.46  
   35.47      // gapi check
   35.48 -    render_gapi = LoadLibrary(TEXT("\\Windows\\gx.dll"));
   35.49 +    render_gapi = SDL_LoadObject("\\Windows\\gx.dll");
   35.50      if(0 == render_gapi)
   35.51 -        render_gapi = LoadLibrary(TEXT("gx.dll"));
   35.52 +        render_gapi = SDL_LoadObject("gx.dll");
   35.53  
   35.54      if(render_gapi)
   35.55 -        FreeLibrary(render_gapi);
   35.56 +        SDL_UnloadObject(render_gapi);
   35.57  
   35.58      for(ii = 0; ii < _this->num_displays; ++ii)
   35.59      {
   35.60 @@ -885,15 +885,15 @@
   35.61              return 0;
   35.62          }
   35.63  
   35.64 -        data->gapi->hGapiLib = LoadLibrary(TEXT("\\Windows\\gx.dll"));
   35.65 +        data->gapi->hGapiLib = SDL_LoadObject("\\Windows\\gx.dll");
   35.66          if(0 == data->gapi->hGapiLib)
   35.67          {
   35.68 -            data->gapi->hGapiLib = LoadLibrary(TEXT("gx.dll"));
   35.69 +            data->gapi->hGapiLib = SDL_LoadObject("gx.dll");
   35.70              if(0 == data->gapi->hGapiLib) return 0;
   35.71          }
   35.72  
   35.73          // load gapi library
   35.74 -#define LINK(type,name,import) name=(PFN##type)GetProcAddress(data->gapi->hGapiLib,TEXT(import))
   35.75 +#define LINK(type,name,import) name=(PFN##type)SDL_LoadFunction(data->gapi->hGapiLib,import)
   35.76          LINK(GXOpenDisplay,         data->gapi->GXOpenDisplay,         "?GXOpenDisplay@@YAHPAUHWND__@@K@Z");
   35.77          LINK(GXCloseDisplay,        data->gapi->GXCloseDisplay,        "?GXCloseDisplay@@YAHXZ");
   35.78          LINK(GXBeginDraw,           data->gapi->GXBeginDraw,           "?GXBeginDraw@@YAPAXXZ");
   35.79 @@ -1005,7 +1005,7 @@
   35.80      if(data->gapi)
   35.81      {
   35.82          if(data->gapi->GXCloseDisplay) data->gapi->GXCloseDisplay(); 
   35.83 -        if(data->gapi->hGapiLib)  FreeLibrary(data->gapi->hGapiLib);
   35.84 +        if(data->gapi->hGapiLib)  SDL_UnloadObject(data->gapi->hGapiLib);
   35.85  
   35.86          SDL_free(data->gapi);
   35.87          data->gapi = NULL;
    36.1 --- a/src/video/windows/SDL_windowskeyboard.c	Mon Jan 24 17:47:18 2011 -0800
    36.2 +++ b/src/video/windows/SDL_windowskeyboard.c	Mon Jan 24 21:20:30 2011 -0800
    36.3 @@ -312,15 +312,15 @@
    36.4          CoCreateInstance(&CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, &IID_ITfThreadMgr, (LPVOID *)&videodata->ime_threadmgr);
    36.5      }
    36.6      videodata->ime_initialized = SDL_TRUE;
    36.7 -    videodata->ime_himm32 = LoadLibraryA("imm32.dll");
    36.8 +    videodata->ime_himm32 = SDL_LoadObject("imm32.dll");
    36.9      if (!videodata->ime_himm32) {
   36.10          videodata->ime_available = SDL_FALSE;
   36.11          return;
   36.12      }
   36.13 -    videodata->ImmLockIMC = (LPINPUTCONTEXT2 (WINAPI *)(HIMC))GetProcAddress(videodata->ime_himm32, "ImmLockIMC");
   36.14 -    videodata->ImmUnlockIMC = (BOOL (WINAPI *)(HIMC))GetProcAddress(videodata->ime_himm32, "ImmUnlockIMC");
   36.15 -    videodata->ImmLockIMCC = (LPVOID (WINAPI *)(HIMCC))GetProcAddress(videodata->ime_himm32, "ImmLockIMCC");
   36.16 -    videodata->ImmUnlockIMCC = (BOOL (WINAPI *)(HIMCC))GetProcAddress(videodata->ime_himm32, "ImmUnlockIMCC");
   36.17 +    videodata->ImmLockIMC = (LPINPUTCONTEXT2 (WINAPI *)(HIMC))SDL_LoadFunction(videodata->ime_himm32, "ImmLockIMC");
   36.18 +    videodata->ImmUnlockIMC = (BOOL (WINAPI *)(HIMC))SDL_LoadFunction(videodata->ime_himm32, "ImmUnlockIMC");
   36.19 +    videodata->ImmLockIMCC = (LPVOID (WINAPI *)(HIMCC))SDL_LoadFunction(videodata->ime_himm32, "ImmLockIMCC");
   36.20 +    videodata->ImmUnlockIMCC = (BOOL (WINAPI *)(HIMCC))SDL_LoadFunction(videodata->ime_himm32, "ImmUnlockIMCC");
   36.21  
   36.22      IME_SetWindow(videodata, hwnd);
   36.23      videodata->ime_himc = ImmGetContext(hwnd);
   36.24 @@ -383,7 +383,7 @@
   36.25      videodata->ime_hwnd_main = 0;
   36.26      videodata->ime_himc = 0;
   36.27      if (videodata->ime_himm32) {
   36.28 -        FreeLibrary(videodata->ime_himm32);
   36.29 +        SDL_UnloadObject(videodata->ime_himm32);
   36.30          videodata->ime_himm32 = 0;
   36.31      }
   36.32      if (videodata->ime_threadmgr) {
   36.33 @@ -606,7 +606,7 @@
   36.34  IME_SetupAPI(SDL_VideoData *videodata)
   36.35  {
   36.36      char ime_file[MAX_PATH + 1];
   36.37 -    HMODULE hime = 0;
   36.38 +    void* hime = 0;
   36.39      HKL hkl = 0;
   36.40      videodata->GetReadingString = 0;
   36.41      videodata->ShowReadingWindow = 0;
   36.42 @@ -617,14 +617,14 @@
   36.43      if (ImmGetIMEFileNameA(hkl, ime_file, sizeof(ime_file) - 1) <= 0)
   36.44          return;
   36.45  
   36.46 -    hime = LoadLibraryA(ime_file);
   36.47 +    hime = SDL_LoadObject(ime_file);
   36.48      if (!hime)
   36.49          return;
   36.50  
   36.51      videodata->GetReadingString = (UINT (WINAPI *)(HIMC, UINT, LPWSTR, PINT, BOOL*, PUINT))
   36.52 -        GetProcAddress(hime, "GetReadingString");
   36.53 +        SDL_LoadFunction(hime, "GetReadingString");
   36.54      videodata->ShowReadingWindow = (BOOL (WINAPI *)(HIMC, BOOL))
   36.55 -        GetProcAddress(hime, "ShowReadingWindow");
   36.56 +        SDL_LoadFunction(hime, "ShowReadingWindow");
   36.57  
   36.58      if (videodata->ShowReadingWindow) {
   36.59          HIMC himc = ImmGetContext(videodata->ime_hwnd_current);
    37.1 --- a/src/video/windows/SDL_windowsopengl.c	Mon Jan 24 17:47:18 2011 -0800
    37.2 +++ b/src/video/windows/SDL_windowsopengl.c	Mon Jan 24 21:20:30 2011 -0800
    37.3 @@ -101,7 +101,7 @@
    37.4          !_this->gl_data->wglDeleteContext ||
    37.5          !_this->gl_data->wglMakeCurrent) {
    37.6          SDL_SetError("Could not retrieve OpenGL functions");
    37.7 -        FreeLibrary(handle);
    37.8 +        SDL_UnloadObject(handle);
    37.9          return -1;
   37.10      }
   37.11  
    38.1 --- a/src/video/windows/SDL_windowsvideo.c	Mon Jan 24 17:47:18 2011 -0800
    38.2 +++ b/src/video/windows/SDL_windowsvideo.c	Mon Jan 24 21:20:30 2011 -0800
    38.3 @@ -37,19 +37,6 @@
    38.4  static int WIN_VideoInit(_THIS);
    38.5  static void WIN_VideoQuit(_THIS);
    38.6  
    38.7 -/* Sets an error message based on GetLastError() */
    38.8 -void
    38.9 -WIN_SetError(const char *prefix)
   38.10 -{
   38.11 -    TCHAR buffer[1024];
   38.12 -    char *message;
   38.13 -    FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0,
   38.14 -                  buffer, SDL_arraysize(buffer), NULL);
   38.15 -    message = WIN_StringToUTF8(buffer);
   38.16 -    SDL_SetError("%s%s%s", prefix ? prefix : "", prefix ? ": " : "", message);
   38.17 -    SDL_free(message);
   38.18 -}
   38.19 -
   38.20  
   38.21  /* Windows driver bootstrap functions */
   38.22  
   38.23 @@ -68,22 +55,22 @@
   38.24  #if SDL_VIDEO_RENDER_D3D
   38.25      if (data->d3d) {
   38.26          IDirect3D9_Release(data->d3d);
   38.27 -        FreeLibrary(data->d3dDLL);
   38.28 +        SDL_UnloadObject(data->d3dDLL);
   38.29      }
   38.30  #endif
   38.31  #if SDL_VIDEO_RENDER_DDRAW
   38.32      if (data->ddraw) {
   38.33          data->ddraw->lpVtbl->Release(data->ddraw);
   38.34 -        FreeLibrary(data->ddrawDLL);
   38.35 +        SDL_UnloadObject(data->ddrawDLL);
   38.36      }
   38.37  #endif
   38.38  #ifdef _WIN32_WCE
   38.39      if(data->hAygShell) {
   38.40 -       FreeLibrary(data->hAygShell);
   38.41 +       SDL_UnloadObject(data->hAygShell);
   38.42      }
   38.43  #endif
   38.44  	if (data->userDLL) {
   38.45 -		FreeLibrary(data->userDLL);
   38.46 +		SDL_UnloadObject(data->userDLL);
   38.47  	}
   38.48  
   38.49      SDL_free(device->driverdata);
   38.50 @@ -115,24 +102,24 @@
   38.51      device->driverdata = data;
   38.52  
   38.53  #if SDL_VIDEO_RENDER_D3D
   38.54 -    data->d3dDLL = LoadLibrary(TEXT("D3D9.DLL"));
   38.55 +    data->d3dDLL = SDL_LoadObject("D3D9.DLL");
   38.56      if (data->d3dDLL) {
   38.57          IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion);
   38.58  
   38.59          D3DCreate =
   38.60 -            (IDirect3D9 * (WINAPI *) (UINT)) GetProcAddress(data->d3dDLL,
   38.61 +            (IDirect3D9 * (WINAPI *) (UINT)) SDL_LoadFunction(data->d3dDLL,
   38.62                                                              "Direct3DCreate9");
   38.63          if (D3DCreate) {
   38.64              data->d3d = D3DCreate(D3D_SDK_VERSION);
   38.65          }
   38.66          if (!data->d3d) {
   38.67 -            FreeLibrary(data->d3dDLL);
   38.68 +            SDL_UnloadObject(data->d3dDLL);
   38.69              data->d3dDLL = NULL;
   38.70          }
   38.71      }
   38.72  #endif /* SDL_VIDEO_RENDER_D3D */
   38.73  #if SDL_VIDEO_RENDER_DDRAW
   38.74 -    data->ddrawDLL = LoadLibrary(TEXT("ddraw.dll"));
   38.75 +    data->ddrawDLL = SDL_LoadObject("ddraw.dll");
   38.76      if (data->ddrawDLL) {
   38.77          IDirectDraw *(WINAPI * DDCreate) (GUID FAR * lpGUID,
   38.78                                            LPDIRECTDRAW FAR * lplpDD,
   38.79 @@ -141,9 +128,9 @@
   38.80          DDCreate =
   38.81              (IDirectDraw *
   38.82               (WINAPI *) (GUID FAR *, LPDIRECTDRAW FAR *, IUnknown FAR *))
   38.83 -            GetProcAddress(data->ddrawDLL, TEXT("DirectDrawCreate"));
   38.84 +            SDL_LoadFunction(data->ddrawDLL, "DirectDrawCreate");
   38.85          if (!DDCreate || DDCreate(NULL, &data->ddraw, NULL) != DD_OK) {
   38.86 -            FreeLibrary(data->ddrawDLL);
   38.87 +            SDL_UnloadObject(data->ddrawDLL);
   38.88              data->ddrawDLL = NULL;
   38.89              data->ddraw = NULL;
   38.90          }
   38.91 @@ -151,19 +138,19 @@
   38.92  #endif /* SDL_VIDEO_RENDER_DDRAW */
   38.93  
   38.94  #ifdef _WIN32_WCE
   38.95 -    data->hAygShell = LoadLibrary(TEXT("\\windows\\aygshell.dll"));
   38.96 +    data->hAygShell = SDL_LoadObject("\\windows\\aygshell.dll");
   38.97      if(0 == data->hAygShell)
   38.98 -        data->hAygShell = LoadLibrary(TEXT("aygshell.dll"));
   38.99 +        data->hAygShell = SDL_LoadObject("aygshell.dll");
  38.100      data->SHFullScreen = (0 != data->hAygShell ?
  38.101 -        (PFNSHFullScreen) GetProcAddress(data->hAygShell, TEXT("SHFullScreen")) : 0);
  38.102 +        (PFNSHFullScreen) SDL_LoadFunction(data->hAygShell, "SHFullScreen") : 0);
  38.103      data->CoordTransform = NULL;
  38.104  #endif
  38.105  
  38.106 -	data->userDLL = LoadLibrary(TEXT("USER32.DLL"));
  38.107 +	data->userDLL = SDL_LoadObject("USER32.DLL");
  38.108  	if (data->userDLL) {
  38.109 -		data->CloseTouchInputHandle = (BOOL (WINAPI *)( HTOUCHINPUT )) GetProcAddress(data->userDLL, TEXT("CloseTouchInputHandle"));
  38.110 -		data->GetTouchInputInfo = (BOOL (WINAPI *)( HTOUCHINPUT, UINT, PTOUCHINPUT, int )) GetProcAddress(data->userDLL, TEXT("GetTouchInputInfo"));
  38.111 -		data->RegisterTouchWindow = (BOOL (WINAPI *)( HWND, ULONG )) GetProcAddress(data->userDLL, TEXT("RegisterTouchWindow"));
  38.112 +		data->CloseTouchInputHandle = (BOOL (WINAPI *)( HTOUCHINPUT )) SDL_LoadFunction(data->userDLL, "CloseTouchInputHandle");
  38.113 +		data->GetTouchInputInfo = (BOOL (WINAPI *)( HTOUCHINPUT, UINT, PTOUCHINPUT, int )) SDL_LoadFunction(data->userDLL, "GetTouchInputInfo");
  38.114 +		data->RegisterTouchWindow = (BOOL (WINAPI *)( HWND, ULONG )) SDL_LoadFunction(data->userDLL, "RegisterTouchWindow");
  38.115  	}
  38.116  
  38.117      /* Set the function pointers */
    39.1 --- a/src/video/windows/SDL_windowsvideo.h	Mon Jan 24 17:47:18 2011 -0800
    39.2 +++ b/src/video/windows/SDL_windowsvideo.h	Mon Jan 24 21:20:30 2011 -0800
    39.3 @@ -26,15 +26,7 @@
    39.4  
    39.5  #include "../SDL_sysvideo.h"
    39.6  
    39.7 -#define WIN32_LEAN_AND_MEAN
    39.8 -#define STRICT
    39.9 -#ifndef UNICODE
   39.10 -#define UNICODE
   39.11 -#endif
   39.12 -#undef WINVER
   39.13 -#define WINVER  0x500           /* Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices() */
   39.14 -
   39.15 -#include <windows.h>
   39.16 +#include "../../core/windows/SDL_windows.h"
   39.17  
   39.18  #if defined(_MSC_VER) && !defined(_WIN32_WCE)
   39.19  #include <msctf.h>
   39.20 @@ -68,15 +60,8 @@
   39.21  #include "SDL_windowsopengl.h"
   39.22  #include "SDL_windowswindow.h"
   39.23  #include "SDL_events.h"
   39.24 +#include "SDL_loadso.h"
   39.25  
   39.26 -#ifdef UNICODE
   39.27 -#define WIN_StringToUTF8(S) SDL_iconv_string("UTF-8", "UCS-2", (char *)S, (SDL_wcslen(S)+1)*sizeof(WCHAR))
   39.28 -#define WIN_UTF8ToString(S) (WCHAR *)SDL_iconv_string("UCS-2", "UTF-8", (char *)S, SDL_strlen(S)+1)
   39.29 -#else
   39.30 -#define WIN_StringToUTF8(S) SDL_iconv_string("UTF-8", "ASCII", (char *)S, (SDL_strlen(S)+1))
   39.31 -#define WIN_UTF8ToString(S) SDL_iconv_string("ASCII", "UTF-8", (char *)S, SDL_strlen(S)+1)
   39.32 -#endif
   39.33 -extern void WIN_SetError(const char *prefix);
   39.34  
   39.35  enum { RENDER_NONE, RENDER_D3D, RENDER_DDRAW, RENDER_GDI, RENDER_GAPI, RENDER_RAW };
   39.36  
   39.37 @@ -147,15 +132,15 @@
   39.38      int render;
   39.39  
   39.40  #if SDL_VIDEO_RENDER_D3D
   39.41 -    HANDLE d3dDLL;
   39.42 +    void* d3dDLL;
   39.43      IDirect3D9 *d3d;
   39.44  #endif
   39.45  #if SDL_VIDEO_RENDER_DDRAW
   39.46 -    HANDLE ddrawDLL;
   39.47 +    void* ddrawDLL;
   39.48      IDirectDraw *ddraw;
   39.49  #endif
   39.50  #ifdef _WIN32_WCE
   39.51 -    HMODULE hAygShell;
   39.52 +    void* hAygShell;
   39.53      PFNSHFullScreen SHFullScreen;
   39.54      PFCoordTransform CoordTransform;
   39.55  #endif
   39.56 @@ -164,7 +149,7 @@
   39.57  	DWORD clipboard_count;
   39.58  
   39.59  	/* Touch input functions */
   39.60 -	HANDLE userDLL;
   39.61 +	void* userDLL;
   39.62  	BOOL (WINAPI *CloseTouchInputHandle)( HTOUCHINPUT );
   39.63  	BOOL (WINAPI *GetTouchInputInfo)( HTOUCHINPUT, UINT, PTOUCHINPUT, int );
   39.64  	BOOL (WINAPI *RegisterTouchWindow)( HWND, ULONG );
   39.65 @@ -199,7 +184,7 @@
   39.66      int ime_winheight;
   39.67  
   39.68      HKL ime_hkl;
   39.69 -    HMODULE ime_himm32;
   39.70 +    void* ime_himm32;
   39.71      UINT (WINAPI *GetReadingString)(HIMC himc, UINT uReadingBufLen, LPWSTR lpwReadingBuf, PINT pnErrorIndex, BOOL *pfIsVertical, PUINT puMaxReadingLen);
   39.72      BOOL (WINAPI *ShowReadingWindow)(HIMC himc, BOOL bShow);
   39.73      LPINPUTCONTEXT2 (WINAPI *ImmLockIMC)(HIMC himc);