From 800ca2ee2a7fbed3aa5652b2c9bdd139b2d09a60 Mon Sep 17 00:00:00 2001 From: Henri Manson Date: Sat, 18 Feb 2006 23:38:01 +0000 Subject: [PATCH] Directsound window class only registered and created in DllMain because of multithreading --- fluidsynth/src/fluid_dll.c | 51 +++++++++++++++++++++++++++- fluidsynth/src/fluid_dsound.c | 64 +++-------------------------------- 2 files changed, 55 insertions(+), 60 deletions(-) diff --git a/fluidsynth/src/fluid_dll.c b/fluidsynth/src/fluid_dll.c index 45b79045..248844fe 100644 --- a/fluidsynth/src/fluid_dll.c +++ b/fluidsynth/src/fluid_dll.c @@ -23,13 +23,17 @@ #include "fluidsynth_priv.h" #include "fluid_sys.h" -HINSTANCE fluid_hinstance = NULL; +static HINSTANCE fluid_hinstance = NULL; +static HWND fluid_wnd = NULL; + +int fluid_win32_create_window(void); #ifndef FLUIDSYNTH_NOT_A_DLL BOOL WINAPI DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { FLUID_LOG(FLUID_DBG, "DllMain\n"); fluid_set_hinstance((void*) hModule); + fluid_win32_create_window(); return TRUE; } #endif @@ -46,5 +50,50 @@ void* fluid_get_hinstance(void) { return (void*) fluid_hinstance; } + +static long FAR PASCAL fluid_win32_wndproc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) { + case WM_CREATE: + break; + case WM_DESTROY: + break; + default: + return DefWindowProc(hWnd, message, wParam, lParam); + break; + } + return(0L); +} + +int fluid_win32_create_window(void) +{ + WNDCLASS myClass; + myClass.hCursor = LoadCursor( NULL, IDC_ARROW ); + myClass.hIcon = NULL; + myClass.lpszMenuName = (LPSTR) NULL; + myClass.lpszClassName = (LPSTR) "FluidSynth"; + myClass.hbrBackground = (HBRUSH)(COLOR_WINDOW); + myClass.hInstance = fluid_hinstance; + myClass.style = CS_GLOBALCLASS; + myClass.lpfnWndProc = fluid_win32_wndproc; + myClass.cbClsExtra = 0; + myClass.cbWndExtra = 0; + if (!RegisterClass(&myClass)) { + return -100; + } + fluid_wnd = CreateWindow((LPSTR) "FluidSynth", (LPSTR) "FluidSynth", WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, CW_USEDEFAULT, 400, 300, (HWND) NULL, (HMENU) NULL, + fluid_hinstance, (LPSTR) NULL); + if (fluid_wnd == NULL) { + FLUID_LOG(FLUID_ERR, "Can't create window"); + return -101; + } + return 0; +} + +HWND fluid_win32_get_window(void) +{ + return fluid_wnd; +} #endif diff --git a/fluidsynth/src/fluid_dsound.c b/fluidsynth/src/fluid_dsound.c index 28f780c7..43e6d4cb 100644 --- a/fluidsynth/src/fluid_dsound.c +++ b/fluidsynth/src/fluid_dsound.c @@ -30,17 +30,13 @@ #include #include -static HWND fluid_wnd = NULL; - fluid_audio_driver_t* new_fluid_dsound_audio_driver(fluid_settings_t* settings, fluid_synth_t* synth); int delete_fluid_dsound_audio_driver(fluid_audio_driver_t* data); DWORD WINAPI fluid_dsound_audio_run(LPVOID lpParameter); -int fluid_win32_create_window(void); -int fluid_win32_destroy_window(void); -long FAR PASCAL fluid_win32_wndproc(HWND hWnd, unsigned message, WPARAM wParam, LPARAM lParam); +HWND fluid_win32_get_window(void); char* fluid_win32_error(HRESULT hr); @@ -100,13 +96,14 @@ new_fluid_dsound_audio_driver(fluid_settings_t* settings, fluid_synth_t* synth) return NULL; } +/* if (fluid_wnd == NULL) { if (fluid_win32_create_window() != 0) { FLUID_LOG(FLUID_ERR, "Couldn't create window needed for DirectSound"); return NULL; } } - +*/ /* create and clear the driver data */ dev = FLUID_NEW(fluid_dsound_audio_driver_t); if (dev == NULL) { @@ -156,7 +153,7 @@ new_fluid_dsound_audio_driver(fluid_settings_t* settings, fluid_synth_t* synth) goto error_recovery; } - hr = IDirectSound_SetCooperativeLevel(dev->direct_sound, fluid_wnd, DSSCL_PRIORITY); + hr = IDirectSound_SetCooperativeLevel(dev->direct_sound, fluid_win32_get_window(), DSSCL_PRIORITY); if (hr != DS_OK) { FLUID_LOG(FLUID_ERR, "Failed to set the cooperative level"); goto error_recovery; @@ -282,7 +279,7 @@ int delete_fluid_dsound_audio_driver(fluid_audio_driver_t* d) FLUID_FREE(dev); - fluid_win32_destroy_window(); +// fluid_win32_destroy_window(); return 0; } @@ -371,54 +368,3 @@ char* fluid_win32_error(HRESULT hr) { } return s; } - - -long FAR PASCAL fluid_win32_wndproc(HWND hWnd, unsigned message, WPARAM wParam, LPARAM lParam) -{ - switch (message) { - case WM_CREATE: - break; - case WM_DESTROY: - break; - default: - return DefWindowProc(hWnd, message, wParam, lParam); - break; - } - return(0L); -} - -int fluid_win32_create_window(void) -{ - WNDCLASS myClass; - myClass.hCursor = LoadCursor( NULL, IDC_ARROW ); - myClass.hIcon = NULL; - myClass.lpszMenuName = (LPSTR) NULL; - myClass.lpszClassName = (LPSTR) "FluidSynth"; - myClass.hbrBackground = (HBRUSH)(COLOR_WINDOW); - myClass.hInstance = FLUID_HINSTANCE; - myClass.style = CS_GLOBALCLASS; - myClass.lpfnWndProc = fluid_win32_wndproc; - myClass.cbClsExtra = 0; - myClass.cbWndExtra = 0; - if (!RegisterClass(&myClass)) { - return -100; - } - fluid_wnd = CreateWindow((LPSTR) "FluidSynth", (LPSTR) "FluidSynth", WS_OVERLAPPEDWINDOW, - CW_USEDEFAULT, CW_USEDEFAULT, 400, 300, (HWND) NULL, (HMENU) NULL, - FLUID_HINSTANCE, (LPSTR) NULL); - if (fluid_wnd == NULL) { - FLUID_LOG(FLUID_ERR, "Can't create window"); - return -101; - } - return 0; -} - -int fluid_win32_destroy_window(void) -{ - if (fluid_wnd != NULL) { - DestroyWindow(fluid_wnd); - fluid_wnd = NULL; - UnregisterClass((LPSTR) "FluidSynth", FLUID_HINSTANCE); - } - return 0; -}