[PATCH v3 2/3] mmdevapi: Load devices on driver initialization.

Rémi Bernon rbernon at codeweavers.com
Thu Jun 3 11:15:30 CDT 2021


Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
 dlls/mmdevapi/devenum.c  | 14 +++-----------
 dlls/mmdevapi/main.c     |  6 ++++++
 dlls/mmdevapi/mmdevapi.h |  3 +++
 3 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/dlls/mmdevapi/devenum.c b/dlls/mmdevapi/devenum.c
index 38ae5f8962d..a0b36671595 100644
--- a/dlls/mmdevapi/devenum.c
+++ b/dlls/mmdevapi/devenum.c
@@ -373,7 +373,7 @@ static MMDevice *MMDevice_Create(WCHAR *name, GUID *id, EDataFlow flow, DWORD st
     return cur;
 }
 
-static HRESULT load_devices_from_reg(void)
+HRESULT load_devices_from_reg(void)
 {
     DWORD i = 0;
     HKEY root, cur;
@@ -466,7 +466,7 @@ static HRESULT set_format(MMDevice *dev)
     return S_OK;
 }
 
-static HRESULT load_driver_devices(EDataFlow flow)
+HRESULT load_driver_devices(EDataFlow flow)
 {
     WCHAR **ids;
     GUID *guids;
@@ -860,14 +860,6 @@ static const IMMDeviceCollectionVtbl MMDevColVtbl =
 
 HRESULT MMDevEnum_Create(REFIID riid, void **ppv)
 {
-    if (enumerator.ref == 0)
-    {
-        enumerator.ref = 1;
-        load_devices_from_reg();
-        load_driver_devices(eRender);
-        load_driver_devices(eCapture);
-    }
-
     return IMMDeviceEnumerator_QueryInterface(&enumerator.IMMDeviceEnumerator_iface, riid, ppv);
 }
 
@@ -1278,7 +1270,7 @@ static const IMMDeviceEnumeratorVtbl MMDevEnumVtbl =
 static MMDevEnumImpl enumerator =
 {
     {&MMDevEnumVtbl},
-    0,
+    1,
 };
 
 static HRESULT MMDevPropStore_Create(MMDevice *parent, DWORD access, IPropertyStore **ppv)
diff --git a/dlls/mmdevapi/main.c b/dlls/mmdevapi/main.c
index 9cc0aad6105..358c1697a23 100644
--- a/dlls/mmdevapi/main.c
+++ b/dlls/mmdevapi/main.c
@@ -148,6 +148,12 @@ static BOOL WINAPI init_driver(INIT_ONCE *once, void *param, void **context)
             *next = ',';
     }
 
+    if (drvs.module != 0){
+        load_devices_from_reg();
+        load_driver_devices(eRender);
+        load_driver_devices(eCapture);
+    }
+
     return drvs.module != 0;
 }
 
diff --git a/dlls/mmdevapi/mmdevapi.h b/dlls/mmdevapi/mmdevapi.h
index 3bcf568cddf..73c9b0e9592 100644
--- a/dlls/mmdevapi/mmdevapi.h
+++ b/dlls/mmdevapi/mmdevapi.h
@@ -73,4 +73,7 @@ extern HRESULT AudioClient_Create(MMDevice *parent, IAudioClient **ppv) DECLSPEC
 extern HRESULT AudioEndpointVolume_Create(MMDevice *parent, IAudioEndpointVolumeEx **ppv) DECLSPEC_HIDDEN;
 extern HRESULT SpatialAudioClient_Create(IMMDevice *device, ISpatialAudioClient **out) DECLSPEC_HIDDEN;
 
+extern HRESULT load_devices_from_reg(void) DECLSPEC_HIDDEN;
+extern HRESULT load_driver_devices(EDataFlow flow) DECLSPEC_HIDDEN;
+
 extern const WCHAR drv_keyW[] DECLSPEC_HIDDEN;
-- 
2.31.0




More information about the wine-devel mailing list