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

Commit

Permalink
WinRT: added support for the SDL_loadso APIs, via LoadPackagedLibrary
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLudwig committed Dec 31, 2012
1 parent a991e2f commit 33f679e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
2 changes: 2 additions & 0 deletions VisualC/SDL/SDL_VS2012_WinRT.vcxproj
Expand Up @@ -53,6 +53,7 @@
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
</ClCompile>
<ClCompile Include="..\..\src\core\windows\SDL_windows.c" />
<ClCompile Include="..\..\src\cpuinfo\SDL_cpuinfo.c" />
<ClCompile Include="..\..\src\events\SDL_clipboardevents.c" />
<ClCompile Include="..\..\src\events\SDL_dropevents.c" />
Expand All @@ -68,6 +69,7 @@
<ClCompile Include="..\..\src\haptic\SDL_haptic.c" />
<ClCompile Include="..\..\src\joystick\dummy\SDL_sysjoystick.c" />
<ClCompile Include="..\..\src\joystick\SDL_joystick.c" />
<ClCompile Include="..\..\src\loadso\windows\SDL_sysloadso.c" />
<ClCompile Include="..\..\src\render\SDL_render.c" />
<ClCompile Include="..\..\src\render\SDL_yuv_mmx.c" />
<ClCompile Include="..\..\src\render\SDL_yuv_sw.c" />
Expand Down
4 changes: 1 addition & 3 deletions include/SDL_config_windowsrt.h
Expand Up @@ -146,9 +146,7 @@ typedef unsigned int uintptr_t;
#define SDL_JOYSTICK_DISABLED 1

/* Enable various shared object loading systems */
// TODO, WinRT: adapt the Win32 shared object loading code for WinRT
#define SDL_LOADSO_DISABLED 1
//#define SDL_LOADSO_WINDOWS 1
#define SDL_LOADSO_WINDOWS 1

/* Enable various threading systems */
#define SDL_THREAD_STDCPP 1
Expand Down
15 changes: 13 additions & 2 deletions src/core/windows/SDL_windows.c
Expand Up @@ -20,12 +20,12 @@
*/
#include "SDL_config.h"

#ifdef __WIN32__
#if defined(__WIN32__) || defined(__WINRT__)

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

#include <objbase.h> /* for CoInitialize/CoUninitialize */
#include <objbase.h> /* for CoInitialize/CoUninitialize (Win32 only) */


/* Sets an error message based on GetLastError() */
Expand All @@ -44,6 +44,14 @@ WIN_SetError(const char *prefix)
HRESULT
WIN_CoInitialize(void)
{
#ifdef __WINRT__
/* DLudwig: On WinRT, it is assumed that COM was initialized in main().
CoInitializeEx is available (not CoInitialize though), however
on WinRT, main() is typically declared with the [MTAThread]
attribute, which, AFAIK, should initialize COM.
*/
return S_OK;
#else
const HRESULT hr = CoInitialize(NULL);

/* S_FALSE means success, but someone else already initialized. */
Expand All @@ -53,12 +61,15 @@ WIN_CoInitialize(void)
}

return hr;
#endif
}

void
WIN_CoUninitialize(void)
{
#ifndef __WINRT__
CoUninitialize();
#endif
}

#endif /* __WIN32__ */
Expand Down
8 changes: 8 additions & 0 deletions src/loadso/windows/SDL_sysloadso.c
Expand Up @@ -33,7 +33,15 @@ void *
SDL_LoadObject(const char *sofile)
{
LPTSTR tstr = WIN_UTF8ToString(sofile);
#ifdef __WINRT__
/* WinRT only publically supports LoadPackagedLibrary() for loading .dll
files. LoadLibrary() is a private API, and not available for apps
(that can be published to MS' Windows Store.)
*/
void *handle = (void *) LoadPackagedLibrary(tstr, 0);
#else
void *handle = (void *) LoadLibrary(tstr);
#endif
SDL_free(tstr);

/* Generate an error message if all loads failed */
Expand Down

0 comments on commit 33f679e

Please sign in to comment.