aboutsummaryrefslogtreecommitdiffstats
path: root/alc/backends/dsound.cpp
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2023-09-29 13:29:51 -0700
committerChris Robinson <[email protected]>2023-09-29 13:29:51 -0700
commit014fb03d8353c8a495b4df4c44a7f29c93adba79 (patch)
treeb3a11f3b2f8aec1e1d8a156044cfb60a9ecd07d8 /alc/backends/dsound.cpp
parentfbe9d42d8a48330bb3ccc3966d1d94b438565f35 (diff)
Add a wrapper for COM initialization
This helps ensure COM is initialized and deinitialized in order relative to other objects (e.g. ComPtr).
Diffstat (limited to 'alc/backends/dsound.cpp')
-rw-r--r--alc/backends/dsound.cpp12
1 files changed, 3 insertions, 9 deletions
diff --git a/alc/backends/dsound.cpp b/alc/backends/dsound.cpp
index b5596f1c..58aa69b2 100644
--- a/alc/backends/dsound.cpp
+++ b/alc/backends/dsound.cpp
@@ -307,12 +307,10 @@ void DSoundPlayback::open(std::string_view name)
if(PlaybackDevices.empty())
{
/* Initialize COM to prevent name truncation */
- HRESULT hrcom{CoInitialize(nullptr)};
+ ComWrapper com{};
hr = DirectSoundEnumerateW(DSoundEnumDevices, &PlaybackDevices);
if(FAILED(hr))
ERR("Error enumerating DirectSound devices (0x%lx)!\n", hr);
- if(SUCCEEDED(hrcom))
- CoUninitialize();
}
const GUID *guid{nullptr};
@@ -583,12 +581,10 @@ void DSoundCapture::open(std::string_view name)
if(CaptureDevices.empty())
{
/* Initialize COM to prevent name truncation */
- HRESULT hrcom{CoInitialize(nullptr)};
+ ComWrapper com{};
hr = DirectSoundCaptureEnumerateW(DSoundEnumDevices, &CaptureDevices);
if(FAILED(hr))
ERR("Error enumerating DirectSound devices (0x%lx)!\n", hr);
- if(SUCCEEDED(hrcom))
- CoUninitialize();
}
const GUID *guid{nullptr};
@@ -815,8 +811,8 @@ std::string DSoundBackendFactory::probe(BackendType type)
};
/* Initialize COM to prevent name truncation */
+ ComWrapper com{};
HRESULT hr;
- HRESULT hrcom{CoInitialize(nullptr)};
switch(type)
{
case BackendType::Playback:
@@ -835,8 +831,6 @@ std::string DSoundBackendFactory::probe(BackendType type)
std::for_each(CaptureDevices.cbegin(), CaptureDevices.cend(), add_device);
break;
}
- if(SUCCEEDED(hrcom))
- CoUninitialize();
return outnames;
}