2 * Copyright 2009 Maarten Lankhorst
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define NONAMELESSUNION
27 #include "wine/debug.h"
28 #include "wine/list.h"
32 #include "mmdeviceapi.h"
35 #include "audioclient.h"
36 #include "endpointvolume.h"
37 #include "audiopolicy.h"
38 #include "spatialaudioclient.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(mmdevapi
);
45 static HKEY key_render
;
46 static HKEY key_capture
;
48 typedef struct MMDevPropStoreImpl
50 IPropertyStore IPropertyStore_iface
;
56 typedef struct MMDevEnumImpl
58 IMMDeviceEnumerator IMMDeviceEnumerator_iface
;
62 static MMDevEnumImpl
*MMDevEnumerator
;
63 static MMDevice
**MMDevice_head
;
64 static MMDevice
*MMDevice_def_rec
, *MMDevice_def_play
;
65 static DWORD MMDevice_count
;
66 static const IMMDeviceEnumeratorVtbl MMDevEnumVtbl
;
67 static const IMMDeviceCollectionVtbl MMDevColVtbl
;
68 static const IMMDeviceVtbl MMDeviceVtbl
;
69 static const IPropertyStoreVtbl MMDevPropVtbl
;
70 static const IMMEndpointVtbl MMEndpointVtbl
;
72 static IMMDevice info_device
;
74 typedef struct MMDevColImpl
76 IMMDeviceCollection IMMDeviceCollection_iface
;
82 typedef struct IPropertyBagImpl
{
83 IPropertyBag IPropertyBag_iface
;
87 static const IPropertyBagVtbl PB_Vtbl
;
89 static HRESULT
MMDevPropStore_Create(MMDevice
*This
, DWORD access
, IPropertyStore
**ppv
);
91 static inline MMDevPropStore
*impl_from_IPropertyStore(IPropertyStore
*iface
)
93 return CONTAINING_RECORD(iface
, MMDevPropStore
, IPropertyStore_iface
);
96 static inline MMDevEnumImpl
*impl_from_IMMDeviceEnumerator(IMMDeviceEnumerator
*iface
)
98 return CONTAINING_RECORD(iface
, MMDevEnumImpl
, IMMDeviceEnumerator_iface
);
101 static inline MMDevColImpl
*impl_from_IMMDeviceCollection(IMMDeviceCollection
*iface
)
103 return CONTAINING_RECORD(iface
, MMDevColImpl
, IMMDeviceCollection_iface
);
106 static inline IPropertyBagImpl
*impl_from_IPropertyBag(IPropertyBag
*iface
)
108 return CONTAINING_RECORD(iface
, IPropertyBagImpl
, IPropertyBag_iface
);
111 static const WCHAR propkey_formatW
[] = L
"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X},%d";
113 static HRESULT
MMDevPropStore_OpenPropKey(const GUID
*guid
, DWORD flow
, HKEY
*propkey
)
118 StringFromGUID2(guid
, buffer
, 39);
119 if ((ret
= RegOpenKeyExW(flow
== eRender
? key_render
: key_capture
, buffer
, 0, KEY_READ
|KEY_WRITE
|KEY_WOW64_64KEY
, &key
)) != ERROR_SUCCESS
)
121 WARN("Opening key %s failed with %u\n", debugstr_w(buffer
), ret
);
124 ret
= RegOpenKeyExW(key
, L
"Properties", 0, KEY_READ
|KEY_WRITE
|KEY_WOW64_64KEY
, propkey
);
126 if (ret
!= ERROR_SUCCESS
)
128 WARN("Opening key Properties failed with %u\n", ret
);
134 static HRESULT
MMDevice_GetPropValue(const GUID
*devguid
, DWORD flow
, REFPROPERTYKEY key
, PROPVARIANT
*pv
)
137 const GUID
*id
= &key
->fmtid
;
143 hr
= MMDevPropStore_OpenPropKey(devguid
, flow
, ®key
);
146 wsprintfW( buffer
, propkey_formatW
, id
->Data1
, id
->Data2
, id
->Data3
,
147 id
->Data4
[0], id
->Data4
[1], id
->Data4
[2], id
->Data4
[3],
148 id
->Data4
[4], id
->Data4
[5], id
->Data4
[6], id
->Data4
[7], key
->pid
);
149 ret
= RegGetValueW(regkey
, NULL
, buffer
, RRF_RT_ANY
, &type
, NULL
, &size
);
150 if (ret
!= ERROR_SUCCESS
)
152 WARN("Reading %s returned %d\n", debugstr_w(buffer
), ret
);
154 PropVariantClear(pv
);
163 pv
->u
.pwszVal
= CoTaskMemAlloc(size
);
167 RegGetValueW(regkey
, NULL
, buffer
, RRF_RT_REG_SZ
, NULL
, (BYTE
*)pv
->u
.pwszVal
, &size
);
173 RegGetValueW(regkey
, NULL
, buffer
, RRF_RT_REG_DWORD
, NULL
, (BYTE
*)&pv
->u
.ulVal
, &size
);
179 pv
->u
.blob
.cbSize
= size
;
180 pv
->u
.blob
.pBlobData
= CoTaskMemAlloc(size
);
181 if (!pv
->u
.blob
.pBlobData
)
184 RegGetValueW(regkey
, NULL
, buffer
, RRF_RT_REG_BINARY
, NULL
, (BYTE
*)pv
->u
.blob
.pBlobData
, &size
);
188 ERR("Unknown/unhandled type: %u\n", type
);
189 PropVariantClear(pv
);
196 static HRESULT
MMDevice_SetPropValue(const GUID
*devguid
, DWORD flow
, REFPROPERTYKEY key
, REFPROPVARIANT pv
)
199 const GUID
*id
= &key
->fmtid
;
204 hr
= MMDevPropStore_OpenPropKey(devguid
, flow
, ®key
);
207 wsprintfW( buffer
, propkey_formatW
, id
->Data1
, id
->Data2
, id
->Data3
,
208 id
->Data4
[0], id
->Data4
[1], id
->Data4
[2], id
->Data4
[3],
209 id
->Data4
[4], id
->Data4
[5], id
->Data4
[6], id
->Data4
[7], key
->pid
);
214 ret
= RegSetValueExW(regkey
, buffer
, 0, REG_DWORD
, (const BYTE
*)&pv
->u
.ulVal
, sizeof(DWORD
));
219 ret
= RegSetValueExW(regkey
, buffer
, 0, REG_BINARY
, pv
->u
.blob
.pBlobData
, pv
->u
.blob
.cbSize
);
220 TRACE("Blob %p %u\n", pv
->u
.blob
.pBlobData
, pv
->u
.blob
.cbSize
);
226 ret
= RegSetValueExW(regkey
, buffer
, 0, REG_SZ
, (const BYTE
*)pv
->u
.pwszVal
, sizeof(WCHAR
)*(1+lstrlenW(pv
->u
.pwszVal
)));
231 FIXME("Unhandled type %u\n", pv
->vt
);
236 TRACE("Writing %s returned %u\n", debugstr_w(buffer
), ret
);
240 static HRESULT
set_driver_prop_value(GUID
*id
, const EDataFlow flow
, const PROPERTYKEY
*prop
)
245 if (!drvs
.pGetPropValue
)
248 hr
= drvs
.pGetPropValue(id
, prop
, &pv
);
252 MMDevice_SetPropValue(id
, flow
, prop
, &pv
);
253 PropVariantClear(&pv
);
259 /* Creates or updates the state of a device
260 * If GUID is null, a random guid will be assigned
261 * and the device will be created
263 static MMDevice
*MMDevice_Create(WCHAR
*name
, GUID
*id
, EDataFlow flow
, DWORD state
, BOOL setdefault
)
266 MMDevice
*cur
= NULL
;
270 static const PROPERTYKEY deviceinterface_key
= {
271 {0x233164c8, 0x1b2c, 0x4c7d, {0xbc, 0x68, 0xb6, 0x71, 0x68, 0x7a, 0x25, 0x67}}, 1
274 static const PROPERTYKEY devicepath_key
= {
275 {0xb3f8fa53, 0x0004, 0x438e, {0x90, 0x03, 0x51, 0xa4, 0x6e, 0x13, 0x9b, 0xfc}}, 2
278 for (i
= 0; i
< MMDevice_count
; ++i
)
280 MMDevice
*device
= MMDevice_head
[i
];
281 if (device
->flow
== flow
&& IsEqualGUID(&device
->devguid
, id
)){
288 /* No device found, allocate new one */
289 cur
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*cur
));
293 cur
->IMMDevice_iface
.lpVtbl
= &MMDeviceVtbl
;
294 cur
->IMMEndpoint_iface
.lpVtbl
= &MMEndpointVtbl
;
296 InitializeCriticalSection(&cur
->crst
);
297 cur
->crst
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": MMDevice.crst");
300 MMDevice_head
= HeapAlloc(GetProcessHeap(), 0, sizeof(*MMDevice_head
));
302 MMDevice_head
= HeapReAlloc(GetProcessHeap(), 0, MMDevice_head
, sizeof(*MMDevice_head
)*(1+MMDevice_count
));
303 MMDevice_head
[MMDevice_count
++] = cur
;
304 }else if(cur
->ref
> 0)
305 WARN("Modifying an MMDevice with postitive reference count!\n");
307 HeapFree(GetProcessHeap(), 0, cur
->drv_id
);
314 StringFromGUID2(&cur
->devguid
, guidstr
, ARRAY_SIZE(guidstr
));
321 if (RegCreateKeyExW(root
, guidstr
, 0, NULL
, 0, KEY_WRITE
|KEY_READ
|KEY_WOW64_64KEY
, NULL
, &key
, NULL
) == ERROR_SUCCESS
)
324 RegSetValueExW(key
, L
"DeviceState", 0, REG_DWORD
, (const BYTE
*)&state
, sizeof(DWORD
));
325 if (!RegCreateKeyExW(key
, L
"Properties", 0, NULL
, 0, KEY_WRITE
|KEY_READ
|KEY_WOW64_64KEY
, NULL
, &keyprop
, NULL
))
331 MMDevice_SetPropValue(id
, flow
, (const PROPERTYKEY
*)&DEVPKEY_Device_FriendlyName
, &pv
);
332 MMDevice_SetPropValue(id
, flow
, (const PROPERTYKEY
*)&DEVPKEY_DeviceInterface_FriendlyName
, &pv
);
333 MMDevice_SetPropValue(id
, flow
, (const PROPERTYKEY
*)&DEVPKEY_Device_DeviceDesc
, &pv
);
335 pv
.u
.pwszVal
= guidstr
;
336 MMDevice_SetPropValue(id
, flow
, &deviceinterface_key
, &pv
);
338 set_driver_prop_value(id
, flow
, &devicepath_key
);
340 if (FAILED(set_driver_prop_value(id
, flow
, &PKEY_AudioEndpoint_FormFactor
)))
343 pv
.u
.ulVal
= (flow
== eCapture
) ? Microphone
: Speakers
;
345 MMDevice_SetPropValue(id
, flow
, &PKEY_AudioEndpoint_FormFactor
, &pv
);
348 if (flow
!= eCapture
)
352 PropVariantInit(&pv2
);
354 /* make read-write by not overwriting if already set */
355 if (FAILED(MMDevice_GetPropValue(id
, flow
, &PKEY_AudioEndpoint_PhysicalSpeakers
, &pv2
)) || pv2
.vt
!= VT_UI4
)
356 set_driver_prop_value(id
, flow
, &PKEY_AudioEndpoint_PhysicalSpeakers
);
358 PropVariantClear(&pv2
);
361 RegCloseKey(keyprop
);
369 MMDevice_def_play
= cur
;
371 MMDevice_def_rec
= cur
;
376 static HRESULT
load_devices_from_reg(void)
383 ret
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
,
384 L
"Software\\Microsoft\\Windows\\CurrentVersion\\MMDevices\\Audio", 0, NULL
, 0,
385 KEY_WRITE
|KEY_READ
|KEY_WOW64_64KEY
, NULL
, &root
, NULL
);
386 if (ret
== ERROR_SUCCESS
)
387 ret
= RegCreateKeyExW(root
, L
"Capture", 0, NULL
, 0, KEY_READ
|KEY_WRITE
|KEY_WOW64_64KEY
, NULL
, &key_capture
, NULL
);
388 if (ret
== ERROR_SUCCESS
)
389 ret
= RegCreateKeyExW(root
, L
"Render", 0, NULL
, 0, KEY_READ
|KEY_WRITE
|KEY_WOW64_64KEY
, NULL
, &key_render
, NULL
);
393 if (ret
!= ERROR_SUCCESS
)
395 RegCloseKey(key_capture
);
396 key_render
= key_capture
= NULL
;
397 WARN("Couldn't create key: %u\n", ret
);
405 PROPVARIANT pv
= { VT_EMPTY
};
407 len
= ARRAY_SIZE(guidvalue
);
408 ret
= RegEnumKeyExW(cur
, i
++, guidvalue
, &len
, NULL
, NULL
, NULL
, NULL
);
409 if (ret
== ERROR_NO_MORE_ITEMS
)
411 if (cur
== key_capture
)
420 if (ret
!= ERROR_SUCCESS
)
422 if (SUCCEEDED(CLSIDFromString(guidvalue
, &guid
))
423 && SUCCEEDED(MMDevice_GetPropValue(&guid
, curflow
, (const PROPERTYKEY
*)&DEVPKEY_Device_FriendlyName
, &pv
))
424 && pv
.vt
== VT_LPWSTR
)
426 DWORD size_bytes
= (lstrlenW(pv
.u
.pwszVal
) + 1) * sizeof(WCHAR
);
427 WCHAR
*name
= HeapAlloc(GetProcessHeap(), 0, size_bytes
);
428 memcpy(name
, pv
.u
.pwszVal
, size_bytes
);
429 MMDevice_Create(name
, &guid
, curflow
,
430 DEVICE_STATE_NOTPRESENT
, FALSE
);
431 CoTaskMemFree(pv
.u
.pwszVal
);
438 static HRESULT
set_format(MMDevice
*dev
)
441 IAudioClient
*client
;
443 PROPVARIANT pv
= { VT_EMPTY
};
445 hr
= drvs
.pGetAudioEndpoint(&dev
->devguid
, &dev
->IMMDevice_iface
, &client
);
449 hr
= IAudioClient_GetMixFormat(client
, &fmt
);
451 IAudioClient_Release(client
);
455 IAudioClient_Release(client
);
458 pv
.u
.blob
.cbSize
= sizeof(WAVEFORMATEX
) + fmt
->cbSize
;
459 pv
.u
.blob
.pBlobData
= (BYTE
*)fmt
;
460 MMDevice_SetPropValue(&dev
->devguid
, dev
->flow
,
461 &PKEY_AudioEngine_DeviceFormat
, &pv
);
462 MMDevice_SetPropValue(&dev
->devguid
, dev
->flow
,
463 &PKEY_AudioEngine_OEMFormat
, &pv
);
469 static HRESULT
load_driver_devices(EDataFlow flow
)
476 if(!drvs
.pGetEndpointIDs
)
479 hr
= drvs
.pGetEndpointIDs(flow
, &ids
, &guids
, &num
, &def
);
483 for(i
= 0; i
< num
; ++i
){
485 dev
= MMDevice_Create(ids
[i
], &guids
[i
], flow
, DEVICE_STATE_ACTIVE
,
490 HeapFree(GetProcessHeap(), 0, guids
);
491 HeapFree(GetProcessHeap(), 0, ids
);
496 static void MMDevice_Destroy(MMDevice
*This
)
499 TRACE("Freeing %s\n", debugstr_w(This
->drv_id
));
500 /* Since this function is called at destruction time, reordering of the list is unimportant */
501 for (i
= 0; i
< MMDevice_count
; ++i
)
503 if (MMDevice_head
[i
] == This
)
505 MMDevice_head
[i
] = MMDevice_head
[--MMDevice_count
];
509 This
->crst
.DebugInfo
->Spare
[0] = 0;
510 DeleteCriticalSection(&This
->crst
);
511 HeapFree(GetProcessHeap(), 0, This
->drv_id
);
512 HeapFree(GetProcessHeap(), 0, This
);
515 static inline MMDevice
*impl_from_IMMDevice(IMMDevice
*iface
)
517 return CONTAINING_RECORD(iface
, MMDevice
, IMMDevice_iface
);
520 static HRESULT WINAPI
MMDevice_QueryInterface(IMMDevice
*iface
, REFIID riid
, void **ppv
)
522 MMDevice
*This
= impl_from_IMMDevice(iface
);
523 TRACE("(%p)->(%s,%p)\n", iface
, debugstr_guid(riid
), ppv
);
528 if (IsEqualIID(riid
, &IID_IUnknown
)
529 || IsEqualIID(riid
, &IID_IMMDevice
))
530 *ppv
= &This
->IMMDevice_iface
;
531 else if (IsEqualIID(riid
, &IID_IMMEndpoint
))
532 *ppv
= &This
->IMMEndpoint_iface
;
535 IUnknown_AddRef((IUnknown
*)*ppv
);
538 WARN("Unknown interface %s\n", debugstr_guid(riid
));
539 return E_NOINTERFACE
;
542 static ULONG WINAPI
MMDevice_AddRef(IMMDevice
*iface
)
544 MMDevice
*This
= impl_from_IMMDevice(iface
);
547 ref
= InterlockedIncrement(&This
->ref
);
548 TRACE("Refcount now %i\n", ref
);
552 static ULONG WINAPI
MMDevice_Release(IMMDevice
*iface
)
554 MMDevice
*This
= impl_from_IMMDevice(iface
);
557 ref
= InterlockedDecrement(&This
->ref
);
558 TRACE("Refcount now %i\n", ref
);
562 static HRESULT WINAPI
MMDevice_Activate(IMMDevice
*iface
, REFIID riid
, DWORD clsctx
, PROPVARIANT
*params
, void **ppv
)
564 HRESULT hr
= E_NOINTERFACE
;
565 MMDevice
*This
= impl_from_IMMDevice(iface
);
567 TRACE("(%p)->(%s, %x, %p, %p)\n", iface
, debugstr_guid(riid
), clsctx
, params
, ppv
);
572 if (IsEqualIID(riid
, &IID_IAudioClient
) ||
573 IsEqualIID(riid
, &IID_IAudioClient2
) ||
574 IsEqualIID(riid
, &IID_IAudioClient3
)){
575 hr
= drvs
.pGetAudioEndpoint(&This
->devguid
, iface
, (IAudioClient
**)ppv
);
576 }else if (IsEqualIID(riid
, &IID_IAudioEndpointVolume
) ||
577 IsEqualIID(riid
, &IID_IAudioEndpointVolumeEx
))
578 hr
= AudioEndpointVolume_Create(This
, (IAudioEndpointVolumeEx
**)ppv
);
579 else if (IsEqualIID(riid
, &IID_IAudioSessionManager
)
580 || IsEqualIID(riid
, &IID_IAudioSessionManager2
))
582 hr
= drvs
.pGetAudioSessionManager(iface
, (IAudioSessionManager2
**)ppv
);
584 else if (IsEqualIID(riid
, &IID_IBaseFilter
))
586 if (This
->flow
== eRender
)
587 hr
= CoCreateInstance(&CLSID_DSoundRender
, NULL
, clsctx
, riid
, ppv
);
589 ERR("Not supported for recording?\n");
592 IPersistPropertyBag
*ppb
;
593 hr
= IUnknown_QueryInterface((IUnknown
*)*ppv
, &IID_IPersistPropertyBag
, (void **)&ppb
);
596 /* ::Load cannot assume the interface stays alive after the function returns,
597 * so just create the interface on the stack, saves a lot of complicated code */
598 IPropertyBagImpl bag
= { { &PB_Vtbl
} };
599 bag
.devguid
= This
->devguid
;
600 hr
= IPersistPropertyBag_Load(ppb
, &bag
.IPropertyBag_iface
, NULL
);
601 IPersistPropertyBag_Release(ppb
);
603 IBaseFilter_Release((IBaseFilter
*)*ppv
);
607 FIXME("Wine doesn't support IPersistPropertyBag on DSoundRender yet, ignoring..\n");
612 else if (IsEqualIID(riid
, &IID_IDeviceTopology
))
614 FIXME("IID_IDeviceTopology unsupported\n");
616 else if (IsEqualIID(riid
, &IID_IDirectSound
)
617 || IsEqualIID(riid
, &IID_IDirectSound8
))
619 if (This
->flow
== eRender
)
620 hr
= CoCreateInstance(&CLSID_DirectSound8
, NULL
, clsctx
, riid
, ppv
);
623 hr
= IDirectSound_Initialize((IDirectSound
*)*ppv
, &This
->devguid
);
625 IDirectSound_Release((IDirectSound
*)*ppv
);
628 else if (IsEqualIID(riid
, &IID_IDirectSoundCapture
))
630 if (This
->flow
== eCapture
)
631 hr
= CoCreateInstance(&CLSID_DirectSoundCapture8
, NULL
, clsctx
, riid
, ppv
);
634 hr
= IDirectSoundCapture_Initialize((IDirectSoundCapture
*)*ppv
, &This
->devguid
);
636 IDirectSoundCapture_Release((IDirectSoundCapture
*)*ppv
);
639 else if (IsEqualIID(riid
, &IID_ISpatialAudioClient
))
641 hr
= SpatialAudioClient_Create(iface
, (ISpatialAudioClient
**)ppv
);
644 ERR("Invalid/unknown iid %s\n", debugstr_guid(riid
));
649 TRACE("Returning %08x\n", hr
);
653 static HRESULT WINAPI
MMDevice_OpenPropertyStore(IMMDevice
*iface
, DWORD access
, IPropertyStore
**ppv
)
655 MMDevice
*This
= impl_from_IMMDevice(iface
);
656 TRACE("(%p)->(%x,%p)\n", This
, access
, ppv
);
660 return MMDevPropStore_Create(This
, access
, ppv
);
663 static HRESULT WINAPI
MMDevice_GetId(IMMDevice
*iface
, WCHAR
**itemid
)
665 MMDevice
*This
= impl_from_IMMDevice(iface
);
667 GUID
*id
= &This
->devguid
;
669 TRACE("(%p)->(%p)\n", This
, itemid
);
672 *itemid
= str
= CoTaskMemAlloc(56 * sizeof(WCHAR
));
674 return E_OUTOFMEMORY
;
675 wsprintfW(str
, L
"{0.0.%u.00000000}.{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
676 This
->flow
, id
->Data1
, id
->Data2
, id
->Data3
,
677 id
->Data4
[0], id
->Data4
[1], id
->Data4
[2], id
->Data4
[3],
678 id
->Data4
[4], id
->Data4
[5], id
->Data4
[6], id
->Data4
[7]);
679 TRACE("returning %s\n", wine_dbgstr_w(str
));
683 static HRESULT WINAPI
MMDevice_GetState(IMMDevice
*iface
, DWORD
*state
)
685 MMDevice
*This
= impl_from_IMMDevice(iface
);
686 TRACE("(%p)->(%p)\n", iface
, state
);
690 *state
= This
->state
;
694 static const IMMDeviceVtbl MMDeviceVtbl
=
696 MMDevice_QueryInterface
,
700 MMDevice_OpenPropertyStore
,
705 static inline MMDevice
*impl_from_IMMEndpoint(IMMEndpoint
*iface
)
707 return CONTAINING_RECORD(iface
, MMDevice
, IMMEndpoint_iface
);
710 static HRESULT WINAPI
MMEndpoint_QueryInterface(IMMEndpoint
*iface
, REFIID riid
, void **ppv
)
712 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
713 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
714 return IMMDevice_QueryInterface(&This
->IMMDevice_iface
, riid
, ppv
);
717 static ULONG WINAPI
MMEndpoint_AddRef(IMMEndpoint
*iface
)
719 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
720 TRACE("(%p)\n", This
);
721 return IMMDevice_AddRef(&This
->IMMDevice_iface
);
724 static ULONG WINAPI
MMEndpoint_Release(IMMEndpoint
*iface
)
726 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
727 TRACE("(%p)\n", This
);
728 return IMMDevice_Release(&This
->IMMDevice_iface
);
731 static HRESULT WINAPI
MMEndpoint_GetDataFlow(IMMEndpoint
*iface
, EDataFlow
*flow
)
733 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
734 TRACE("(%p)->(%p)\n", This
, flow
);
741 static const IMMEndpointVtbl MMEndpointVtbl
=
743 MMEndpoint_QueryInterface
,
746 MMEndpoint_GetDataFlow
749 static HRESULT
MMDevCol_Create(IMMDeviceCollection
**ppv
, EDataFlow flow
, DWORD state
)
753 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
756 return E_OUTOFMEMORY
;
757 This
->IMMDeviceCollection_iface
.lpVtbl
= &MMDevColVtbl
;
761 *ppv
= &This
->IMMDeviceCollection_iface
;
765 static void MMDevCol_Destroy(MMDevColImpl
*This
)
767 HeapFree(GetProcessHeap(), 0, This
);
770 static HRESULT WINAPI
MMDevCol_QueryInterface(IMMDeviceCollection
*iface
, REFIID riid
, void **ppv
)
772 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
773 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
777 if (IsEqualIID(riid
, &IID_IUnknown
)
778 || IsEqualIID(riid
, &IID_IMMDeviceCollection
))
779 *ppv
= &This
->IMMDeviceCollection_iface
;
783 return E_NOINTERFACE
;
784 IUnknown_AddRef((IUnknown
*)*ppv
);
788 static ULONG WINAPI
MMDevCol_AddRef(IMMDeviceCollection
*iface
)
790 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
791 LONG ref
= InterlockedIncrement(&This
->ref
);
792 TRACE("Refcount now %i\n", ref
);
796 static ULONG WINAPI
MMDevCol_Release(IMMDeviceCollection
*iface
)
798 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
799 LONG ref
= InterlockedDecrement(&This
->ref
);
800 TRACE("Refcount now %i\n", ref
);
802 MMDevCol_Destroy(This
);
806 static HRESULT WINAPI
MMDevCol_GetCount(IMMDeviceCollection
*iface
, UINT
*numdevs
)
808 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
811 TRACE("(%p)->(%p)\n", This
, numdevs
);
816 for (i
= 0; i
< MMDevice_count
; ++i
)
818 MMDevice
*cur
= MMDevice_head
[i
];
819 if ((cur
->flow
== This
->flow
|| This
->flow
== eAll
)
820 && (cur
->state
& This
->state
))
826 static HRESULT WINAPI
MMDevCol_Item(IMMDeviceCollection
*iface
, UINT n
, IMMDevice
**dev
)
828 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
831 TRACE("(%p)->(%u, %p)\n", This
, n
, dev
);
835 for (j
= 0; j
< MMDevice_count
; ++j
)
837 MMDevice
*cur
= MMDevice_head
[j
];
838 if ((cur
->flow
== This
->flow
|| This
->flow
== eAll
)
839 && (cur
->state
& This
->state
)
842 *dev
= &cur
->IMMDevice_iface
;
843 IMMDevice_AddRef(*dev
);
847 WARN("Could not obtain item %u\n", n
);
852 static const IMMDeviceCollectionVtbl MMDevColVtbl
=
854 MMDevCol_QueryInterface
,
861 HRESULT
MMDevEnum_Create(REFIID riid
, void **ppv
)
863 MMDevEnumImpl
*This
= MMDevEnumerator
;
867 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
870 return E_OUTOFMEMORY
;
872 This
->IMMDeviceEnumerator_iface
.lpVtbl
= &MMDevEnumVtbl
;
873 MMDevEnumerator
= This
;
875 load_devices_from_reg();
876 load_driver_devices(eRender
);
877 load_driver_devices(eCapture
);
879 return IMMDeviceEnumerator_QueryInterface(&This
->IMMDeviceEnumerator_iface
, riid
, ppv
);
882 void MMDevEnum_Free(void)
884 while (MMDevice_count
)
885 MMDevice_Destroy(MMDevice_head
[0]);
886 RegCloseKey(key_render
);
887 RegCloseKey(key_capture
);
888 key_render
= key_capture
= NULL
;
889 HeapFree(GetProcessHeap(), 0, MMDevEnumerator
);
890 MMDevEnumerator
= NULL
;
893 static HRESULT WINAPI
MMDevEnum_QueryInterface(IMMDeviceEnumerator
*iface
, REFIID riid
, void **ppv
)
895 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
896 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
900 if (IsEqualIID(riid
, &IID_IUnknown
)
901 || IsEqualIID(riid
, &IID_IMMDeviceEnumerator
))
902 *ppv
= &This
->IMMDeviceEnumerator_iface
;
906 return E_NOINTERFACE
;
907 IUnknown_AddRef((IUnknown
*)*ppv
);
911 static ULONG WINAPI
MMDevEnum_AddRef(IMMDeviceEnumerator
*iface
)
913 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
914 LONG ref
= InterlockedIncrement(&This
->ref
);
915 TRACE("Refcount now %i\n", ref
);
919 static ULONG WINAPI
MMDevEnum_Release(IMMDeviceEnumerator
*iface
)
921 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
922 LONG ref
= InterlockedDecrement(&This
->ref
);
925 TRACE("Refcount now %i\n", ref
);
929 static HRESULT WINAPI
MMDevEnum_EnumAudioEndpoints(IMMDeviceEnumerator
*iface
, EDataFlow flow
, DWORD mask
, IMMDeviceCollection
**devices
)
931 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
932 TRACE("(%p)->(%u,%u,%p)\n", This
, flow
, mask
, devices
);
936 if (flow
>= EDataFlow_enum_count
)
938 if (mask
& ~DEVICE_STATEMASK_ALL
)
940 return MMDevCol_Create(devices
, flow
, mask
);
943 static HRESULT WINAPI
MMDevEnum_GetDefaultAudioEndpoint(IMMDeviceEnumerator
*iface
, EDataFlow flow
, ERole role
, IMMDevice
**device
)
945 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
950 TRACE("(%p)->(%u,%u,%p)\n", This
, flow
, role
, device
);
955 if((flow
!= eRender
&& flow
!= eCapture
) ||
956 (role
!= eConsole
&& role
!= eMultimedia
&& role
!= eCommunications
)){
957 WARN("Unknown flow (%u) or role (%u)\n", flow
, role
);
963 if(!drvs
.module_name
[0])
966 lstrcpyW(reg_key
, drv_keyW
);
967 lstrcatW(reg_key
, L
"\\");
968 lstrcatW(reg_key
, drvs
.module_name
);
970 if(RegOpenKeyW(HKEY_CURRENT_USER
, reg_key
, &key
) == ERROR_SUCCESS
){
971 const WCHAR
*reg_x_name
, *reg_vx_name
;
973 DWORD size
= sizeof(def_id
), state
;
976 reg_x_name
= L
"DefaultOutput";
977 reg_vx_name
= L
"DefaultVoiceOutput";
979 reg_x_name
= L
"DefaultInput";
980 reg_vx_name
= L
"DefaultVoiceInput";
983 if(role
== eCommunications
&&
984 RegQueryValueExW(key
, reg_vx_name
, 0, NULL
,
985 (BYTE
*)def_id
, &size
) == ERROR_SUCCESS
){
986 hr
= IMMDeviceEnumerator_GetDevice(iface
, def_id
, device
);
988 if(SUCCEEDED(IMMDevice_GetState(*device
, &state
)) &&
989 state
== DEVICE_STATE_ACTIVE
){
995 TRACE("Unable to find voice device %s\n", wine_dbgstr_w(def_id
));
998 if(RegQueryValueExW(key
, reg_x_name
, 0, NULL
,
999 (BYTE
*)def_id
, &size
) == ERROR_SUCCESS
){
1000 hr
= IMMDeviceEnumerator_GetDevice(iface
, def_id
, device
);
1002 if(SUCCEEDED(IMMDevice_GetState(*device
, &state
)) &&
1003 state
== DEVICE_STATE_ACTIVE
){
1009 TRACE("Unable to find device %s\n", wine_dbgstr_w(def_id
));
1015 if (flow
== eRender
)
1016 *device
= &MMDevice_def_play
->IMMDevice_iface
;
1018 *device
= &MMDevice_def_rec
->IMMDevice_iface
;
1022 IMMDevice_AddRef(*device
);
1026 static HRESULT WINAPI
MMDevEnum_GetDevice(IMMDeviceEnumerator
*iface
, const WCHAR
*name
, IMMDevice
**device
)
1028 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
1030 IMMDevice
*dev
= NULL
;
1032 TRACE("(%p)->(%s,%p)\n", This
, debugstr_w(name
), device
);
1034 if(!name
|| !device
)
1037 if(!lstrcmpW(name
, L
"Wine info device")){
1038 *device
= &info_device
;
1042 for (i
= 0; i
< MMDevice_count
; ++i
)
1046 dev
= &MMDevice_head
[i
]->IMMDevice_iface
;
1047 hr
= IMMDevice_GetId(dev
, &str
);
1050 WARN("GetId failed: %08x\n", hr
);
1054 if (str
&& !lstrcmpW(str
, name
))
1057 IMMDevice_AddRef(dev
);
1063 TRACE("Could not find device %s\n", debugstr_w(name
));
1064 return E_INVALIDARG
;
1067 struct NotificationClientWrapper
{
1068 IMMNotificationClient
*client
;
1072 static struct list g_notif_clients
= LIST_INIT(g_notif_clients
);
1073 static HANDLE g_notif_thread
;
1075 static CRITICAL_SECTION g_notif_lock
;
1076 static CRITICAL_SECTION_DEBUG g_notif_lock_debug
=
1078 0, 0, &g_notif_lock
,
1079 { &g_notif_lock_debug
.ProcessLocksList
, &g_notif_lock_debug
.ProcessLocksList
},
1080 0, 0, { (DWORD_PTR
)(__FILE__
": g_notif_lock") }
1082 static CRITICAL_SECTION g_notif_lock
= { &g_notif_lock_debug
, -1, 0, 0, 0, 0 };
1084 static void notify_clients(EDataFlow flow
, ERole role
, const WCHAR
*id
)
1086 struct NotificationClientWrapper
*wrapper
;
1087 LIST_FOR_EACH_ENTRY(wrapper
, &g_notif_clients
,
1088 struct NotificationClientWrapper
, entry
)
1089 IMMNotificationClient_OnDefaultDeviceChanged(wrapper
->client
, flow
,
1092 /* Windows 7 treats changes to eConsole as changes to eMultimedia */
1093 if(role
== eConsole
)
1094 notify_clients(flow
, eMultimedia
, id
);
1097 static BOOL
notify_if_changed(EDataFlow flow
, ERole role
, HKEY key
,
1098 const WCHAR
*val_name
, WCHAR
*old_val
, IMMDevice
*def_dev
)
1100 WCHAR new_val
[64], *id
;
1104 size
= sizeof(new_val
);
1105 if(RegQueryValueExW(key
, val_name
, 0, NULL
,
1106 (BYTE
*)new_val
, &size
) != ERROR_SUCCESS
){
1107 if(old_val
[0] != 0){
1108 /* set by user -> system default */
1110 hr
= IMMDevice_GetId(def_dev
, &id
);
1112 ERR("GetId failed: %08x\n", hr
);
1118 notify_clients(flow
, role
, id
);
1125 /* system default -> system default, noop */
1129 if(!lstrcmpW(old_val
, new_val
)){
1130 /* set by user -> same value */
1134 if(new_val
[0] != 0){
1135 /* set by user -> different value */
1136 notify_clients(flow
, role
, new_val
);
1137 memcpy(old_val
, new_val
, sizeof(new_val
));
1141 /* set by user -> system default */
1143 hr
= IMMDevice_GetId(def_dev
, &id
);
1145 ERR("GetId failed: %08x\n", hr
);
1151 notify_clients(flow
, role
, id
);
1158 static DWORD WINAPI
notif_thread_proc(void *user
)
1162 WCHAR out_name
[64], vout_name
[64], in_name
[64], vin_name
[64];
1165 lstrcpyW(reg_key
, drv_keyW
);
1166 lstrcatW(reg_key
, L
"\\");
1167 lstrcatW(reg_key
, drvs
.module_name
);
1169 if(RegCreateKeyExW(HKEY_CURRENT_USER
, reg_key
, 0, NULL
, 0,
1170 MAXIMUM_ALLOWED
, NULL
, &key
, NULL
) != ERROR_SUCCESS
){
1171 ERR("RegCreateKeyEx failed: %u\n", GetLastError());
1175 size
= sizeof(out_name
);
1176 if(RegQueryValueExW(key
, L
"DefaultOutput", 0, NULL
, (BYTE
*)out_name
, &size
) != ERROR_SUCCESS
)
1179 size
= sizeof(vout_name
);
1180 if(RegQueryValueExW(key
, L
"DefaultVoiceOutput", 0, NULL
, (BYTE
*)vout_name
, &size
) != ERROR_SUCCESS
)
1183 size
= sizeof(in_name
);
1184 if(RegQueryValueExW(key
, L
"DefaultInput", 0, NULL
, (BYTE
*)in_name
, &size
) != ERROR_SUCCESS
)
1187 size
= sizeof(vin_name
);
1188 if(RegQueryValueExW(key
, L
"DefaultVoiceInput", 0, NULL
, (BYTE
*)vin_name
, &size
) != ERROR_SUCCESS
)
1192 if(RegNotifyChangeKeyValue(key
, FALSE
, REG_NOTIFY_CHANGE_LAST_SET
,
1193 NULL
, FALSE
) != ERROR_SUCCESS
){
1194 ERR("RegNotifyChangeKeyValue failed: %u\n", GetLastError());
1196 g_notif_thread
= NULL
;
1200 EnterCriticalSection(&g_notif_lock
);
1202 notify_if_changed(eRender
, eConsole
, key
, L
"DefaultOutput",
1203 out_name
, &MMDevice_def_play
->IMMDevice_iface
);
1204 notify_if_changed(eRender
, eCommunications
, key
, L
"DefaultVoiceOutput",
1205 vout_name
, &MMDevice_def_play
->IMMDevice_iface
);
1206 notify_if_changed(eCapture
, eConsole
, key
, L
"DefaultInput",
1207 in_name
, &MMDevice_def_rec
->IMMDevice_iface
);
1208 notify_if_changed(eCapture
, eCommunications
, key
, L
"DefaultVoiceInput",
1209 vin_name
, &MMDevice_def_rec
->IMMDevice_iface
);
1211 LeaveCriticalSection(&g_notif_lock
);
1216 g_notif_thread
= NULL
;
1221 static HRESULT WINAPI
MMDevEnum_RegisterEndpointNotificationCallback(IMMDeviceEnumerator
*iface
, IMMNotificationClient
*client
)
1223 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
1224 struct NotificationClientWrapper
*wrapper
;
1226 TRACE("(%p)->(%p)\n", This
, client
);
1231 wrapper
= HeapAlloc(GetProcessHeap(), 0, sizeof(*wrapper
));
1233 return E_OUTOFMEMORY
;
1235 wrapper
->client
= client
;
1237 EnterCriticalSection(&g_notif_lock
);
1239 list_add_tail(&g_notif_clients
, &wrapper
->entry
);
1241 if(!g_notif_thread
){
1242 g_notif_thread
= CreateThread(NULL
, 0, notif_thread_proc
, NULL
, 0, NULL
);
1244 ERR("CreateThread failed: %u\n", GetLastError());
1247 LeaveCriticalSection(&g_notif_lock
);
1252 static HRESULT WINAPI
MMDevEnum_UnregisterEndpointNotificationCallback(IMMDeviceEnumerator
*iface
, IMMNotificationClient
*client
)
1254 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
1255 struct NotificationClientWrapper
*wrapper
;
1257 TRACE("(%p)->(%p)\n", This
, client
);
1262 EnterCriticalSection(&g_notif_lock
);
1264 LIST_FOR_EACH_ENTRY(wrapper
, &g_notif_clients
, struct NotificationClientWrapper
, entry
){
1265 if(wrapper
->client
== client
){
1266 list_remove(&wrapper
->entry
);
1267 HeapFree(GetProcessHeap(), 0, wrapper
);
1268 LeaveCriticalSection(&g_notif_lock
);
1273 LeaveCriticalSection(&g_notif_lock
);
1278 static const IMMDeviceEnumeratorVtbl MMDevEnumVtbl
=
1280 MMDevEnum_QueryInterface
,
1283 MMDevEnum_EnumAudioEndpoints
,
1284 MMDevEnum_GetDefaultAudioEndpoint
,
1285 MMDevEnum_GetDevice
,
1286 MMDevEnum_RegisterEndpointNotificationCallback
,
1287 MMDevEnum_UnregisterEndpointNotificationCallback
1290 static HRESULT
MMDevPropStore_Create(MMDevice
*parent
, DWORD access
, IPropertyStore
**ppv
)
1292 MMDevPropStore
*This
;
1293 if (access
!= STGM_READ
1294 && access
!= STGM_WRITE
1295 && access
!= STGM_READWRITE
)
1297 WARN("Invalid access %08x\n", access
);
1298 return E_INVALIDARG
;
1300 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
1301 *ppv
= &This
->IPropertyStore_iface
;
1303 return E_OUTOFMEMORY
;
1304 This
->IPropertyStore_iface
.lpVtbl
= &MMDevPropVtbl
;
1306 This
->parent
= parent
;
1307 This
->access
= access
;
1311 static void MMDevPropStore_Destroy(MMDevPropStore
*This
)
1313 HeapFree(GetProcessHeap(), 0, This
);
1316 static HRESULT WINAPI
MMDevPropStore_QueryInterface(IPropertyStore
*iface
, REFIID riid
, void **ppv
)
1318 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1319 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
1323 if (IsEqualIID(riid
, &IID_IUnknown
)
1324 || IsEqualIID(riid
, &IID_IPropertyStore
))
1325 *ppv
= &This
->IPropertyStore_iface
;
1329 return E_NOINTERFACE
;
1330 IUnknown_AddRef((IUnknown
*)*ppv
);
1334 static ULONG WINAPI
MMDevPropStore_AddRef(IPropertyStore
*iface
)
1336 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1337 LONG ref
= InterlockedIncrement(&This
->ref
);
1338 TRACE("Refcount now %i\n", ref
);
1342 static ULONG WINAPI
MMDevPropStore_Release(IPropertyStore
*iface
)
1344 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1345 LONG ref
= InterlockedDecrement(&This
->ref
);
1346 TRACE("Refcount now %i\n", ref
);
1348 MMDevPropStore_Destroy(This
);
1352 static HRESULT WINAPI
MMDevPropStore_GetCount(IPropertyStore
*iface
, DWORD
*nprops
)
1354 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1360 TRACE("(%p)->(%p)\n", iface
, nprops
);
1363 hr
= MMDevPropStore_OpenPropKey(&This
->parent
->devguid
, This
->parent
->flow
, &propkey
);
1368 DWORD len
= ARRAY_SIZE(buffer
);
1369 if (RegEnumValueW(propkey
, i
, buffer
, &len
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
)
1373 RegCloseKey(propkey
);
1374 TRACE("Returning %i\n", i
);
1379 static HRESULT WINAPI
MMDevPropStore_GetAt(IPropertyStore
*iface
, DWORD prop
, PROPERTYKEY
*key
)
1381 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1383 DWORD len
= ARRAY_SIZE(buffer
);
1387 TRACE("(%p)->(%u,%p)\n", iface
, prop
, key
);
1391 hr
= MMDevPropStore_OpenPropKey(&This
->parent
->devguid
, This
->parent
->flow
, &propkey
);
1395 if (RegEnumValueW(propkey
, prop
, buffer
, &len
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
1398 WARN("GetAt %u failed\n", prop
);
1399 return E_INVALIDARG
;
1401 RegCloseKey(propkey
);
1403 CLSIDFromString(buffer
, &key
->fmtid
);
1404 key
->pid
= wcstol(&buffer
[39], NULL
, 10);
1408 static HRESULT WINAPI
MMDevPropStore_GetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, PROPVARIANT
*pv
)
1410 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1411 TRACE("(%p)->(\"%s,%u\", %p)\n", This
, key
? debugstr_guid(&key
->fmtid
) : NULL
, key
? key
->pid
: 0, pv
);
1415 if (This
->access
!= STGM_READ
1416 && This
->access
!= STGM_READWRITE
)
1417 return STG_E_ACCESSDENIED
;
1420 if (IsEqualPropertyKey(*key
, PKEY_AudioEndpoint_GUID
))
1423 pv
->u
.pwszVal
= CoTaskMemAlloc(39 * sizeof(WCHAR
));
1425 return E_OUTOFMEMORY
;
1426 StringFromGUID2(&This
->parent
->devguid
, pv
->u
.pwszVal
, 39);
1430 return MMDevice_GetPropValue(&This
->parent
->devguid
, This
->parent
->flow
, key
, pv
);
1433 static HRESULT WINAPI
MMDevPropStore_SetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, REFPROPVARIANT pv
)
1435 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1436 TRACE("(%p)->(\"%s,%u\", %p)\n", This
, key
? debugstr_guid(&key
->fmtid
) : NULL
, key
? key
->pid
: 0, pv
);
1441 if (This
->access
!= STGM_WRITE
1442 && This
->access
!= STGM_READWRITE
)
1443 return STG_E_ACCESSDENIED
;
1444 return MMDevice_SetPropValue(&This
->parent
->devguid
, This
->parent
->flow
, key
, pv
);
1447 static HRESULT WINAPI
MMDevPropStore_Commit(IPropertyStore
*iface
)
1449 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1450 TRACE("(%p)\n", iface
);
1452 if (This
->access
!= STGM_WRITE
1453 && This
->access
!= STGM_READWRITE
)
1454 return STG_E_ACCESSDENIED
;
1456 /* Does nothing - for mmdevapi, the propstore values are written on SetValue,
1462 static const IPropertyStoreVtbl MMDevPropVtbl
=
1464 MMDevPropStore_QueryInterface
,
1465 MMDevPropStore_AddRef
,
1466 MMDevPropStore_Release
,
1467 MMDevPropStore_GetCount
,
1468 MMDevPropStore_GetAt
,
1469 MMDevPropStore_GetValue
,
1470 MMDevPropStore_SetValue
,
1471 MMDevPropStore_Commit
1475 /* Property bag for IBaseFilter activation */
1476 static HRESULT WINAPI
PB_QueryInterface(IPropertyBag
*iface
, REFIID riid
, void **ppv
)
1478 ERR("Should not be called\n");
1480 return E_NOINTERFACE
;
1483 static ULONG WINAPI
PB_AddRef(IPropertyBag
*iface
)
1485 ERR("Should not be called\n");
1489 static ULONG WINAPI
PB_Release(IPropertyBag
*iface
)
1491 ERR("Should not be called\n");
1495 static HRESULT WINAPI
PB_Read(IPropertyBag
*iface
, LPCOLESTR name
, VARIANT
*var
, IErrorLog
*log
)
1497 IPropertyBagImpl
*This
= impl_from_IPropertyBag(iface
);
1498 TRACE("Trying to read %s, type %u\n", debugstr_w(name
), var
->n1
.n2
.vt
);
1499 if (!lstrcmpW(name
, L
"DSGuid"))
1502 StringFromGUID2(&This
->devguid
, guidstr
,ARRAY_SIZE(guidstr
));
1503 var
->n1
.n2
.vt
= VT_BSTR
;
1504 var
->n1
.n2
.n3
.bstrVal
= SysAllocString(guidstr
);
1507 ERR("Unknown property '%s' queried\n", debugstr_w(name
));
1511 static HRESULT WINAPI
PB_Write(IPropertyBag
*iface
, LPCOLESTR name
, VARIANT
*var
)
1513 ERR("Should not be called\n");
1517 static const IPropertyBagVtbl PB_Vtbl
=
1526 static ULONG WINAPI
info_device_ps_AddRef(IPropertyStore
*iface
)
1531 static ULONG WINAPI
info_device_ps_Release(IPropertyStore
*iface
)
1536 static HRESULT WINAPI
info_device_ps_GetValue(IPropertyStore
*iface
,
1537 REFPROPERTYKEY key
, PROPVARIANT
*pv
)
1539 TRACE("(static)->(\"%s,%u\", %p)\n", debugstr_guid(&key
->fmtid
), key
? key
->pid
: 0, pv
);
1544 if (IsEqualPropertyKey(*key
, DEVPKEY_Device_Driver
))
1546 INT size
= (lstrlenW(drvs
.module_name
) + 1) * sizeof(WCHAR
);
1548 pv
->u
.pwszVal
= CoTaskMemAlloc(size
);
1550 return E_OUTOFMEMORY
;
1551 memcpy(pv
->u
.pwszVal
, drvs
.module_name
, size
);
1555 return E_INVALIDARG
;
1558 static const IPropertyStoreVtbl info_device_ps_Vtbl
=
1561 info_device_ps_AddRef
,
1562 info_device_ps_Release
,
1565 info_device_ps_GetValue
,
1570 static IPropertyStore info_device_ps
= {
1571 &info_device_ps_Vtbl
1574 static ULONG WINAPI
info_device_AddRef(IMMDevice
*iface
)
1579 static ULONG WINAPI
info_device_Release(IMMDevice
*iface
)
1584 static HRESULT WINAPI
info_device_OpenPropertyStore(IMMDevice
*iface
,
1585 DWORD access
, IPropertyStore
**ppv
)
1587 TRACE("(static)->(%x, %p)\n", access
, ppv
);
1588 *ppv
= &info_device_ps
;
1592 static const IMMDeviceVtbl info_device_Vtbl
=
1596 info_device_Release
,
1598 info_device_OpenPropertyStore
,
1603 static IMMDevice info_device
= {