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 #include <wine/list.h>
29 static const WCHAR software_mmdevapi
[] =
30 { 'S','o','f','t','w','a','r','e','\\',
31 'M','i','c','r','o','s','o','f','t','\\',
32 'W','i','n','d','o','w','s','\\',
33 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
34 'M','M','D','e','v','i','c','e','s','\\',
35 'A','u','d','i','o',0};
36 static const WCHAR reg_render
[] =
37 { 'R','e','n','d','e','r',0 };
38 static const WCHAR reg_capture
[] =
39 { 'C','a','p','t','u','r','e',0 };
40 static const WCHAR reg_devicestate
[] =
41 { 'D','e','v','i','c','e','S','t','a','t','e',0 };
42 static const WCHAR reg_properties
[] =
43 { 'P','r','o','p','e','r','t','i','e','s',0 };
44 static const WCHAR slashW
[] = {'\\',0};
45 static const WCHAR reg_out_nameW
[] = {'D','e','f','a','u','l','t','O','u','t','p','u','t',0};
46 static const WCHAR reg_vout_nameW
[] = {'D','e','f','a','u','l','t','V','o','i','c','e','O','u','t','p','u','t',0};
47 static const WCHAR reg_in_nameW
[] = {'D','e','f','a','u','l','t','I','n','p','u','t',0};
48 static const WCHAR reg_vin_nameW
[] = {'D','e','f','a','u','l','t','V','o','i','c','e','I','n','p','u','t',0};
50 static HKEY key_render
;
51 static HKEY key_capture
;
53 typedef struct MMDevPropStoreImpl
55 IPropertyStore IPropertyStore_iface
;
61 typedef struct MMDevEnumImpl
63 IMMDeviceEnumerator IMMDeviceEnumerator_iface
;
67 static MMDevEnumImpl
*MMDevEnumerator
;
68 static MMDevice
**MMDevice_head
;
69 static MMDevice
*MMDevice_def_rec
, *MMDevice_def_play
;
70 static DWORD MMDevice_count
;
71 static const IMMDeviceEnumeratorVtbl MMDevEnumVtbl
;
72 static const IMMDeviceCollectionVtbl MMDevColVtbl
;
73 static const IMMDeviceVtbl MMDeviceVtbl
;
74 static const IPropertyStoreVtbl MMDevPropVtbl
;
75 static const IMMEndpointVtbl MMEndpointVtbl
;
77 static IMMDevice info_device
;
79 typedef struct MMDevColImpl
81 IMMDeviceCollection IMMDeviceCollection_iface
;
87 typedef struct IPropertyBagImpl
{
88 IPropertyBag IPropertyBag_iface
;
92 static const IPropertyBagVtbl PB_Vtbl
;
94 static HRESULT
MMDevPropStore_Create(MMDevice
*This
, DWORD access
, IPropertyStore
**ppv
);
96 static inline MMDevPropStore
*impl_from_IPropertyStore(IPropertyStore
*iface
)
98 return CONTAINING_RECORD(iface
, MMDevPropStore
, IPropertyStore_iface
);
101 static inline MMDevEnumImpl
*impl_from_IMMDeviceEnumerator(IMMDeviceEnumerator
*iface
)
103 return CONTAINING_RECORD(iface
, MMDevEnumImpl
, IMMDeviceEnumerator_iface
);
106 static inline MMDevColImpl
*impl_from_IMMDeviceCollection(IMMDeviceCollection
*iface
)
108 return CONTAINING_RECORD(iface
, MMDevColImpl
, IMMDeviceCollection_iface
);
111 static inline IPropertyBagImpl
*impl_from_IPropertyBag(IPropertyBag
*iface
)
113 return CONTAINING_RECORD(iface
, IPropertyBagImpl
, IPropertyBag_iface
);
116 static const WCHAR propkey_formatW
[] = {
117 '{','%','0','8','X','-','%','0','4','X','-',
118 '%','0','4','X','-','%','0','2','X','%','0','2','X','-',
119 '%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X',
120 '%','0','2','X','%','0','2','X','}',',','%','d',0 };
122 static HRESULT
MMDevPropStore_OpenPropKey(const GUID
*guid
, DWORD flow
, HKEY
*propkey
)
127 StringFromGUID2(guid
, buffer
, 39);
128 if ((ret
= RegOpenKeyExW(flow
== eRender
? key_render
: key_capture
, buffer
, 0, KEY_READ
|KEY_WRITE
|KEY_WOW64_64KEY
, &key
)) != ERROR_SUCCESS
)
130 WARN("Opening key %s failed with %u\n", debugstr_w(buffer
), ret
);
133 ret
= RegOpenKeyExW(key
, reg_properties
, 0, KEY_READ
|KEY_WRITE
|KEY_WOW64_64KEY
, propkey
);
135 if (ret
!= ERROR_SUCCESS
)
137 WARN("Opening key %s failed with %u\n", debugstr_w(reg_properties
), ret
);
143 static HRESULT
MMDevice_GetPropValue(const GUID
*devguid
, DWORD flow
, REFPROPERTYKEY key
, PROPVARIANT
*pv
)
146 const GUID
*id
= &key
->fmtid
;
152 hr
= MMDevPropStore_OpenPropKey(devguid
, flow
, ®key
);
155 wsprintfW( buffer
, propkey_formatW
, id
->Data1
, id
->Data2
, id
->Data3
,
156 id
->Data4
[0], id
->Data4
[1], id
->Data4
[2], id
->Data4
[3],
157 id
->Data4
[4], id
->Data4
[5], id
->Data4
[6], id
->Data4
[7], key
->pid
);
158 ret
= RegGetValueW(regkey
, NULL
, buffer
, RRF_RT_ANY
, &type
, NULL
, &size
);
159 if (ret
!= ERROR_SUCCESS
)
161 WARN("Reading %s returned %d\n", debugstr_w(buffer
), ret
);
163 PropVariantClear(pv
);
172 pv
->u
.pwszVal
= CoTaskMemAlloc(size
);
176 RegGetValueW(regkey
, NULL
, buffer
, RRF_RT_REG_SZ
, NULL
, (BYTE
*)pv
->u
.pwszVal
, &size
);
182 RegGetValueW(regkey
, NULL
, buffer
, RRF_RT_REG_DWORD
, NULL
, (BYTE
*)&pv
->u
.ulVal
, &size
);
188 pv
->u
.blob
.cbSize
= size
;
189 pv
->u
.blob
.pBlobData
= CoTaskMemAlloc(size
);
190 if (!pv
->u
.blob
.pBlobData
)
193 RegGetValueW(regkey
, NULL
, buffer
, RRF_RT_REG_BINARY
, NULL
, (BYTE
*)pv
->u
.blob
.pBlobData
, &size
);
197 ERR("Unknown/unhandled type: %u\n", type
);
198 PropVariantClear(pv
);
205 static HRESULT
MMDevice_SetPropValue(const GUID
*devguid
, DWORD flow
, REFPROPERTYKEY key
, REFPROPVARIANT pv
)
208 const GUID
*id
= &key
->fmtid
;
213 hr
= MMDevPropStore_OpenPropKey(devguid
, flow
, ®key
);
216 wsprintfW( buffer
, propkey_formatW
, id
->Data1
, id
->Data2
, id
->Data3
,
217 id
->Data4
[0], id
->Data4
[1], id
->Data4
[2], id
->Data4
[3],
218 id
->Data4
[4], id
->Data4
[5], id
->Data4
[6], id
->Data4
[7], key
->pid
);
223 ret
= RegSetValueExW(regkey
, buffer
, 0, REG_DWORD
, (const BYTE
*)&pv
->u
.ulVal
, sizeof(DWORD
));
228 ret
= RegSetValueExW(regkey
, buffer
, 0, REG_BINARY
, pv
->u
.blob
.pBlobData
, pv
->u
.blob
.cbSize
);
229 TRACE("Blob %p %u\n", pv
->u
.blob
.pBlobData
, pv
->u
.blob
.cbSize
);
235 ret
= RegSetValueExW(regkey
, buffer
, 0, REG_SZ
, (const BYTE
*)pv
->u
.pwszVal
, sizeof(WCHAR
)*(1+lstrlenW(pv
->u
.pwszVal
)));
240 FIXME("Unhandled type %u\n", pv
->vt
);
245 TRACE("Writing %s returned %u\n", debugstr_w(buffer
), ret
);
249 static HRESULT
set_driver_prop_value(GUID
*id
, const EDataFlow flow
, const PROPERTYKEY
*prop
)
254 if (!drvs
.pGetPropValue
)
257 hr
= drvs
.pGetPropValue(id
, prop
, &pv
);
261 MMDevice_SetPropValue(id
, flow
, prop
, &pv
);
262 PropVariantClear(&pv
);
268 /* Creates or updates the state of a device
269 * If GUID is null, a random guid will be assigned
270 * and the device will be created
272 static MMDevice
*MMDevice_Create(WCHAR
*name
, GUID
*id
, EDataFlow flow
, DWORD state
, BOOL setdefault
)
275 MMDevice
*cur
= NULL
;
279 static const PROPERTYKEY deviceinterface_key
= {
280 {0x233164c8, 0x1b2c, 0x4c7d, {0xbc, 0x68, 0xb6, 0x71, 0x68, 0x7a, 0x25, 0x67}}, 1
283 static const PROPERTYKEY devicepath_key
= {
284 {0xb3f8fa53, 0x0004, 0x438e, {0x90, 0x03, 0x51, 0xa4, 0x6e, 0x13, 0x9b, 0xfc}}, 2
287 for (i
= 0; i
< MMDevice_count
; ++i
)
289 MMDevice
*device
= MMDevice_head
[i
];
290 if (device
->flow
== flow
&& IsEqualGUID(&device
->devguid
, id
)){
297 /* No device found, allocate new one */
298 cur
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*cur
));
302 cur
->IMMDevice_iface
.lpVtbl
= &MMDeviceVtbl
;
303 cur
->IMMEndpoint_iface
.lpVtbl
= &MMEndpointVtbl
;
305 InitializeCriticalSection(&cur
->crst
);
306 cur
->crst
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": MMDevice.crst");
309 MMDevice_head
= HeapAlloc(GetProcessHeap(), 0, sizeof(*MMDevice_head
));
311 MMDevice_head
= HeapReAlloc(GetProcessHeap(), 0, MMDevice_head
, sizeof(*MMDevice_head
)*(1+MMDevice_count
));
312 MMDevice_head
[MMDevice_count
++] = cur
;
313 }else if(cur
->ref
> 0)
314 WARN("Modifying an MMDevice with postitive reference count!\n");
316 HeapFree(GetProcessHeap(), 0, cur
->drv_id
);
323 StringFromGUID2(&cur
->devguid
, guidstr
, sizeof(guidstr
)/sizeof(*guidstr
));
330 if (RegCreateKeyExW(root
, guidstr
, 0, NULL
, 0, KEY_WRITE
|KEY_READ
|KEY_WOW64_64KEY
, NULL
, &key
, NULL
) == ERROR_SUCCESS
)
333 RegSetValueExW(key
, reg_devicestate
, 0, REG_DWORD
, (const BYTE
*)&state
, sizeof(DWORD
));
334 if (!RegCreateKeyExW(key
, reg_properties
, 0, NULL
, 0, KEY_WRITE
|KEY_READ
|KEY_WOW64_64KEY
, NULL
, &keyprop
, NULL
))
340 MMDevice_SetPropValue(id
, flow
, (const PROPERTYKEY
*)&DEVPKEY_Device_FriendlyName
, &pv
);
341 MMDevice_SetPropValue(id
, flow
, (const PROPERTYKEY
*)&DEVPKEY_DeviceInterface_FriendlyName
, &pv
);
342 MMDevice_SetPropValue(id
, flow
, (const PROPERTYKEY
*)&DEVPKEY_Device_DeviceDesc
, &pv
);
344 pv
.u
.pwszVal
= guidstr
;
345 MMDevice_SetPropValue(id
, flow
, &deviceinterface_key
, &pv
);
347 set_driver_prop_value(id
, flow
, &devicepath_key
);
349 if (FAILED(set_driver_prop_value(id
, flow
, &PKEY_AudioEndpoint_FormFactor
)))
352 pv
.u
.ulVal
= (flow
== eCapture
) ? Microphone
: Speakers
;
354 MMDevice_SetPropValue(id
, flow
, &PKEY_AudioEndpoint_FormFactor
, &pv
);
357 if (flow
!= eCapture
)
361 PropVariantInit(&pv2
);
363 /* make read-write by not overwriting if already set */
364 if (FAILED(MMDevice_GetPropValue(id
, flow
, &PKEY_AudioEndpoint_PhysicalSpeakers
, &pv2
)) || pv2
.vt
!= VT_UI4
)
365 set_driver_prop_value(id
, flow
, &PKEY_AudioEndpoint_PhysicalSpeakers
);
367 PropVariantClear(&pv2
);
370 RegCloseKey(keyprop
);
378 MMDevice_def_play
= cur
;
380 MMDevice_def_rec
= cur
;
385 static HRESULT
load_devices_from_reg(void)
392 ret
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, software_mmdevapi
, 0, NULL
, 0, KEY_WRITE
|KEY_READ
|KEY_WOW64_64KEY
, NULL
, &root
, NULL
);
393 if (ret
== ERROR_SUCCESS
)
394 ret
= RegCreateKeyExW(root
, reg_capture
, 0, NULL
, 0, KEY_READ
|KEY_WRITE
|KEY_WOW64_64KEY
, NULL
, &key_capture
, NULL
);
395 if (ret
== ERROR_SUCCESS
)
396 ret
= RegCreateKeyExW(root
, reg_render
, 0, NULL
, 0, KEY_READ
|KEY_WRITE
|KEY_WOW64_64KEY
, NULL
, &key_render
, NULL
);
400 if (ret
!= ERROR_SUCCESS
)
402 RegCloseKey(key_capture
);
403 key_render
= key_capture
= NULL
;
404 WARN("Couldn't create key: %u\n", ret
);
412 PROPVARIANT pv
= { VT_EMPTY
};
414 len
= sizeof(guidvalue
)/sizeof(guidvalue
[0]);
415 ret
= RegEnumKeyExW(cur
, i
++, guidvalue
, &len
, NULL
, NULL
, NULL
, NULL
);
416 if (ret
== ERROR_NO_MORE_ITEMS
)
418 if (cur
== key_capture
)
427 if (ret
!= ERROR_SUCCESS
)
429 if (SUCCEEDED(CLSIDFromString(guidvalue
, &guid
))
430 && SUCCEEDED(MMDevice_GetPropValue(&guid
, curflow
, (const PROPERTYKEY
*)&DEVPKEY_Device_FriendlyName
, &pv
))
431 && pv
.vt
== VT_LPWSTR
)
433 DWORD size_bytes
= (strlenW(pv
.u
.pwszVal
) + 1) * sizeof(WCHAR
);
434 WCHAR
*name
= HeapAlloc(GetProcessHeap(), 0, size_bytes
);
435 memcpy(name
, pv
.u
.pwszVal
, size_bytes
);
436 MMDevice_Create(name
, &guid
, curflow
,
437 DEVICE_STATE_NOTPRESENT
, FALSE
);
438 CoTaskMemFree(pv
.u
.pwszVal
);
445 static HRESULT
set_format(MMDevice
*dev
)
448 IAudioClient
*client
;
450 PROPVARIANT pv
= { VT_EMPTY
};
452 hr
= drvs
.pGetAudioEndpoint(&dev
->devguid
, &dev
->IMMDevice_iface
, &client
);
456 hr
= IAudioClient_GetMixFormat(client
, &fmt
);
458 IAudioClient_Release(client
);
462 IAudioClient_Release(client
);
465 pv
.u
.blob
.cbSize
= sizeof(WAVEFORMATEX
) + fmt
->cbSize
;
466 pv
.u
.blob
.pBlobData
= (BYTE
*)fmt
;
467 MMDevice_SetPropValue(&dev
->devguid
, dev
->flow
,
468 &PKEY_AudioEngine_DeviceFormat
, &pv
);
469 MMDevice_SetPropValue(&dev
->devguid
, dev
->flow
,
470 &PKEY_AudioEngine_OEMFormat
, &pv
);
476 static HRESULT
load_driver_devices(EDataFlow flow
)
483 if(!drvs
.pGetEndpointIDs
)
486 hr
= drvs
.pGetEndpointIDs(flow
, &ids
, &guids
, &num
, &def
);
490 for(i
= 0; i
< num
; ++i
){
492 dev
= MMDevice_Create(ids
[i
], &guids
[i
], flow
, DEVICE_STATE_ACTIVE
,
497 HeapFree(GetProcessHeap(), 0, guids
);
498 HeapFree(GetProcessHeap(), 0, ids
);
503 static void MMDevice_Destroy(MMDevice
*This
)
506 TRACE("Freeing %s\n", debugstr_w(This
->drv_id
));
507 /* Since this function is called at destruction time, reordering of the list is unimportant */
508 for (i
= 0; i
< MMDevice_count
; ++i
)
510 if (MMDevice_head
[i
] == This
)
512 MMDevice_head
[i
] = MMDevice_head
[--MMDevice_count
];
516 This
->crst
.DebugInfo
->Spare
[0] = 0;
517 DeleteCriticalSection(&This
->crst
);
518 HeapFree(GetProcessHeap(), 0, This
->drv_id
);
519 HeapFree(GetProcessHeap(), 0, This
);
522 static inline MMDevice
*impl_from_IMMDevice(IMMDevice
*iface
)
524 return CONTAINING_RECORD(iface
, MMDevice
, IMMDevice_iface
);
527 static HRESULT WINAPI
MMDevice_QueryInterface(IMMDevice
*iface
, REFIID riid
, void **ppv
)
529 MMDevice
*This
= impl_from_IMMDevice(iface
);
530 TRACE("(%p)->(%s,%p)\n", iface
, debugstr_guid(riid
), ppv
);
535 if (IsEqualIID(riid
, &IID_IUnknown
)
536 || IsEqualIID(riid
, &IID_IMMDevice
))
537 *ppv
= &This
->IMMDevice_iface
;
538 else if (IsEqualIID(riid
, &IID_IMMEndpoint
))
539 *ppv
= &This
->IMMEndpoint_iface
;
542 IUnknown_AddRef((IUnknown
*)*ppv
);
545 WARN("Unknown interface %s\n", debugstr_guid(riid
));
546 return E_NOINTERFACE
;
549 static ULONG WINAPI
MMDevice_AddRef(IMMDevice
*iface
)
551 MMDevice
*This
= impl_from_IMMDevice(iface
);
554 ref
= InterlockedIncrement(&This
->ref
);
555 TRACE("Refcount now %i\n", ref
);
559 static ULONG WINAPI
MMDevice_Release(IMMDevice
*iface
)
561 MMDevice
*This
= impl_from_IMMDevice(iface
);
564 ref
= InterlockedDecrement(&This
->ref
);
565 TRACE("Refcount now %i\n", ref
);
569 static HRESULT WINAPI
MMDevice_Activate(IMMDevice
*iface
, REFIID riid
, DWORD clsctx
, PROPVARIANT
*params
, void **ppv
)
571 HRESULT hr
= E_NOINTERFACE
;
572 MMDevice
*This
= impl_from_IMMDevice(iface
);
574 TRACE("(%p)->(%s, %x, %p, %p)\n", iface
, debugstr_guid(riid
), clsctx
, params
, ppv
);
579 if (IsEqualIID(riid
, &IID_IAudioClient
)){
580 hr
= drvs
.pGetAudioEndpoint(&This
->devguid
, iface
, (IAudioClient
**)ppv
);
581 }else if (IsEqualIID(riid
, &IID_IAudioEndpointVolume
) ||
582 IsEqualIID(riid
, &IID_IAudioEndpointVolumeEx
))
583 hr
= AudioEndpointVolume_Create(This
, (IAudioEndpointVolumeEx
**)ppv
);
584 else if (IsEqualIID(riid
, &IID_IAudioSessionManager
)
585 || IsEqualIID(riid
, &IID_IAudioSessionManager2
))
587 hr
= drvs
.pGetAudioSessionManager(iface
, (IAudioSessionManager2
**)ppv
);
589 else if (IsEqualIID(riid
, &IID_IBaseFilter
))
591 if (This
->flow
== eRender
)
592 hr
= CoCreateInstance(&CLSID_DSoundRender
, NULL
, clsctx
, riid
, ppv
);
594 ERR("Not supported for recording?\n");
597 IPersistPropertyBag
*ppb
;
598 hr
= IUnknown_QueryInterface((IUnknown
*)*ppv
, &IID_IPersistPropertyBag
, (void*)&ppb
);
601 /* ::Load cannot assume the interface stays alive after the function returns,
602 * so just create the interface on the stack, saves a lot of complicated code */
603 IPropertyBagImpl bag
= { { &PB_Vtbl
} };
604 bag
.devguid
= This
->devguid
;
605 hr
= IPersistPropertyBag_Load(ppb
, &bag
.IPropertyBag_iface
, NULL
);
606 IPersistPropertyBag_Release(ppb
);
608 IBaseFilter_Release((IBaseFilter
*)*ppv
);
612 FIXME("Wine doesn't support IPersistPropertyBag on DSoundRender yet, ignoring..\n");
617 else if (IsEqualIID(riid
, &IID_IDeviceTopology
))
619 FIXME("IID_IDeviceTopology unsupported\n");
621 else if (IsEqualIID(riid
, &IID_IDirectSound
)
622 || IsEqualIID(riid
, &IID_IDirectSound8
))
624 if (This
->flow
== eRender
)
625 hr
= CoCreateInstance(&CLSID_DirectSound8
, NULL
, clsctx
, riid
, ppv
);
628 hr
= IDirectSound_Initialize((IDirectSound
*)*ppv
, &This
->devguid
);
630 IDirectSound_Release((IDirectSound
*)*ppv
);
633 else if (IsEqualIID(riid
, &IID_IDirectSoundCapture
))
635 if (This
->flow
== eCapture
)
636 hr
= CoCreateInstance(&CLSID_DirectSoundCapture8
, NULL
, clsctx
, riid
, ppv
);
639 hr
= IDirectSoundCapture_Initialize((IDirectSoundCapture
*)*ppv
, &This
->devguid
);
641 IDirectSoundCapture_Release((IDirectSoundCapture
*)*ppv
);
645 ERR("Invalid/unknown iid %s\n", debugstr_guid(riid
));
650 TRACE("Returning %08x\n", hr
);
654 static HRESULT WINAPI
MMDevice_OpenPropertyStore(IMMDevice
*iface
, DWORD access
, IPropertyStore
**ppv
)
656 MMDevice
*This
= impl_from_IMMDevice(iface
);
657 TRACE("(%p)->(%x,%p)\n", This
, access
, ppv
);
661 return MMDevPropStore_Create(This
, access
, ppv
);
664 static HRESULT WINAPI
MMDevice_GetId(IMMDevice
*iface
, WCHAR
**itemid
)
666 MMDevice
*This
= impl_from_IMMDevice(iface
);
668 GUID
*id
= &This
->devguid
;
669 static const WCHAR formatW
[] = { '{','0','.','0','.','%','u','.','0','0','0','0','0','0','0','0','}','.',
670 '{','%','0','8','X','-','%','0','4','X','-',
671 '%','0','4','X','-','%','0','2','X','%','0','2','X','-',
672 '%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X',
673 '%','0','2','X','%','0','2','X','}',0 };
675 TRACE("(%p)->(%p)\n", This
, itemid
);
678 *itemid
= str
= CoTaskMemAlloc(56 * sizeof(WCHAR
));
680 return E_OUTOFMEMORY
;
681 wsprintfW( str
, formatW
, This
->flow
, id
->Data1
, id
->Data2
, id
->Data3
,
682 id
->Data4
[0], id
->Data4
[1], id
->Data4
[2], id
->Data4
[3],
683 id
->Data4
[4], id
->Data4
[5], id
->Data4
[6], id
->Data4
[7] );
684 TRACE("returning %s\n", wine_dbgstr_w(str
));
688 static HRESULT WINAPI
MMDevice_GetState(IMMDevice
*iface
, DWORD
*state
)
690 MMDevice
*This
= impl_from_IMMDevice(iface
);
691 TRACE("(%p)->(%p)\n", iface
, state
);
695 *state
= This
->state
;
699 static const IMMDeviceVtbl MMDeviceVtbl
=
701 MMDevice_QueryInterface
,
705 MMDevice_OpenPropertyStore
,
710 static inline MMDevice
*impl_from_IMMEndpoint(IMMEndpoint
*iface
)
712 return CONTAINING_RECORD(iface
, MMDevice
, IMMEndpoint_iface
);
715 static HRESULT WINAPI
MMEndpoint_QueryInterface(IMMEndpoint
*iface
, REFIID riid
, void **ppv
)
717 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
718 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
719 return IMMDevice_QueryInterface(&This
->IMMDevice_iface
, riid
, ppv
);
722 static ULONG WINAPI
MMEndpoint_AddRef(IMMEndpoint
*iface
)
724 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
725 TRACE("(%p)\n", This
);
726 return IMMDevice_AddRef(&This
->IMMDevice_iface
);
729 static ULONG WINAPI
MMEndpoint_Release(IMMEndpoint
*iface
)
731 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
732 TRACE("(%p)\n", This
);
733 return IMMDevice_Release(&This
->IMMDevice_iface
);
736 static HRESULT WINAPI
MMEndpoint_GetDataFlow(IMMEndpoint
*iface
, EDataFlow
*flow
)
738 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
739 TRACE("(%p)->(%p)\n", This
, flow
);
746 static const IMMEndpointVtbl MMEndpointVtbl
=
748 MMEndpoint_QueryInterface
,
751 MMEndpoint_GetDataFlow
754 static HRESULT
MMDevCol_Create(IMMDeviceCollection
**ppv
, EDataFlow flow
, DWORD state
)
758 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
761 return E_OUTOFMEMORY
;
762 This
->IMMDeviceCollection_iface
.lpVtbl
= &MMDevColVtbl
;
766 *ppv
= &This
->IMMDeviceCollection_iface
;
770 static void MMDevCol_Destroy(MMDevColImpl
*This
)
772 HeapFree(GetProcessHeap(), 0, This
);
775 static HRESULT WINAPI
MMDevCol_QueryInterface(IMMDeviceCollection
*iface
, REFIID riid
, void **ppv
)
777 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
778 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
782 if (IsEqualIID(riid
, &IID_IUnknown
)
783 || IsEqualIID(riid
, &IID_IMMDeviceCollection
))
784 *ppv
= &This
->IMMDeviceCollection_iface
;
788 return E_NOINTERFACE
;
789 IUnknown_AddRef((IUnknown
*)*ppv
);
793 static ULONG WINAPI
MMDevCol_AddRef(IMMDeviceCollection
*iface
)
795 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
796 LONG ref
= InterlockedIncrement(&This
->ref
);
797 TRACE("Refcount now %i\n", ref
);
801 static ULONG WINAPI
MMDevCol_Release(IMMDeviceCollection
*iface
)
803 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
804 LONG ref
= InterlockedDecrement(&This
->ref
);
805 TRACE("Refcount now %i\n", ref
);
807 MMDevCol_Destroy(This
);
811 static HRESULT WINAPI
MMDevCol_GetCount(IMMDeviceCollection
*iface
, UINT
*numdevs
)
813 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
816 TRACE("(%p)->(%p)\n", This
, numdevs
);
821 for (i
= 0; i
< MMDevice_count
; ++i
)
823 MMDevice
*cur
= MMDevice_head
[i
];
824 if ((cur
->flow
== This
->flow
|| This
->flow
== eAll
)
825 && (cur
->state
& This
->state
))
831 static HRESULT WINAPI
MMDevCol_Item(IMMDeviceCollection
*iface
, UINT n
, IMMDevice
**dev
)
833 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
836 TRACE("(%p)->(%u, %p)\n", This
, n
, dev
);
840 for (j
= 0; j
< MMDevice_count
; ++j
)
842 MMDevice
*cur
= MMDevice_head
[j
];
843 if ((cur
->flow
== This
->flow
|| This
->flow
== eAll
)
844 && (cur
->state
& This
->state
)
847 *dev
= &cur
->IMMDevice_iface
;
848 IMMDevice_AddRef(*dev
);
852 WARN("Could not obtain item %u\n", n
);
857 static const IMMDeviceCollectionVtbl MMDevColVtbl
=
859 MMDevCol_QueryInterface
,
866 HRESULT
MMDevEnum_Create(REFIID riid
, void **ppv
)
868 MMDevEnumImpl
*This
= MMDevEnumerator
;
872 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
875 return E_OUTOFMEMORY
;
877 This
->IMMDeviceEnumerator_iface
.lpVtbl
= &MMDevEnumVtbl
;
878 MMDevEnumerator
= This
;
880 load_devices_from_reg();
881 load_driver_devices(eRender
);
882 load_driver_devices(eCapture
);
884 return IMMDeviceEnumerator_QueryInterface(&This
->IMMDeviceEnumerator_iface
, riid
, ppv
);
887 void MMDevEnum_Free(void)
889 while (MMDevice_count
)
890 MMDevice_Destroy(MMDevice_head
[0]);
891 RegCloseKey(key_render
);
892 RegCloseKey(key_capture
);
893 key_render
= key_capture
= NULL
;
894 HeapFree(GetProcessHeap(), 0, MMDevEnumerator
);
895 MMDevEnumerator
= NULL
;
898 static HRESULT WINAPI
MMDevEnum_QueryInterface(IMMDeviceEnumerator
*iface
, REFIID riid
, void **ppv
)
900 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
901 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
905 if (IsEqualIID(riid
, &IID_IUnknown
)
906 || IsEqualIID(riid
, &IID_IMMDeviceEnumerator
))
907 *ppv
= &This
->IMMDeviceEnumerator_iface
;
911 return E_NOINTERFACE
;
912 IUnknown_AddRef((IUnknown
*)*ppv
);
916 static ULONG WINAPI
MMDevEnum_AddRef(IMMDeviceEnumerator
*iface
)
918 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
919 LONG ref
= InterlockedIncrement(&This
->ref
);
920 TRACE("Refcount now %i\n", ref
);
924 static ULONG WINAPI
MMDevEnum_Release(IMMDeviceEnumerator
*iface
)
926 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
927 LONG ref
= InterlockedDecrement(&This
->ref
);
930 TRACE("Refcount now %i\n", ref
);
934 static HRESULT WINAPI
MMDevEnum_EnumAudioEndpoints(IMMDeviceEnumerator
*iface
, EDataFlow flow
, DWORD mask
, IMMDeviceCollection
**devices
)
936 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
937 TRACE("(%p)->(%u,%u,%p)\n", This
, flow
, mask
, devices
);
941 if (flow
>= EDataFlow_enum_count
)
943 if (mask
& ~DEVICE_STATEMASK_ALL
)
945 return MMDevCol_Create(devices
, flow
, mask
);
948 static HRESULT WINAPI
MMDevEnum_GetDefaultAudioEndpoint(IMMDeviceEnumerator
*iface
, EDataFlow flow
, ERole role
, IMMDevice
**device
)
950 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
955 TRACE("(%p)->(%u,%u,%p)\n", This
, flow
, role
, device
);
960 if((flow
!= eRender
&& flow
!= eCapture
) ||
961 (role
!= eConsole
&& role
!= eMultimedia
&& role
!= eCommunications
)){
962 WARN("Unknown flow (%u) or role (%u)\n", flow
, role
);
968 if(!drvs
.module_name
[0])
971 lstrcpyW(reg_key
, drv_keyW
);
972 lstrcatW(reg_key
, slashW
);
973 lstrcatW(reg_key
, drvs
.module_name
);
975 if(RegOpenKeyW(HKEY_CURRENT_USER
, reg_key
, &key
) == ERROR_SUCCESS
){
976 const WCHAR
*reg_x_name
, *reg_vx_name
;
978 DWORD size
= sizeof(def_id
), state
;
981 reg_x_name
= reg_out_nameW
;
982 reg_vx_name
= reg_vout_nameW
;
984 reg_x_name
= reg_in_nameW
;
985 reg_vx_name
= reg_vin_nameW
;
988 if(role
== eCommunications
&&
989 RegQueryValueExW(key
, reg_vx_name
, 0, NULL
,
990 (BYTE
*)def_id
, &size
) == ERROR_SUCCESS
){
991 hr
= IMMDeviceEnumerator_GetDevice(iface
, def_id
, device
);
993 if(SUCCEEDED(IMMDevice_GetState(*device
, &state
)) &&
994 state
== DEVICE_STATE_ACTIVE
){
1000 TRACE("Unable to find voice device %s\n", wine_dbgstr_w(def_id
));
1003 if(RegQueryValueExW(key
, reg_x_name
, 0, NULL
,
1004 (BYTE
*)def_id
, &size
) == ERROR_SUCCESS
){
1005 hr
= IMMDeviceEnumerator_GetDevice(iface
, def_id
, device
);
1007 if(SUCCEEDED(IMMDevice_GetState(*device
, &state
)) &&
1008 state
== DEVICE_STATE_ACTIVE
){
1014 TRACE("Unable to find device %s\n", wine_dbgstr_w(def_id
));
1020 if (flow
== eRender
)
1021 *device
= &MMDevice_def_play
->IMMDevice_iface
;
1023 *device
= &MMDevice_def_rec
->IMMDevice_iface
;
1027 IMMDevice_AddRef(*device
);
1031 static HRESULT WINAPI
MMDevEnum_GetDevice(IMMDeviceEnumerator
*iface
, const WCHAR
*name
, IMMDevice
**device
)
1033 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
1035 IMMDevice
*dev
= NULL
;
1037 static const WCHAR wine_info_deviceW
[] = {'W','i','n','e',' ',
1038 'i','n','f','o',' ','d','e','v','i','c','e',0};
1040 TRACE("(%p)->(%s,%p)\n", This
, debugstr_w(name
), device
);
1042 if(!name
|| !device
)
1045 if(!lstrcmpW(name
, wine_info_deviceW
)){
1046 *device
= &info_device
;
1050 for (i
= 0; i
< MMDevice_count
; ++i
)
1054 dev
= &MMDevice_head
[i
]->IMMDevice_iface
;
1055 hr
= IMMDevice_GetId(dev
, &str
);
1058 WARN("GetId failed: %08x\n", hr
);
1062 if (str
&& !lstrcmpW(str
, name
))
1065 IMMDevice_AddRef(dev
);
1071 TRACE("Could not find device %s\n", debugstr_w(name
));
1072 return E_INVALIDARG
;
1075 struct NotificationClientWrapper
{
1076 IMMNotificationClient
*client
;
1080 static struct list g_notif_clients
= LIST_INIT(g_notif_clients
);
1081 static HANDLE g_notif_thread
;
1083 static CRITICAL_SECTION g_notif_lock
;
1084 static CRITICAL_SECTION_DEBUG g_notif_lock_debug
=
1086 0, 0, &g_notif_lock
,
1087 { &g_notif_lock_debug
.ProcessLocksList
, &g_notif_lock_debug
.ProcessLocksList
},
1088 0, 0, { (DWORD_PTR
)(__FILE__
": g_notif_lock") }
1090 static CRITICAL_SECTION g_notif_lock
= { &g_notif_lock_debug
, -1, 0, 0, 0, 0 };
1092 static void notify_clients(EDataFlow flow
, ERole role
, const WCHAR
*id
)
1094 struct NotificationClientWrapper
*wrapper
;
1095 LIST_FOR_EACH_ENTRY(wrapper
, &g_notif_clients
,
1096 struct NotificationClientWrapper
, entry
)
1097 IMMNotificationClient_OnDefaultDeviceChanged(wrapper
->client
, flow
,
1100 /* Windows 7 treats changes to eConsole as changes to eMultimedia */
1101 if(role
== eConsole
)
1102 notify_clients(flow
, eMultimedia
, id
);
1105 static BOOL
notify_if_changed(EDataFlow flow
, ERole role
, HKEY key
,
1106 const WCHAR
*val_name
, WCHAR
*old_val
, IMMDevice
*def_dev
)
1108 WCHAR new_val
[64], *id
;
1112 size
= sizeof(new_val
);
1113 if(RegQueryValueExW(key
, val_name
, 0, NULL
,
1114 (BYTE
*)new_val
, &size
) != ERROR_SUCCESS
){
1115 if(old_val
[0] != 0){
1116 /* set by user -> system default */
1118 hr
= IMMDevice_GetId(def_dev
, &id
);
1120 ERR("GetId failed: %08x\n", hr
);
1126 notify_clients(flow
, role
, id
);
1133 /* system default -> system default, noop */
1137 if(!lstrcmpW(old_val
, new_val
)){
1138 /* set by user -> same value */
1142 if(new_val
[0] != 0){
1143 /* set by user -> different value */
1144 notify_clients(flow
, role
, new_val
);
1145 memcpy(old_val
, new_val
, sizeof(new_val
));
1149 /* set by user -> system default */
1151 hr
= IMMDevice_GetId(def_dev
, &id
);
1153 ERR("GetId failed: %08x\n", hr
);
1159 notify_clients(flow
, role
, id
);
1166 static DWORD WINAPI
notif_thread_proc(void *user
)
1170 WCHAR out_name
[64], vout_name
[64], in_name
[64], vin_name
[64];
1173 lstrcpyW(reg_key
, drv_keyW
);
1174 lstrcatW(reg_key
, slashW
);
1175 lstrcatW(reg_key
, drvs
.module_name
);
1177 if(RegCreateKeyExW(HKEY_CURRENT_USER
, reg_key
, 0, NULL
, 0,
1178 MAXIMUM_ALLOWED
, NULL
, &key
, NULL
) != ERROR_SUCCESS
){
1179 ERR("RegCreateKeyEx failed: %u\n", GetLastError());
1183 size
= sizeof(out_name
);
1184 if(RegQueryValueExW(key
, reg_out_nameW
, 0, NULL
,
1185 (BYTE
*)out_name
, &size
) != ERROR_SUCCESS
)
1188 size
= sizeof(vout_name
);
1189 if(RegQueryValueExW(key
, reg_vout_nameW
, 0, NULL
,
1190 (BYTE
*)vout_name
, &size
) != ERROR_SUCCESS
)
1193 size
= sizeof(in_name
);
1194 if(RegQueryValueExW(key
, reg_in_nameW
, 0, NULL
,
1195 (BYTE
*)in_name
, &size
) != ERROR_SUCCESS
)
1198 size
= sizeof(vin_name
);
1199 if(RegQueryValueExW(key
, reg_vin_nameW
, 0, NULL
,
1200 (BYTE
*)vin_name
, &size
) != ERROR_SUCCESS
)
1204 if(RegNotifyChangeKeyValue(key
, FALSE
, REG_NOTIFY_CHANGE_LAST_SET
,
1205 NULL
, FALSE
) != ERROR_SUCCESS
){
1206 ERR("RegNotifyChangeKeyValue failed: %u\n", GetLastError());
1208 g_notif_thread
= NULL
;
1212 EnterCriticalSection(&g_notif_lock
);
1214 notify_if_changed(eRender
, eConsole
, key
, reg_out_nameW
,
1215 out_name
, &MMDevice_def_play
->IMMDevice_iface
);
1216 notify_if_changed(eRender
, eCommunications
, key
, reg_vout_nameW
,
1217 vout_name
, &MMDevice_def_play
->IMMDevice_iface
);
1218 notify_if_changed(eCapture
, eConsole
, key
, reg_in_nameW
,
1219 in_name
, &MMDevice_def_rec
->IMMDevice_iface
);
1220 notify_if_changed(eCapture
, eCommunications
, key
, reg_vin_nameW
,
1221 vin_name
, &MMDevice_def_rec
->IMMDevice_iface
);
1223 LeaveCriticalSection(&g_notif_lock
);
1228 g_notif_thread
= NULL
;
1233 static HRESULT WINAPI
MMDevEnum_RegisterEndpointNotificationCallback(IMMDeviceEnumerator
*iface
, IMMNotificationClient
*client
)
1235 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
1236 struct NotificationClientWrapper
*wrapper
;
1238 TRACE("(%p)->(%p)\n", This
, client
);
1243 wrapper
= HeapAlloc(GetProcessHeap(), 0, sizeof(*wrapper
));
1245 return E_OUTOFMEMORY
;
1247 wrapper
->client
= client
;
1249 EnterCriticalSection(&g_notif_lock
);
1251 list_add_tail(&g_notif_clients
, &wrapper
->entry
);
1253 if(!g_notif_thread
){
1254 g_notif_thread
= CreateThread(NULL
, 0, notif_thread_proc
, NULL
, 0, NULL
);
1256 ERR("CreateThread failed: %u\n", GetLastError());
1259 LeaveCriticalSection(&g_notif_lock
);
1264 static HRESULT WINAPI
MMDevEnum_UnregisterEndpointNotificationCallback(IMMDeviceEnumerator
*iface
, IMMNotificationClient
*client
)
1266 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
1267 struct NotificationClientWrapper
*wrapper
;
1269 TRACE("(%p)->(%p)\n", This
, client
);
1274 EnterCriticalSection(&g_notif_lock
);
1276 LIST_FOR_EACH_ENTRY(wrapper
, &g_notif_clients
, struct NotificationClientWrapper
, entry
){
1277 if(wrapper
->client
== client
){
1278 list_remove(&wrapper
->entry
);
1279 HeapFree(GetProcessHeap(), 0, wrapper
);
1280 LeaveCriticalSection(&g_notif_lock
);
1285 LeaveCriticalSection(&g_notif_lock
);
1290 static const IMMDeviceEnumeratorVtbl MMDevEnumVtbl
=
1292 MMDevEnum_QueryInterface
,
1295 MMDevEnum_EnumAudioEndpoints
,
1296 MMDevEnum_GetDefaultAudioEndpoint
,
1297 MMDevEnum_GetDevice
,
1298 MMDevEnum_RegisterEndpointNotificationCallback
,
1299 MMDevEnum_UnregisterEndpointNotificationCallback
1302 static HRESULT
MMDevPropStore_Create(MMDevice
*parent
, DWORD access
, IPropertyStore
**ppv
)
1304 MMDevPropStore
*This
;
1305 if (access
!= STGM_READ
1306 && access
!= STGM_WRITE
1307 && access
!= STGM_READWRITE
)
1309 WARN("Invalid access %08x\n", access
);
1310 return E_INVALIDARG
;
1312 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
1313 *ppv
= &This
->IPropertyStore_iface
;
1315 return E_OUTOFMEMORY
;
1316 This
->IPropertyStore_iface
.lpVtbl
= &MMDevPropVtbl
;
1318 This
->parent
= parent
;
1319 This
->access
= access
;
1323 static void MMDevPropStore_Destroy(MMDevPropStore
*This
)
1325 HeapFree(GetProcessHeap(), 0, This
);
1328 static HRESULT WINAPI
MMDevPropStore_QueryInterface(IPropertyStore
*iface
, REFIID riid
, void **ppv
)
1330 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1331 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
1335 if (IsEqualIID(riid
, &IID_IUnknown
)
1336 || IsEqualIID(riid
, &IID_IPropertyStore
))
1337 *ppv
= &This
->IPropertyStore_iface
;
1341 return E_NOINTERFACE
;
1342 IUnknown_AddRef((IUnknown
*)*ppv
);
1346 static ULONG WINAPI
MMDevPropStore_AddRef(IPropertyStore
*iface
)
1348 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1349 LONG ref
= InterlockedIncrement(&This
->ref
);
1350 TRACE("Refcount now %i\n", ref
);
1354 static ULONG WINAPI
MMDevPropStore_Release(IPropertyStore
*iface
)
1356 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1357 LONG ref
= InterlockedDecrement(&This
->ref
);
1358 TRACE("Refcount now %i\n", ref
);
1360 MMDevPropStore_Destroy(This
);
1364 static HRESULT WINAPI
MMDevPropStore_GetCount(IPropertyStore
*iface
, DWORD
*nprops
)
1366 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1372 TRACE("(%p)->(%p)\n", iface
, nprops
);
1375 hr
= MMDevPropStore_OpenPropKey(&This
->parent
->devguid
, This
->parent
->flow
, &propkey
);
1380 DWORD len
= sizeof(buffer
)/sizeof(*buffer
);
1381 if (RegEnumValueW(propkey
, i
, buffer
, &len
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
)
1385 RegCloseKey(propkey
);
1386 TRACE("Returning %i\n", i
);
1391 static HRESULT WINAPI
MMDevPropStore_GetAt(IPropertyStore
*iface
, DWORD prop
, PROPERTYKEY
*key
)
1393 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1395 DWORD len
= sizeof(buffer
)/sizeof(*buffer
);
1399 TRACE("(%p)->(%u,%p)\n", iface
, prop
, key
);
1403 hr
= MMDevPropStore_OpenPropKey(&This
->parent
->devguid
, This
->parent
->flow
, &propkey
);
1407 if (RegEnumValueW(propkey
, prop
, buffer
, &len
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
1410 WARN("GetAt %u failed\n", prop
);
1411 return E_INVALIDARG
;
1413 RegCloseKey(propkey
);
1415 CLSIDFromString(buffer
, &key
->fmtid
);
1416 key
->pid
= atoiW(&buffer
[39]);
1420 static HRESULT WINAPI
MMDevPropStore_GetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, PROPVARIANT
*pv
)
1422 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1423 TRACE("(%p)->(\"%s,%u\", %p)\n", This
, key
? debugstr_guid(&key
->fmtid
) : NULL
, key
? key
->pid
: 0, pv
);
1427 if (This
->access
!= STGM_READ
1428 && This
->access
!= STGM_READWRITE
)
1429 return STG_E_ACCESSDENIED
;
1432 if (IsEqualPropertyKey(*key
, PKEY_AudioEndpoint_GUID
))
1435 pv
->u
.pwszVal
= CoTaskMemAlloc(39 * sizeof(WCHAR
));
1437 return E_OUTOFMEMORY
;
1438 StringFromGUID2(&This
->parent
->devguid
, pv
->u
.pwszVal
, 39);
1442 return MMDevice_GetPropValue(&This
->parent
->devguid
, This
->parent
->flow
, key
, pv
);
1445 static HRESULT WINAPI
MMDevPropStore_SetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, REFPROPVARIANT pv
)
1447 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1448 TRACE("(%p)->(\"%s,%u\", %p)\n", This
, key
? debugstr_guid(&key
->fmtid
) : NULL
, key
? key
->pid
: 0, pv
);
1453 if (This
->access
!= STGM_WRITE
1454 && This
->access
!= STGM_READWRITE
)
1455 return STG_E_ACCESSDENIED
;
1456 return MMDevice_SetPropValue(&This
->parent
->devguid
, This
->parent
->flow
, key
, pv
);
1459 static HRESULT WINAPI
MMDevPropStore_Commit(IPropertyStore
*iface
)
1461 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1462 TRACE("(%p)\n", iface
);
1464 if (This
->access
!= STGM_WRITE
1465 && This
->access
!= STGM_READWRITE
)
1466 return STG_E_ACCESSDENIED
;
1468 /* Does nothing - for mmdevapi, the propstore values are written on SetValue,
1474 static const IPropertyStoreVtbl MMDevPropVtbl
=
1476 MMDevPropStore_QueryInterface
,
1477 MMDevPropStore_AddRef
,
1478 MMDevPropStore_Release
,
1479 MMDevPropStore_GetCount
,
1480 MMDevPropStore_GetAt
,
1481 MMDevPropStore_GetValue
,
1482 MMDevPropStore_SetValue
,
1483 MMDevPropStore_Commit
1487 /* Property bag for IBaseFilter activation */
1488 static HRESULT WINAPI
PB_QueryInterface(IPropertyBag
*iface
, REFIID riid
, void **ppv
)
1490 ERR("Should not be called\n");
1492 return E_NOINTERFACE
;
1495 static ULONG WINAPI
PB_AddRef(IPropertyBag
*iface
)
1497 ERR("Should not be called\n");
1501 static ULONG WINAPI
PB_Release(IPropertyBag
*iface
)
1503 ERR("Should not be called\n");
1507 static HRESULT WINAPI
PB_Read(IPropertyBag
*iface
, LPCOLESTR name
, VARIANT
*var
, IErrorLog
*log
)
1509 static const WCHAR dsguid
[] = { 'D','S','G','u','i','d', 0 };
1510 IPropertyBagImpl
*This
= impl_from_IPropertyBag(iface
);
1511 TRACE("Trying to read %s, type %u\n", debugstr_w(name
), var
->n1
.n2
.vt
);
1512 if (!lstrcmpW(name
, dsguid
))
1515 StringFromGUID2(&This
->devguid
, guidstr
,sizeof(guidstr
)/sizeof(*guidstr
));
1516 var
->n1
.n2
.vt
= VT_BSTR
;
1517 var
->n1
.n2
.n3
.bstrVal
= SysAllocString(guidstr
);
1520 ERR("Unknown property '%s' queried\n", debugstr_w(name
));
1524 static HRESULT WINAPI
PB_Write(IPropertyBag
*iface
, LPCOLESTR name
, VARIANT
*var
)
1526 ERR("Should not be called\n");
1530 static const IPropertyBagVtbl PB_Vtbl
=
1539 static ULONG WINAPI
info_device_ps_AddRef(IPropertyStore
*iface
)
1544 static ULONG WINAPI
info_device_ps_Release(IPropertyStore
*iface
)
1549 static HRESULT WINAPI
info_device_ps_GetValue(IPropertyStore
*iface
,
1550 REFPROPERTYKEY key
, PROPVARIANT
*pv
)
1552 TRACE("(static)->(\"%s,%u\", %p)\n", debugstr_guid(&key
->fmtid
), key
? key
->pid
: 0, pv
);
1557 if (IsEqualPropertyKey(*key
, DEVPKEY_Device_Driver
))
1559 INT size
= (lstrlenW(drvs
.module_name
) + 1) * sizeof(WCHAR
);
1561 pv
->u
.pwszVal
= CoTaskMemAlloc(size
);
1563 return E_OUTOFMEMORY
;
1564 memcpy(pv
->u
.pwszVal
, drvs
.module_name
, size
);
1568 return E_INVALIDARG
;
1571 static const IPropertyStoreVtbl info_device_ps_Vtbl
=
1574 info_device_ps_AddRef
,
1575 info_device_ps_Release
,
1578 info_device_ps_GetValue
,
1583 static IPropertyStore info_device_ps
= {
1584 &info_device_ps_Vtbl
1587 static ULONG WINAPI
info_device_AddRef(IMMDevice
*iface
)
1592 static ULONG WINAPI
info_device_Release(IMMDevice
*iface
)
1597 static HRESULT WINAPI
info_device_OpenPropertyStore(IMMDevice
*iface
,
1598 DWORD access
, IPropertyStore
**ppv
)
1600 TRACE("(static)->(%x, %p)\n", access
, ppv
);
1601 *ppv
= &info_device_ps
;
1605 static const IMMDeviceVtbl info_device_Vtbl
=
1609 info_device_Release
,
1611 info_device_OpenPropertyStore
,
1616 static IMMDevice info_device
= {