diff options
author | Chris Robinson <[email protected]> | 2011-10-24 22:11:16 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2011-10-24 22:11:16 -0700 |
commit | 319f40462fe695126b02493a6d2fcd06ae3807b2 (patch) | |
tree | 9740050d009d9f33f9f4c0054c42e310bfe7a9c0 | |
parent | e5374f60c9fef1ccbeba86e7e9120519a5964c50 (diff) |
Initialize/Uninitialize COM as needed
-rw-r--r-- | Alc/backends/mmdevapi.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Alc/backends/mmdevapi.c b/Alc/backends/mmdevapi.c index 541bea3d..275a839a 100644 --- a/Alc/backends/mmdevapi.c +++ b/Alc/backends/mmdevapi.c @@ -486,6 +486,7 @@ static DWORD CALLBACK MMDevApiMsgProc(void *ptr) { ThreadRequest *req = ptr; IMMDeviceEnumerator *Enumerator; + ALuint deviceCount = 0; MMDevApiData *data; ALCdevice *device; HRESULT hr; @@ -515,6 +516,8 @@ static DWORD CALLBACK MMDevApiMsgProc(void *ptr) IMMDeviceEnumerator_Release(Enumerator); Enumerator = NULL; + CoUninitialize(); + req->result = S_OK; SetEvent(req->FinishedEvt); @@ -529,7 +532,11 @@ static DWORD CALLBACK MMDevApiMsgProc(void *ptr) device = (ALCdevice*)msg.lParam; data = device->ExtraData; - hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, &ptr); + hr = S_OK; + if(++deviceCount == 1) + hr = CoInitialize(NULL); + if(SUCCEEDED(hr)) + hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, &ptr); if(SUCCEEDED(hr)) { Enumerator = ptr; @@ -592,6 +599,9 @@ static DWORD CALLBACK MMDevApiMsgProc(void *ptr) IMMDevice_Release(data->mmdev); data->mmdev = NULL; + if(--deviceCount == 0) + CoUninitialize(); + req->result = S_OK; SetEvent(req->FinishedEvt); continue; @@ -603,7 +613,6 @@ static DWORD CALLBACK MMDevApiMsgProc(void *ptr) } TRACE("Message loop finished\n"); - CoUninitialize(); return 0; } |