Win32 dynamic loading tweaks.

This commit is contained in:
Camilla Berglund 2010-09-14 04:27:02 +02:00
parent 318f731e3e
commit 02804bc182
2 changed files with 63 additions and 74 deletions

View File

@ -234,11 +234,11 @@ typedef DWORD (WINAPI * TIMEGETTIME_T) (void);
// gdi32.dll shortcuts // gdi32.dll shortcuts
#ifndef _GLFW_NO_DLOAD_GDI32 #ifndef _GLFW_NO_DLOAD_GDI32
#define _glfw_ChoosePixelFormat _glfwLibrary.Win32.libs.ChoosePixelFormat #define _glfw_ChoosePixelFormat _glfwLibrary.Win32.gdi.ChoosePixelFormat
#define _glfw_DescribePixelFormat _glfwLibrary.Win32.libs.DescribePixelFormat #define _glfw_DescribePixelFormat _glfwLibrary.Win32.gdi.DescribePixelFormat
#define _glfw_GetPixelFormat _glfwLibrary.Win32.libs.GetPixelFormat #define _glfw_GetPixelFormat _glfwLibrary.Win32.gdi.GetPixelFormat
#define _glfw_SetPixelFormat _glfwLibrary.Win32.libs.SetPixelFormat #define _glfw_SetPixelFormat _glfwLibrary.Win32.gdi.SetPixelFormat
#define _glfw_SwapBuffers _glfwLibrary.Win32.libs.SwapBuffers #define _glfw_SwapBuffers _glfwLibrary.Win32.gdi.SwapBuffers
#else #else
#define _glfw_ChoosePixelFormat ChoosePixelFormat #define _glfw_ChoosePixelFormat ChoosePixelFormat
#define _glfw_DescribePixelFormat DescribePixelFormat #define _glfw_DescribePixelFormat DescribePixelFormat
@ -249,10 +249,10 @@ typedef DWORD (WINAPI * TIMEGETTIME_T) (void);
// winmm.dll shortcuts // winmm.dll shortcuts
#ifndef _GLFW_NO_DLOAD_WINMM #ifndef _GLFW_NO_DLOAD_WINMM
#define _glfw_joyGetDevCaps _glfwLibrary.Win32.libs.joyGetDevCapsA #define _glfw_joyGetDevCaps _glfwLibrary.Win32.winmm.joyGetDevCapsA
#define _glfw_joyGetPos _glfwLibrary.Win32.libs.joyGetPos #define _glfw_joyGetPos _glfwLibrary.Win32.winmm.joyGetPos
#define _glfw_joyGetPosEx _glfwLibrary.Win32.libs.joyGetPosEx #define _glfw_joyGetPosEx _glfwLibrary.Win32.winmm.joyGetPosEx
#define _glfw_timeGetTime _glfwLibrary.Win32.libs.timeGetTime #define _glfw_timeGetTime _glfwLibrary.Win32.winmm.timeGetTime
#else #else
#define _glfw_joyGetDevCaps joyGetDevCapsA #define _glfw_joyGetDevCaps joyGetDevCapsA
#define _glfw_joyGetPos joyGetPos #define _glfw_joyGetPos joyGetPos
@ -341,29 +341,28 @@ typedef struct _GLFWlibraryWin32
__int64 t0_64; __int64 t0_64;
} timer; } timer;
#if !defined(_GLFW_NO_DLOAD_WINMM) || !defined(_GLFW_NO_DLOAD_GDI32)
// Library handles and function pointers
struct {
#ifndef _GLFW_NO_DLOAD_GDI32 #ifndef _GLFW_NO_DLOAD_GDI32
// gdi32.dll // gdi32.dll
HINSTANCE gdi32; struct {
HINSTANCE instance;
CHOOSEPIXELFORMAT_T ChoosePixelFormat; CHOOSEPIXELFORMAT_T ChoosePixelFormat;
DESCRIBEPIXELFORMAT_T DescribePixelFormat; DESCRIBEPIXELFORMAT_T DescribePixelFormat;
GETPIXELFORMAT_T GetPixelFormat; GETPIXELFORMAT_T GetPixelFormat;
SETPIXELFORMAT_T SetPixelFormat; SETPIXELFORMAT_T SetPixelFormat;
SWAPBUFFERS_T SwapBuffers; SWAPBUFFERS_T SwapBuffers;
} gdi;
#endif // _GLFW_NO_DLOAD_GDI32 #endif // _GLFW_NO_DLOAD_GDI32
// winmm.dll
#ifndef _GLFW_NO_DLOAD_WINMM #ifndef _GLFW_NO_DLOAD_WINMM
// winmm.dll
struct {
HINSTANCE winmm; HINSTANCE winmm;
JOYGETDEVCAPSA_T joyGetDevCapsA; JOYGETDEVCAPSA_T joyGetDevCapsA;
JOYGETPOS_T joyGetPos; JOYGETPOS_T joyGetPos;
JOYGETPOSEX_T joyGetPosEx; JOYGETPOSEX_T joyGetPosEx;
TIMEGETTIME_T timeGetTime; TIMEGETTIME_T timeGetTime;
} winmm;
#endif // _GLFW_NO_DLOAD_WINMM #endif // _GLFW_NO_DLOAD_WINMM
} libs;
#endif
} _GLFWlibraryWin32; } _GLFWlibraryWin32;

View File

@ -47,62 +47,54 @@ static GLboolean initLibraries(void)
#ifndef _GLFW_NO_DLOAD_GDI32 #ifndef _GLFW_NO_DLOAD_GDI32
// gdi32.dll (OpenGL pixel format functions & SwapBuffers) // gdi32.dll (OpenGL pixel format functions & SwapBuffers)
_glfwLibrary.Win32.libs.gdi32 = LoadLibrary("gdi32.dll"); _glfwLibrary.Win32.gdi.instance = LoadLibrary("gdi32.dll");
if (_glfwLibrary.Win32.libs.gdi32 != NULL) if (!_glfwLibrary.Win32.gdi.instance)
{ return GL_FALSE;
_glfwLibrary.Win32.libs.ChoosePixelFormat = (CHOOSEPIXELFORMAT_T)
GetProcAddress(_glfwLibrary.Win32.libs.gdi32, "ChoosePixelFormat");
_glfwLibrary.Win32.libs.DescribePixelFormat = (DESCRIBEPIXELFORMAT_T)
GetProcAddress(_glfwLibrary.Win32.libs.gdi32, "DescribePixelFormat");
_glfwLibrary.Win32.libs.GetPixelFormat = (GETPIXELFORMAT_T)
GetProcAddress(_glfwLibrary.Win32.libs.gdi32, "GetPixelFormat");
_glfwLibrary.Win32.libs.SetPixelFormat = (SETPIXELFORMAT_T)
GetProcAddress(_glfwLibrary.Win32.libs.gdi32, "SetPixelFormat");
_glfwLibrary.Win32.libs.SwapBuffers = (SWAPBUFFERS_T)
GetProcAddress(_glfwLibrary.Win32.libs.gdi32, "SwapBuffers");
if (!_glfwLibrary.Win32.libs.ChoosePixelFormat || _glfwLibrary.Win32.gdi.ChoosePixelFormat = (CHOOSEPIXELFORMAT_T)
!_glfwLibrary.Win32.libs.DescribePixelFormat || GetProcAddress(_glfwLibrary.Win32.gdi.instance, "ChoosePixelFormat");
!_glfwLibrary.Win32.libs.GetPixelFormat || _glfwLibrary.Win32.gdi.DescribePixelFormat = (DESCRIBEPIXELFORMAT_T)
!_glfwLibrary.Win32.libs.SetPixelFormat || GetProcAddress(_glfwLibrary.Win32.gdi.instance, "DescribePixelFormat");
!_glfwLibrary.Win32.libs.SwapBuffers) _glfwLibrary.Win32.gdi.GetPixelFormat = (GETPIXELFORMAT_T)
GetProcAddress(_glfwLibrary.Win32.gdi.instance, "GetPixelFormat");
_glfwLibrary.Win32.gdi.SetPixelFormat = (SETPIXELFORMAT_T)
GetProcAddress(_glfwLibrary.Win32.gdi.instance, "SetPixelFormat");
_glfwLibrary.Win32.gdi.SwapBuffers = (SWAPBUFFERS_T)
GetProcAddress(_glfwLibrary.Win32.gdi.instance, "SwapBuffers");
if (!_glfwLibrary.Win32.gdi.ChoosePixelFormat ||
!_glfwLibrary.Win32.gdi.DescribePixelFormat ||
!_glfwLibrary.Win32.gdi.GetPixelFormat ||
!_glfwLibrary.Win32.gdi.SetPixelFormat ||
!_glfwLibrary.Win32.gdi.SwapBuffers)
{ {
FreeLibrary(_glfwLibrary.Win32.libs.gdi32);
_glfwLibrary.Win32.libs.gdi32 = NULL;
return GL_FALSE; return GL_FALSE;
} }
}
else
return GL_FALSE;
#endif // _GLFW_NO_DLOAD_GDI32 #endif // _GLFW_NO_DLOAD_GDI32
#ifndef _GLFW_NO_DLOAD_WINMM #ifndef _GLFW_NO_DLOAD_WINMM
// winmm.dll (for joystick and timer support) // winmm.dll (for joystick and timer support)
_glfwLibrary.Win32.libs.winmm = LoadLibrary("winmm.dll"); _glfwLibrary.Win32.winmm.instance = LoadLibrary("winmm.dll");
if (_glfwLibrary.Win32.libs.winmm != NULL) if (!_glfwLibrary.Win32.winmm.instance)
{ return GL_FALSE;
_glfwLibrary.Win32.libs.joyGetDevCapsA = (JOYGETDEVCAPSA_T)
GetProcAddress(_glfwLibrary.Win32.libs.winmm, "joyGetDevCapsA");
_glfwLibrary.Win32.libs.joyGetPos = (JOYGETPOS_T)
GetProcAddress(_glfwLibrary.Win32.libs.winmm, "joyGetPos");
_glfwLibrary.Win32.libs.joyGetPosEx = (JOYGETPOSEX_T)
GetProcAddress(_glfwLibrary.Win32.libs.winmm, "joyGetPosEx");
_glfwLibrary.Win32.libs.timeGetTime = (TIMEGETTIME_T)
GetProcAddress(_glfwLibrary.Win32.libs.winmm, "timeGetTime");
if (!_glfwLibrary.Win32.libs.joyGetDevCapsA || _glfwLibrary.Win32.winmm.joyGetDevCapsA = (JOYGETDEVCAPSA_T)
!_glfwLibrary.Win32.libs.joyGetPos || GetProcAddress(_glfwLibrary.Win32.winmm.instance, "joyGetDevCapsA");
!_glfwLibrary.Win32.libs.joyGetPosEx || _glfwLibrary.Win32.winmm.joyGetPos = (JOYGETPOS_T)
!_glfwLibrary.Win32.libs.timeGetTime) GetProcAddress(_glfwLibrary.Win32.winmm.instance, "joyGetPos");
_glfwLibrary.Win32.winmm.joyGetPosEx = (JOYGETPOSEX_T)
GetProcAddress(_glfwLibrary.Win32.winmm.instance, "joyGetPosEx");
_glfwLibrary.Win32.winmm.timeGetTime = (TIMEGETTIME_T)
GetProcAddress(_glfwLibrary.Win32.winmm.instance, "timeGetTime");
if (!_glfwLibrary.Win32.winmm.joyGetDevCapsA ||
!_glfwLibrary.Win32.winmm.joyGetPos ||
!_glfwLibrary.Win32.winmm.joyGetPosEx ||
!_glfwLibrary.Win32.winmm.timeGetTime)
{ {
FreeLibrary(_glfwLibrary.Win32.libs.winmm);
_glfwLibrary.Win32.libs.winmm = NULL;
return GL_FALSE; return GL_FALSE;
} }
}
else
return GL_FALSE;
#endif // _GLFW_NO_DLOAD_WINMM #endif // _GLFW_NO_DLOAD_WINMM
return GL_TRUE; return GL_TRUE;
@ -115,21 +107,19 @@ static GLboolean initLibraries(void)
static void freeLibraries(void) static void freeLibraries(void)
{ {
// gdi32.dll
#ifndef _GLFW_NO_DLOAD_GDI32 #ifndef _GLFW_NO_DLOAD_GDI32
if (_glfwLibrary.Win32.libs.gdi32 != NULL) if (_glfwLibrary.Win32.gdi.instance != NULL)
{ {
FreeLibrary(_glfwLibrary.Win32.libs.gdi32); FreeLibrary(_glfwLibrary.Win32.gdi.instance);
_glfwLibrary.Win32.libs.gdi32 = NULL; _glfwLibrary.Win32.gdi.instance = NULL;
} }
#endif // _GLFW_NO_DLOAD_GDI32 #endif // _GLFW_NO_DLOAD_GDI32
// winmm.dll
#ifndef _GLFW_NO_DLOAD_WINMM #ifndef _GLFW_NO_DLOAD_WINMM
if (_glfwLibrary.Win32.libs.winmm != NULL) if (_glfwLibrary.Win32.winmm.winmm != NULL)
{ {
FreeLibrary(_glfwLibrary.Win32.libs.winmm); FreeLibrary(_glfwLibrary.Win32.winmm.winmm);
_glfwLibrary.Win32.libs.winmm = NULL; _glfwLibrary.Win32.winmm.winmm = NULL;
} }
#endif // _GLFW_NO_DLOAD_WINMM #endif // _GLFW_NO_DLOAD_WINMM
} }