Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Include windows.h in a single point in the source, so we can be consi…
Browse files Browse the repository at this point in the history
…stent 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
  • Loading branch information
slouken committed Jan 25, 2011
1 parent cc33ffa commit 6b41c2c
Show file tree
Hide file tree
Showing 37 changed files with 273 additions and 272 deletions.
23 changes: 12 additions & 11 deletions Android.mk
Expand Up @@ -12,30 +12,31 @@ LOCAL_MODULE := SDL

LOCAL_C_INCLUDES := $(LOCAL_PATH)/include

LOCAL_SRC_FILES := src/SDL_android.cpp \
LOCAL_SRC_FILES := \
$(subst $(LOCAL_PATH)/,, \
$(wildcard $(LOCAL_PATH)/src/*.c) \
$(wildcard $(LOCAL_PATH)/src/audio/*.c) \
$(wildcard $(LOCAL_PATH)/src/audio/android/*.c) \
$(wildcard $(LOCAL_PATH)/src/audio/dummy/*.c) \
$(LOCAL_PATH)/src/atomic/SDL_atomic.c \
$(LOCAL_PATH)/src/atomic/SDL_spinlock.c.arm \
$(wildcard $(LOCAL_PATH)/src/core/android/*.cpp) \
$(wildcard $(LOCAL_PATH)/src/cpuinfo/*.c) \
$(wildcard $(LOCAL_PATH)/src/events/*.c) \
$(wildcard $(LOCAL_PATH)/src/file/*.c) \
$(wildcard $(LOCAL_PATH)/src/joystick/*.c) \
$(wildcard $(LOCAL_PATH)/src/haptic/*.c) \
$(wildcard $(LOCAL_PATH)/src/haptic/dummy/*.c) \
$(wildcard $(LOCAL_PATH)/src/joystick/*.c) \
$(wildcard $(LOCAL_PATH)/src/joystick/android/*.c) \
$(wildcard $(LOCAL_PATH)/src/loadso/dlopen/*.c)) \
$(wildcard $(LOCAL_PATH)/src/power/*.c) \
$(wildcard $(LOCAL_PATH)/src/stdlib/*.c) \
$(wildcard $(LOCAL_PATH)/src/thread/*.c) \
$(wildcard $(LOCAL_PATH)/src/timer/*.c) \
$(wildcard $(LOCAL_PATH)/src/video/*.c) \
$(wildcard $(LOCAL_PATH)/src/power/*.c) \
$(wildcard $(LOCAL_PATH)/src/audio/android/*.c) \
$(wildcard $(LOCAL_PATH)/src/audio/dummy/*.c) \
$(wildcard $(LOCAL_PATH)/src/video/android/*.c) \
$(wildcard $(LOCAL_PATH)/src/joystick/android/*.c) \
$(wildcard $(LOCAL_PATH)/src/haptic/dummy/*.c) \
$(wildcard $(LOCAL_PATH)/src/thread/pthread/*.c) \
$(wildcard $(LOCAL_PATH)/src/timer/*.c) \
$(wildcard $(LOCAL_PATH)/src/timer/unix/*.c) \
$(wildcard $(LOCAL_PATH)/src/loadso/dlopen/*.c))
$(wildcard $(LOCAL_PATH)/src/video/*.c) \
$(wildcard $(LOCAL_PATH)/src/video/android/*.c)

LOCAL_LDLIBS := -ldl -lGLESv1_CM -llog

Expand Down
24 changes: 16 additions & 8 deletions VisualC/SDL/SDL_VS2008.vcproj
Expand Up @@ -1150,6 +1150,22 @@
RelativePath="..\..\src\audio\SDL_wave.h"
>
</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
RelativePath="..\..\src\video\windows\SDL_windowsclipboard.c"
>
Expand Down Expand Up @@ -1230,14 +1246,6 @@
RelativePath="..\..\src\video\windows\SDL_windowswindow.h"
>
</File>
<File
RelativePath="..\..\src\events\SDL_windowevents.c"
>
</File>
<File
RelativePath="..\..\src\events\SDL_windowevents_c.h"
>
</File>
<File
RelativePath="..\..\src\video\SDL_yuv_mmx.c"
>
Expand Down
4 changes: 3 additions & 1 deletion VisualC/SDL/SDL_VS2010.vcxproj
Expand Up @@ -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_version.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\default_cursor.h" />
<ClInclude Include="..\..\src\audio\windx5\directx.h" />
Expand Down Expand Up @@ -345,6 +346,7 @@ echo #define SDL_REVISION 0 &gt;"$(ProjectDir)\..\..\include\SDL_revision.h"
<ClInclude Include="..\..\src\video\windows\wmmsg.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\core\windows\SDL_windows.c" />
<ClCompile Include="..\..\src\events\SDL_clipboardevents.c" />
<ClCompile Include="..\..\src\events\SDL_gesture.c" />
<ClCompile Include="..\..\src\events\SDL_touch.c" />
Expand Down Expand Up @@ -460,4 +462,4 @@ echo #define SDL_REVISION 0 &gt;"$(ProjectDir)\..\..\include\SDL_revision.h"
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
8 changes: 8 additions & 0 deletions VisualCE/SDL/SDL.vcproj
Expand Up @@ -1053,6 +1053,10 @@
RelativePath="..\..\src\events\SDL_windowevents.c"
>
</File>
<File
RelativePath="..\..\src\core\windows\SDL_windows.c"
>
</File>
<File
RelativePath="..\..\src\video\windows\SDL_windowsclipboard.c"
>
Expand Down Expand Up @@ -1358,6 +1362,10 @@
RelativePath="..\..\src\events\SDL_windowevents_c.h"
>
</File>
<File
RelativePath="..\..\src\core\windows\SDL_windows.h"
>
</File>
<File
RelativePath="..\..\src\video\windows\SDL_windowsclipboard.h"
>
Expand Down
3 changes: 1 addition & 2 deletions src/SDL.c
Expand Up @@ -329,8 +329,7 @@ SDL_GetPlatform()

#if !defined(HAVE_LIBC) || (defined(__WATCOMC__) && defined(BUILD_DLL))
/* Need to include DllMain() on Watcom C for some reason.. */
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "core/windows/SDL_windows.h"

BOOL APIENTRY
_DllMainCRTStartup(HANDLE hModule,
Expand Down
9 changes: 1 addition & 8 deletions src/SDL_assert.c
Expand Up @@ -27,18 +27,11 @@
#include "video/SDL_sysvideo.h"

#ifdef __WIN32__
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "core/windows/SDL_windows.h"

#ifndef WS_OVERLAPPEDWINDOW
#define WS_OVERLAPPEDWINDOW 0
#endif

#ifdef UNICODE
#define WIN_UTF8ToString(S) (WCHAR *)SDL_iconv_string("UCS-2", "UTF-8", (char *)S, SDL_strlen(S)+1)
#else
#define WIN_UTF8ToString(S) SDL_iconv_string("ASCII", "UTF-8", (char *)S, SDL_strlen(S)+1)
#endif
#else /* fprintf, _exit(), etc. */
#include <stdio.h>
#include <stdlib.h>
Expand Down
11 changes: 2 additions & 9 deletions src/atomic/SDL_spinlock.c
Expand Up @@ -25,22 +25,15 @@
#include "SDL_timer.h"

/* Don't do the check for Visual Studio 2005, it's safe here */
#if defined(_MSC_VER)
#ifdef _WIN32_WCE
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#else
#include <intrin.h>
#endif
#endif /* _MSC_VER */
#include "../core/windows/SDL_windows.h"

/* This function is where all the magic happens... */
SDL_bool
SDL_AtomicTryLock(SDL_SpinLock *lock)
{
#if defined(_MSC_VER)
SDL_COMPILE_TIME_ASSERT(locksize, sizeof(*lock) == sizeof(long));
return (_InterlockedExchange((long*)lock, 1) == 0);
return (InterlockedExchange((long*)lock, 1) == 0);

#elif defined(__MACOSX__)
return OSAtomicCompareAndSwap32Barrier(0, 1, lock);
Expand Down
2 changes: 1 addition & 1 deletion src/audio/android/SDL_androidaudio.c
Expand Up @@ -27,7 +27,7 @@
#include "../SDL_audio_c.h"
#include "SDL_androidaudio.h"

#include "../../SDL_android.h"
#include "../../core/android/SDL_android.h"

#include <android/log.h>

Expand Down
10 changes: 1 addition & 9 deletions src/audio/windib/SDL_dibaudio.c
Expand Up @@ -23,8 +23,7 @@

/* Allow access to a raw mixing buffer */

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "../../core/windows/SDL_windows.h"
#include <mmsystem.h>

#include "SDL_timer.h"
Expand Down Expand Up @@ -67,21 +66,14 @@ SetMMerror(char *function, MMRESULT code)
{
size_t len;
char errbuf[MAXERRORLENGTH];
#ifdef _WIN32_WCE
wchar_t werrbuf[MAXERRORLENGTH];
#endif

SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: ", function);
len = SDL_strlen(errbuf);

#ifdef _WIN32_WCE
/* UNICODE version */
waveOutGetErrorText(code, werrbuf, MAXERRORLENGTH - len);
WideCharToMultiByte(CP_ACP, 0, werrbuf, -1, errbuf + len,
MAXERRORLENGTH - len, NULL, NULL);
#else
waveOutGetErrorText(code, errbuf + len, (UINT) (MAXERRORLENGTH - len));
#endif

SDL_SetError("%s", errbuf);
}
Expand Down
18 changes: 9 additions & 9 deletions src/audio/windx5/SDL_dx5audio.c
Expand Up @@ -24,6 +24,7 @@
/* Allow access to a raw mixing buffer */

#include "SDL_timer.h"
#include "SDL_loadso.h"
#include "SDL_audio.h"
#include "../SDL_audio_c.h"
#include "SDL_dx5audio.h"
Expand All @@ -38,19 +39,19 @@
#endif

/* DirectX function pointers for audio */
static HINSTANCE DSoundDLL = NULL;
static void* DSoundDLL = NULL;
static HRESULT(WINAPI * DSoundCreate) (LPGUID, LPDIRECTSOUND *, LPUNKNOWN) =
NULL;

static void
DSOUND_Unload(void)
{
DSoundCreate = NULL;

if (DSoundDLL != NULL) {
FreeLibrary(DSoundDLL);
SDL_UnloadObject(DSoundDLL);
DSoundDLL = NULL;
}

DSoundCreate = NULL;
DSoundDLL = NULL;
}


Expand All @@ -61,17 +62,16 @@ DSOUND_Load(void)

DSOUND_Unload();

DSoundDLL = LoadLibrary(TEXT("DSOUND.DLL"));
DSoundDLL = SDL_LoadObject("DSOUND.DLL");
if (DSoundDLL == NULL) {
SDL_SetError("DirectSound: failed to load DSOUND.DLL");
} else {
/* Now make sure we have DirectX 5 or better... */
/* (DirectSoundCaptureCreate was added in DX5) */
if (!GetProcAddress(DSoundDLL, TEXT("DirectSoundCaptureCreate"))) {
if (!SDL_LoadFunction(DSoundDLL, "DirectSoundCaptureCreate")) {
SDL_SetError("DirectSound: System doesn't appear to have DX5.");
} else {
DSoundCreate = (void *) GetProcAddress(DSoundDLL,
TEXT("DirectSoundCreate"));
DSoundCreate = SDL_LoadFunction(DSoundDLL, "DirectSoundCreate");
}

if (!DSoundCreate) {
Expand Down
3 changes: 1 addition & 2 deletions src/audio/windx5/directx.h
Expand Up @@ -4,8 +4,7 @@

/* Include all of the DirectX 5.0 headers and adds any necessary tweaks */

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "../../core/windows/SDL_windows.h"
#include <mmsystem.h>
#ifndef WIN32
#define WIN32
Expand Down
File renamed without changes.
File renamed without changes.
41 changes: 41 additions & 0 deletions src/core/windows/SDL_windows.c
@@ -0,0 +1,41 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2010 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"

#include "SDL_error.h"
#include "SDL_windows.h"


/* Sets an error message based on GetLastError() */
void
WIN_SetError(const char *prefix)
{
TCHAR buffer[1024];
char *message;
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0,
buffer, SDL_arraysize(buffer), NULL);
message = WIN_StringToUTF8(buffer);
SDL_SetError("%s%s%s", prefix ? prefix : "", prefix ? ": " : "", message);
SDL_free(message);
}

/* vi: set ts=4 sw=4 expandtab: */
53 changes: 53 additions & 0 deletions src/core/windows/SDL_windows.h
@@ -0,0 +1,53 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2010 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/

/* This is an include file for windows.h with the SDL build settings */

#ifndef _INCLUDED_WINDOWS_H
#define _INCLUDED_WINDOWS_H

#define WIN32_LEAN_AND_MEAN
#define STRICT
#ifndef UNICODE
#define UNICODE 1
#endif
#undef WINVER
#define WINVER 0x500 /* Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices() */

#include <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: */
3 changes: 1 addition & 2 deletions src/cpuinfo/SDL_cpuinfo.c
Expand Up @@ -39,8 +39,7 @@
#include <setjmp.h>
#endif
#ifdef __WIN32__
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "../core/windows/SDL_windows.h"
#endif

#define CPU_HAS_RDTSC 0x00000001
Expand Down

0 comments on commit 6b41c2c

Please sign in to comment.