diff --git a/src/win32/DirectSound.cpp b/src/win32/DirectSound.cpp index 5ad5067b..6b9b74fb 100644 --- a/src/win32/DirectSound.cpp +++ b/src/win32/DirectSound.cpp @@ -62,11 +62,6 @@ public: DirectSound::DirectSound() { - if( S_OK != CoInitializeEx( NULL, COINIT_MULTITHREADED ) ) { - systemMessage( IDS_COM_FAILURE, NULL ); - return; - } - pDirectSound = NULL; dsbPrimary = NULL; dsbSecondary = NULL; @@ -103,8 +98,6 @@ DirectSound::~DirectSound() pDirectSound->Release(); pDirectSound = NULL; } - - CoUninitialize(); } diff --git a/src/win32/Directories.cpp b/src/win32/Directories.cpp index bdfde831..8b05e453 100644 --- a/src/win32/Directories.cpp +++ b/src/win32/Directories.cpp @@ -271,7 +271,6 @@ CString Directories::browseForDir(CString title) bi.lpfn = browseCallbackProc; bi.lParam = (LPARAM)(LPCTSTR)initialFolderDir; - CoInitialize( NULL ); // required by BIF_USENEWUI pidl = SHBrowseForFolder(&bi); if(pidl) { diff --git a/src/win32/VBA.cpp b/src/win32/VBA.cpp index 7b1e3a7c..1acc4fea 100644 --- a/src/win32/VBA.cpp +++ b/src/win32/VBA.cpp @@ -219,6 +219,11 @@ BEGIN_MESSAGE_MAP(VBA, CWinApp) VBA::VBA() { + // COINIT_MULTITHREADED is not supported by SHBrowseForFolder with BIF_USENEWUI + // OpenAL also causes trouble when COINIT_MULTITHREADED is used + if( S_OK != CoInitializeEx( NULL, COINIT_APARTMENTTHREADED ) ) { + systemMessage( IDS_COM_FAILURE, NULL ); + } mode320Available = false; mode640Available = false; mode800Available = false; @@ -419,6 +424,8 @@ VBA::~VBA() free( oalDevice ); } #endif + + CoUninitialize(); } ///////////////////////////////////////////////////////////////////////////// diff --git a/src/win32/XAudio2.cpp b/src/win32/XAudio2.cpp index a95df28f..0b4f9f82 100644 --- a/src/win32/XAudio2.cpp +++ b/src/win32/XAudio2.cpp @@ -45,10 +45,22 @@ class XAudio2_BufferNotify : public IXAudio2VoiceCallback public: HANDLE hBufferEndEvent; - XAudio2_BufferNotify() { hBufferEndEvent = CreateEvent( NULL, FALSE, FALSE, NULL ); } - ~XAudio2_BufferNotify() { CloseHandle( hBufferEndEvent ); } + XAudio2_BufferNotify() { + hBufferEndEvent = NULL; + hBufferEndEvent = CreateEvent( NULL, FALSE, FALSE, NULL ); + ASSERT( hBufferEndEvent != NULL ); + } + + ~XAudio2_BufferNotify() { + CloseHandle( hBufferEndEvent ); + hBufferEndEvent = NULL; + } + + STDMETHOD_( void, OnBufferEnd ) ( void *pBufferContext ) { + ASSERT( hBufferEndEvent != NULL ); + SetEvent( hBufferEndEvent ); + } - STDMETHOD_( void, OnBufferEnd ) ( void *pBufferContext ) { SetEvent( hBufferEndEvent ); } // dummies: STDMETHOD_( void, OnVoiceProcessingPassStart ) () {} @@ -115,12 +127,6 @@ XAudio2_Output::XAudio2_Output() sVoice = NULL; ZeroMemory( &buf, sizeof( buf ) ); ZeroMemory( &vState, sizeof( vState ) ); - - if( S_OK != CoInitializeEx( NULL, COINIT_MULTITHREADED ) ) { - systemMessage( IDS_COM_FAILURE, NULL ); - failed = true; - return; - } } @@ -146,8 +152,6 @@ XAudio2_Output::~XAudio2_Output() if( xaud ) { xaud->Release(); } - - CoUninitialize(); }