Skip to content

Commit b6d15b8

Browse files
committed
[AUDIOSRV] Broadcast winmm_devicechange to all desktops and applications
This is an undocumented WinMM specific message that tells whether the `KSCATEGORY_AUDIO` devices were installed or removed. wParam and lParam are not used by this message.
1 parent fbe8102 commit b6d15b8

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

  • base/services/audiosrv

base/services/audiosrv/pnp.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <debug.h>
2020

2121
static HDEVNOTIFY device_notification_handle = NULL;
22+
static UINT uWinMMDeviceChange = 0;
2223

2324
/*
2425
Finds all devices within the KSCATEGORY_AUDIO category and puts them
@@ -100,6 +101,11 @@ ProcessExistingDevices(VOID)
100101

101102
SetupDiDestroyDeviceInfoList(dev_info);
102103

104+
uWinMMDeviceChange = RegisterWindowMessageW(L"winmm_devicechange");
105+
106+
if (uWinMMDeviceChange == 0)
107+
DPRINT("Failed to register window message: GetLastError %u", GetLastError());
108+
103109
return TRUE;
104110
}
105111

@@ -116,6 +122,20 @@ ProcessDeviceArrival(DEV_BROADCAST_DEVICEINTERFACE* device)
116122
AppendAudioDeviceToList(list_node);
117123
DestroyDeviceDescriptor(list_node);
118124

125+
DWORD dwInfo = BSM_ALLDESKTOPS | BSM_APPLICATIONS;
126+
BroadcastSystemMessageW(BSF_POSTMESSAGE, &dwInfo, uWinMMDeviceChange, 0, 0);
127+
128+
return NO_ERROR;
129+
}
130+
131+
DWORD
132+
ProcessDeviceRemovalComplete(DEV_BROADCAST_DEVICEINTERFACE* device)
133+
{
134+
/* If we need to clean up appended audio devices here,
135+
* this has to be implemented as well. */
136+
DWORD dwInfo = BSM_ALLDESKTOPS | BSM_APPLICATIONS;
137+
BroadcastSystemMessageW(BSF_POSTMESSAGE, &dwInfo, uWinMMDeviceChange, 0, 0);
138+
119139
return NO_ERROR;
120140
}
121141

@@ -184,7 +204,15 @@ HandleDeviceEvent(
184204
return ProcessDeviceArrival(incoming_device);
185205
}
186206

187-
default :
207+
case DBT_DEVICEREMOVECOMPLETE:
208+
{
209+
DEV_BROADCAST_DEVICEINTERFACE* removed_device =
210+
(DEV_BROADCAST_DEVICEINTERFACE*)lpEventData;
211+
212+
return ProcessDeviceRemovalComplete(removed_device);
213+
}
214+
215+
default:
188216
{
189217
break;
190218
}

0 commit comments

Comments
 (0)