aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2012-03-08 17:42:16 -0800
committerChris Robinson <[email protected]>2012-03-08 17:42:16 -0800
commit1a4a0abd1a1fd9a20345db54efef6587bec67197 (patch)
tree36be0e37fb89ca39a25f6d64fa6c484c7d03c931
parentdddacc25a53e12b036b3599fd045b9eab942d5af (diff)
Pin the DLL for Windows
The mmdevapi backend does not react well to being unloaded dynamically. It has a message-handling thread running in the background which can't quit before DllMain is called with DLL_PROCESS_DETACH, at which point it's too late to safely message and wait for it shutddown, thus it can continue running after the DLL is unloaded from memory.
-rw-r--r--Alc/ALc.c6
-rw-r--r--CMakeLists.txt8
2 files changed, 8 insertions, 6 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index 449160d7..1dc4f609 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -418,15 +418,17 @@ static void alc_deinit_safe(void);
UIntMap TlsDestructor;
#ifndef AL_LIBTYPE_STATIC
-BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
+BOOL APIENTRY DllMain(HINSTANCE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
{
ALsizei i;
- (void)hModule;
// Perform actions based on the reason for calling.
switch(ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
+ /* Pin the DLL so we won't get unloaded until the process terminates */
+ GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_PIN | GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
+ (WCHAR*)hModule, &hModule);
InitUIntMap(&TlsDestructor, ~0);
alc_init();
break;
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1abd4d40..eb55a795 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -64,7 +64,7 @@ OPTION(ALSOFT_CONFIG "Install alsoft.conf configuration file" OFF)
IF(WIN32)
SET(LIBNAME OpenAL32)
- ADD_DEFINITIONS("-D_WIN32 -D_WIN32_WINNT=0x0500")
+ ADD_DEFINITIONS("-D_WIN32 -D_WIN32_WINNT=0x0501")
ELSE()
SET(LIBNAME openal)
ENDIF()
@@ -332,7 +332,7 @@ IF(DLOPEN)
ENDIF()
# Check if we have Windows headers
-CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0500)
+CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0501)
IF(NOT HAVE_WINDOWS_H)
CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
IF(NOT HAVE_GETTIMEOFDAY)
@@ -378,7 +378,7 @@ ENDIF()
CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
IF(NOT HAVE_STDINT_H)
IF(HAVE_WINDOWS_H)
- CHECK_C_SOURCE_COMPILES("\#define _WIN32_WINNT 0x0500
+ CHECK_C_SOURCE_COMPILES("\#define _WIN32_WINNT 0x0501
\#include <windows.h>
__int64 foo;
int main() {return 0;}" HAVE___INT64)
@@ -551,7 +551,7 @@ ENDIF()
IF(HAVE_WINDOWS_H)
IF(WINMM)
- CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0500)
+ CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0501)
IF(HAVE_MMSYSTEM_H AND HAVE_LIBWINMM)
SET(HAVE_WINMM 1)
SET(ALC_OBJS ${ALC_OBJS} Alc/backends/winmm.c)