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
)) != 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
, 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 /* Creates or updates the state of a device
250 * If GUID is null, a random guid will be assigned
251 * and the device will be created
253 static MMDevice
*MMDevice_Create(WCHAR
*name
, GUID
*id
, EDataFlow flow
, DWORD state
, BOOL setdefault
)
256 MMDevice
*cur
= NULL
;
260 static const PROPERTYKEY deviceinterface_key
= {
261 {0x233164c8, 0x1b2c, 0x4c7d, {0xbc, 0x68, 0xb6, 0x71, 0x68, 0x7a, 0x25, 0x67}}, 1
264 for (i
= 0; i
< MMDevice_count
; ++i
)
266 MMDevice
*device
= MMDevice_head
[i
];
267 if (device
->flow
== flow
&& IsEqualGUID(&device
->devguid
, id
)){
274 /* No device found, allocate new one */
275 cur
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*cur
));
279 cur
->IMMDevice_iface
.lpVtbl
= &MMDeviceVtbl
;
280 cur
->IMMEndpoint_iface
.lpVtbl
= &MMEndpointVtbl
;
282 InitializeCriticalSection(&cur
->crst
);
283 cur
->crst
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": MMDevice.crst");
286 MMDevice_head
= HeapAlloc(GetProcessHeap(), 0, sizeof(*MMDevice_head
));
288 MMDevice_head
= HeapReAlloc(GetProcessHeap(), 0, MMDevice_head
, sizeof(*MMDevice_head
)*(1+MMDevice_count
));
289 MMDevice_head
[MMDevice_count
++] = cur
;
290 }else if(cur
->ref
> 0)
291 WARN("Modifying an MMDevice with postitive reference count!\n");
293 HeapFree(GetProcessHeap(), 0, cur
->drv_id
);
300 StringFromGUID2(&cur
->devguid
, guidstr
, sizeof(guidstr
)/sizeof(*guidstr
));
307 if (RegCreateKeyExW(root
, guidstr
, 0, NULL
, 0, KEY_WRITE
|KEY_READ
, NULL
, &key
, NULL
) == ERROR_SUCCESS
)
310 RegSetValueExW(key
, reg_devicestate
, 0, REG_DWORD
, (const BYTE
*)&state
, sizeof(DWORD
));
311 if (!RegCreateKeyExW(key
, reg_properties
, 0, NULL
, 0, KEY_WRITE
|KEY_READ
, NULL
, &keyprop
, NULL
))
317 MMDevice_SetPropValue(id
, flow
, (const PROPERTYKEY
*)&DEVPKEY_Device_FriendlyName
, &pv
);
318 MMDevice_SetPropValue(id
, flow
, (const PROPERTYKEY
*)&DEVPKEY_Device_DeviceDesc
, &pv
);
320 pv
.u
.pwszVal
= guidstr
;
321 MMDevice_SetPropValue(id
, flow
, &deviceinterface_key
, &pv
);
323 RegCloseKey(keyprop
);
331 MMDevice_def_play
= cur
;
333 MMDevice_def_rec
= cur
;
338 static HRESULT
load_devices_from_reg(void)
345 ret
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, software_mmdevapi
, 0, NULL
, 0, KEY_WRITE
|KEY_READ
, NULL
, &root
, NULL
);
346 if (ret
== ERROR_SUCCESS
)
347 ret
= RegCreateKeyExW(root
, reg_capture
, 0, NULL
, 0, KEY_READ
|KEY_WRITE
, NULL
, &key_capture
, NULL
);
348 if (ret
== ERROR_SUCCESS
)
349 ret
= RegCreateKeyExW(root
, reg_render
, 0, NULL
, 0, KEY_READ
|KEY_WRITE
, NULL
, &key_render
, NULL
);
353 if (ret
!= ERROR_SUCCESS
)
355 RegCloseKey(key_capture
);
356 key_render
= key_capture
= NULL
;
357 WARN("Couldn't create key: %u\n", ret
);
365 PROPVARIANT pv
= { VT_EMPTY
};
367 len
= sizeof(guidvalue
)/sizeof(guidvalue
[0]);
368 ret
= RegEnumKeyExW(cur
, i
++, guidvalue
, &len
, NULL
, NULL
, NULL
, NULL
);
369 if (ret
== ERROR_NO_MORE_ITEMS
)
371 if (cur
== key_capture
)
380 if (ret
!= ERROR_SUCCESS
)
382 if (SUCCEEDED(CLSIDFromString(guidvalue
, &guid
))
383 && SUCCEEDED(MMDevice_GetPropValue(&guid
, curflow
, (const PROPERTYKEY
*)&DEVPKEY_Device_FriendlyName
, &pv
))
384 && pv
.vt
== VT_LPWSTR
)
386 DWORD size_bytes
= (strlenW(pv
.u
.pwszVal
) + 1) * sizeof(WCHAR
);
387 WCHAR
*name
= HeapAlloc(GetProcessHeap(), 0, size_bytes
);
388 memcpy(name
, pv
.u
.pwszVal
, size_bytes
);
389 MMDevice_Create(name
, &guid
, curflow
,
390 DEVICE_STATE_NOTPRESENT
, FALSE
);
391 CoTaskMemFree(pv
.u
.pwszVal
);
398 static HRESULT
set_format(MMDevice
*dev
)
401 IAudioClient
*client
;
403 PROPVARIANT pv
= { VT_EMPTY
};
405 hr
= drvs
.pGetAudioEndpoint(&dev
->devguid
, &dev
->IMMDevice_iface
, &client
);
409 hr
= IAudioClient_GetMixFormat(client
, &fmt
);
411 IAudioClient_Release(client
);
415 IAudioClient_Release(client
);
418 pv
.u
.blob
.cbSize
= sizeof(WAVEFORMATEX
) + fmt
->cbSize
;
419 pv
.u
.blob
.pBlobData
= (BYTE
*)fmt
;
420 MMDevice_SetPropValue(&dev
->devguid
, dev
->flow
,
421 &PKEY_AudioEngine_DeviceFormat
, &pv
);
422 MMDevice_SetPropValue(&dev
->devguid
, dev
->flow
,
423 &PKEY_AudioEngine_OEMFormat
, &pv
);
428 static HRESULT
load_driver_devices(EDataFlow flow
)
435 if(!drvs
.pGetEndpointIDs
)
438 hr
= drvs
.pGetEndpointIDs(flow
, &ids
, &guids
, &num
, &def
);
442 for(i
= 0; i
< num
; ++i
){
444 dev
= MMDevice_Create(ids
[i
], &guids
[i
], flow
, DEVICE_STATE_ACTIVE
,
449 HeapFree(GetProcessHeap(), 0, guids
);
450 HeapFree(GetProcessHeap(), 0, ids
);
455 static void MMDevice_Destroy(MMDevice
*This
)
458 TRACE("Freeing %s\n", debugstr_w(This
->drv_id
));
459 /* Since this function is called at destruction time, reordering of the list is unimportant */
460 for (i
= 0; i
< MMDevice_count
; ++i
)
462 if (MMDevice_head
[i
] == This
)
464 MMDevice_head
[i
] = MMDevice_head
[--MMDevice_count
];
468 This
->crst
.DebugInfo
->Spare
[0] = 0;
469 DeleteCriticalSection(&This
->crst
);
470 HeapFree(GetProcessHeap(), 0, This
->drv_id
);
471 HeapFree(GetProcessHeap(), 0, This
);
474 static inline MMDevice
*impl_from_IMMDevice(IMMDevice
*iface
)
476 return CONTAINING_RECORD(iface
, MMDevice
, IMMDevice_iface
);
479 static HRESULT WINAPI
MMDevice_QueryInterface(IMMDevice
*iface
, REFIID riid
, void **ppv
)
481 MMDevice
*This
= impl_from_IMMDevice(iface
);
482 TRACE("(%p)->(%s,%p)\n", iface
, debugstr_guid(riid
), ppv
);
487 if (IsEqualIID(riid
, &IID_IUnknown
)
488 || IsEqualIID(riid
, &IID_IMMDevice
))
490 else if (IsEqualIID(riid
, &IID_IMMEndpoint
))
491 *ppv
= &This
->IMMEndpoint_iface
;
494 IUnknown_AddRef((IUnknown
*)*ppv
);
497 WARN("Unknown interface %s\n", debugstr_guid(riid
));
498 return E_NOINTERFACE
;
501 static ULONG WINAPI
MMDevice_AddRef(IMMDevice
*iface
)
503 MMDevice
*This
= impl_from_IMMDevice(iface
);
506 ref
= InterlockedIncrement(&This
->ref
);
507 TRACE("Refcount now %i\n", ref
);
511 static ULONG WINAPI
MMDevice_Release(IMMDevice
*iface
)
513 MMDevice
*This
= impl_from_IMMDevice(iface
);
516 ref
= InterlockedDecrement(&This
->ref
);
517 TRACE("Refcount now %i\n", ref
);
521 static HRESULT WINAPI
MMDevice_Activate(IMMDevice
*iface
, REFIID riid
, DWORD clsctx
, PROPVARIANT
*params
, void **ppv
)
523 HRESULT hr
= E_NOINTERFACE
;
524 MMDevice
*This
= impl_from_IMMDevice(iface
);
526 TRACE("(%p)->(%p,%x,%p,%p)\n", iface
, riid
, clsctx
, params
, ppv
);
531 if (IsEqualIID(riid
, &IID_IAudioClient
)){
532 hr
= drvs
.pGetAudioEndpoint(&This
->devguid
, iface
, (IAudioClient
**)ppv
);
533 }else if (IsEqualIID(riid
, &IID_IAudioEndpointVolume
))
534 hr
= AudioEndpointVolume_Create(This
, (IAudioEndpointVolume
**)ppv
);
535 else if (IsEqualIID(riid
, &IID_IAudioSessionManager
)
536 || IsEqualIID(riid
, &IID_IAudioSessionManager2
))
538 hr
= drvs
.pGetAudioSessionManager(iface
, (IAudioSessionManager2
**)ppv
);
540 else if (IsEqualIID(riid
, &IID_IBaseFilter
))
542 if (This
->flow
== eRender
)
543 hr
= CoCreateInstance(&CLSID_DSoundRender
, NULL
, clsctx
, riid
, ppv
);
545 ERR("Not supported for recording?\n");
548 IPersistPropertyBag
*ppb
;
549 hr
= IUnknown_QueryInterface((IUnknown
*)*ppv
, &IID_IPersistPropertyBag
, (void*)&ppb
);
552 /* ::Load cannot assume the interface stays alive after the function returns,
553 * so just create the interface on the stack, saves a lot of complicated code */
554 IPropertyBagImpl bag
= { { &PB_Vtbl
} };
555 bag
.devguid
= This
->devguid
;
556 hr
= IPersistPropertyBag_Load(ppb
, &bag
.IPropertyBag_iface
, NULL
);
557 IPersistPropertyBag_Release(ppb
);
559 IBaseFilter_Release((IBaseFilter
*)*ppv
);
563 FIXME("Wine doesn't support IPersistPropertyBag on DSoundRender yet, ignoring..\n");
568 else if (IsEqualIID(riid
, &IID_IDeviceTopology
))
570 FIXME("IID_IDeviceTopology unsupported\n");
572 else if (IsEqualIID(riid
, &IID_IDirectSound
)
573 || IsEqualIID(riid
, &IID_IDirectSound8
))
575 if (This
->flow
== eRender
)
576 hr
= CoCreateInstance(&CLSID_DirectSound8
, NULL
, clsctx
, riid
, ppv
);
579 hr
= IDirectSound_Initialize((IDirectSound
*)*ppv
, &This
->devguid
);
581 IDirectSound_Release((IDirectSound
*)*ppv
);
584 else if (IsEqualIID(riid
, &IID_IDirectSoundCapture
)
585 || IsEqualIID(riid
, &IID_IDirectSoundCapture8
))
587 if (This
->flow
== eCapture
)
588 hr
= CoCreateInstance(&CLSID_DirectSoundCapture8
, NULL
, clsctx
, riid
, ppv
);
591 hr
= IDirectSoundCapture_Initialize((IDirectSoundCapture
*)*ppv
, &This
->devguid
);
593 IDirectSoundCapture_Release((IDirectSoundCapture
*)*ppv
);
597 ERR("Invalid/unknown iid %s\n", debugstr_guid(riid
));
602 TRACE("Returning %08x\n", hr
);
606 static HRESULT WINAPI
MMDevice_OpenPropertyStore(IMMDevice
*iface
, DWORD access
, IPropertyStore
**ppv
)
608 MMDevice
*This
= impl_from_IMMDevice(iface
);
609 TRACE("(%p)->(%x,%p)\n", This
, access
, ppv
);
613 return MMDevPropStore_Create(This
, access
, ppv
);
616 static HRESULT WINAPI
MMDevice_GetId(IMMDevice
*iface
, WCHAR
**itemid
)
618 MMDevice
*This
= impl_from_IMMDevice(iface
);
620 GUID
*id
= &This
->devguid
;
621 static const WCHAR formatW
[] = { '{','0','.','0','.','%','u','.','0','0','0','0','0','0','0','0','}','.',
622 '{','%','0','8','X','-','%','0','4','X','-',
623 '%','0','4','X','-','%','0','2','X','%','0','2','X','-',
624 '%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X',
625 '%','0','2','X','%','0','2','X','}',0 };
627 TRACE("(%p)->(%p)\n", This
, itemid
);
630 *itemid
= str
= CoTaskMemAlloc(56 * sizeof(WCHAR
));
632 return E_OUTOFMEMORY
;
633 wsprintfW( str
, formatW
, This
->flow
, id
->Data1
, id
->Data2
, id
->Data3
,
634 id
->Data4
[0], id
->Data4
[1], id
->Data4
[2], id
->Data4
[3],
635 id
->Data4
[4], id
->Data4
[5], id
->Data4
[6], id
->Data4
[7] );
636 TRACE("returning %s\n", wine_dbgstr_w(str
));
640 static HRESULT WINAPI
MMDevice_GetState(IMMDevice
*iface
, DWORD
*state
)
642 MMDevice
*This
= impl_from_IMMDevice(iface
);
643 TRACE("(%p)->(%p)\n", iface
, state
);
647 *state
= This
->state
;
651 static const IMMDeviceVtbl MMDeviceVtbl
=
653 MMDevice_QueryInterface
,
657 MMDevice_OpenPropertyStore
,
662 static inline MMDevice
*impl_from_IMMEndpoint(IMMEndpoint
*iface
)
664 return CONTAINING_RECORD(iface
, MMDevice
, IMMEndpoint_iface
);
667 static HRESULT WINAPI
MMEndpoint_QueryInterface(IMMEndpoint
*iface
, REFIID riid
, void **ppv
)
669 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
670 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
671 return IMMDevice_QueryInterface(&This
->IMMDevice_iface
, riid
, ppv
);
674 static ULONG WINAPI
MMEndpoint_AddRef(IMMEndpoint
*iface
)
676 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
677 TRACE("(%p)\n", This
);
678 return IMMDevice_AddRef(&This
->IMMDevice_iface
);
681 static ULONG WINAPI
MMEndpoint_Release(IMMEndpoint
*iface
)
683 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
684 TRACE("(%p)\n", This
);
685 return IMMDevice_Release(&This
->IMMDevice_iface
);
688 static HRESULT WINAPI
MMEndpoint_GetDataFlow(IMMEndpoint
*iface
, EDataFlow
*flow
)
690 MMDevice
*This
= impl_from_IMMEndpoint(iface
);
691 TRACE("(%p)->(%p)\n", This
, flow
);
698 static const IMMEndpointVtbl MMEndpointVtbl
=
700 MMEndpoint_QueryInterface
,
703 MMEndpoint_GetDataFlow
706 static HRESULT
MMDevCol_Create(IMMDeviceCollection
**ppv
, EDataFlow flow
, DWORD state
)
710 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
713 return E_OUTOFMEMORY
;
714 This
->IMMDeviceCollection_iface
.lpVtbl
= &MMDevColVtbl
;
718 *ppv
= &This
->IMMDeviceCollection_iface
;
722 static void MMDevCol_Destroy(MMDevColImpl
*This
)
724 HeapFree(GetProcessHeap(), 0, This
);
727 static HRESULT WINAPI
MMDevCol_QueryInterface(IMMDeviceCollection
*iface
, REFIID riid
, void **ppv
)
729 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
730 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
734 if (IsEqualIID(riid
, &IID_IUnknown
)
735 || IsEqualIID(riid
, &IID_IMMDeviceCollection
))
740 return E_NOINTERFACE
;
741 IUnknown_AddRef((IUnknown
*)*ppv
);
745 static ULONG WINAPI
MMDevCol_AddRef(IMMDeviceCollection
*iface
)
747 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
748 LONG ref
= InterlockedIncrement(&This
->ref
);
749 TRACE("Refcount now %i\n", ref
);
753 static ULONG WINAPI
MMDevCol_Release(IMMDeviceCollection
*iface
)
755 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
756 LONG ref
= InterlockedDecrement(&This
->ref
);
757 TRACE("Refcount now %i\n", ref
);
759 MMDevCol_Destroy(This
);
763 static HRESULT WINAPI
MMDevCol_GetCount(IMMDeviceCollection
*iface
, UINT
*numdevs
)
765 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
768 TRACE("(%p)->(%p)\n", This
, numdevs
);
773 for (i
= 0; i
< MMDevice_count
; ++i
)
775 MMDevice
*cur
= MMDevice_head
[i
];
776 if ((cur
->flow
== This
->flow
|| This
->flow
== eAll
)
777 && (cur
->state
& This
->state
))
783 static HRESULT WINAPI
MMDevCol_Item(IMMDeviceCollection
*iface
, UINT n
, IMMDevice
**dev
)
785 MMDevColImpl
*This
= impl_from_IMMDeviceCollection(iface
);
788 TRACE("(%p)->(%u, %p)\n", This
, n
, dev
);
792 for (j
= 0; j
< MMDevice_count
; ++j
)
794 MMDevice
*cur
= MMDevice_head
[j
];
795 if ((cur
->flow
== This
->flow
|| This
->flow
== eAll
)
796 && (cur
->state
& This
->state
)
799 *dev
= &cur
->IMMDevice_iface
;
800 IMMDevice_AddRef(*dev
);
804 WARN("Could not obtain item %u\n", n
);
809 static const IMMDeviceCollectionVtbl MMDevColVtbl
=
811 MMDevCol_QueryInterface
,
818 HRESULT
MMDevEnum_Create(REFIID riid
, void **ppv
)
820 MMDevEnumImpl
*This
= MMDevEnumerator
;
824 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
827 return E_OUTOFMEMORY
;
829 This
->IMMDeviceEnumerator_iface
.lpVtbl
= &MMDevEnumVtbl
;
830 MMDevEnumerator
= This
;
832 load_devices_from_reg();
833 load_driver_devices(eRender
);
834 load_driver_devices(eCapture
);
836 return IUnknown_QueryInterface((IUnknown
*)This
, riid
, ppv
);
839 void MMDevEnum_Free(void)
841 while (MMDevice_count
)
842 MMDevice_Destroy(MMDevice_head
[0]);
843 RegCloseKey(key_render
);
844 RegCloseKey(key_capture
);
845 key_render
= key_capture
= NULL
;
846 HeapFree(GetProcessHeap(), 0, MMDevEnumerator
);
847 MMDevEnumerator
= NULL
;
850 static HRESULT WINAPI
MMDevEnum_QueryInterface(IMMDeviceEnumerator
*iface
, REFIID riid
, void **ppv
)
852 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
853 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
857 if (IsEqualIID(riid
, &IID_IUnknown
)
858 || IsEqualIID(riid
, &IID_IMMDeviceEnumerator
))
863 return E_NOINTERFACE
;
864 IUnknown_AddRef((IUnknown
*)*ppv
);
868 static ULONG WINAPI
MMDevEnum_AddRef(IMMDeviceEnumerator
*iface
)
870 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
871 LONG ref
= InterlockedIncrement(&This
->ref
);
872 TRACE("Refcount now %i\n", ref
);
876 static ULONG WINAPI
MMDevEnum_Release(IMMDeviceEnumerator
*iface
)
878 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
879 LONG ref
= InterlockedDecrement(&This
->ref
);
882 TRACE("Refcount now %i\n", ref
);
886 static HRESULT WINAPI
MMDevEnum_EnumAudioEndpoints(IMMDeviceEnumerator
*iface
, EDataFlow flow
, DWORD mask
, IMMDeviceCollection
**devices
)
888 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
889 TRACE("(%p)->(%u,%u,%p)\n", This
, flow
, mask
, devices
);
893 if (flow
>= EDataFlow_enum_count
)
895 if (mask
& ~DEVICE_STATEMASK_ALL
)
897 return MMDevCol_Create(devices
, flow
, mask
);
900 static HRESULT WINAPI
MMDevEnum_GetDefaultAudioEndpoint(IMMDeviceEnumerator
*iface
, EDataFlow flow
, ERole role
, IMMDevice
**device
)
902 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
907 TRACE("(%p)->(%u,%u,%p)\n", This
, flow
, role
, device
);
912 if((flow
!= eRender
&& flow
!= eCapture
) ||
913 (role
!= eConsole
&& role
!= eMultimedia
&& role
!= eCommunications
)){
914 WARN("Unknown flow (%u) or role (%u)\n", flow
, role
);
920 if(!drvs
.module_name
[0])
923 lstrcpyW(reg_key
, drv_keyW
);
924 lstrcatW(reg_key
, slashW
);
925 lstrcatW(reg_key
, drvs
.module_name
);
927 if(RegOpenKeyW(HKEY_CURRENT_USER
, reg_key
, &key
) == ERROR_SUCCESS
){
928 const WCHAR
*reg_x_name
, *reg_vx_name
;
930 DWORD size
= sizeof(def_id
), state
;
933 reg_x_name
= reg_out_nameW
;
934 reg_vx_name
= reg_vout_nameW
;
936 reg_x_name
= reg_in_nameW
;
937 reg_vx_name
= reg_vin_nameW
;
940 if(role
== eCommunications
&&
941 RegQueryValueExW(key
, reg_vx_name
, 0, NULL
,
942 (BYTE
*)def_id
, &size
) == ERROR_SUCCESS
){
943 hr
= IMMDeviceEnumerator_GetDevice(iface
, def_id
, device
);
945 if(SUCCEEDED(IMMDevice_GetState(*device
, &state
)) &&
946 state
== DEVICE_STATE_ACTIVE
){
952 TRACE("Unable to find voice device %s\n", wine_dbgstr_w(def_id
));
955 if(RegQueryValueExW(key
, reg_x_name
, 0, NULL
,
956 (BYTE
*)def_id
, &size
) == ERROR_SUCCESS
){
957 hr
= IMMDeviceEnumerator_GetDevice(iface
, def_id
, device
);
959 if(SUCCEEDED(IMMDevice_GetState(*device
, &state
)) &&
960 state
== DEVICE_STATE_ACTIVE
){
966 TRACE("Unable to find device %s\n", wine_dbgstr_w(def_id
));
973 *device
= &MMDevice_def_play
->IMMDevice_iface
;
975 *device
= &MMDevice_def_rec
->IMMDevice_iface
;
979 IMMDevice_AddRef(*device
);
983 static HRESULT WINAPI
MMDevEnum_GetDevice(IMMDeviceEnumerator
*iface
, const WCHAR
*name
, IMMDevice
**device
)
985 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
987 IMMDevice
*dev
= NULL
;
989 static const WCHAR wine_info_deviceW
[] = {'W','i','n','e',' ',
990 'i','n','f','o',' ','d','e','v','i','c','e',0};
992 TRACE("(%p)->(%s,%p)\n", This
, debugstr_w(name
), device
);
997 if(!lstrcmpW(name
, wine_info_deviceW
)){
998 *device
= &info_device
;
1002 for (i
= 0; i
< MMDevice_count
; ++i
)
1005 dev
= &MMDevice_head
[i
]->IMMDevice_iface
;
1006 IMMDevice_GetId(dev
, &str
);
1008 if (str
&& !lstrcmpW(str
, name
))
1011 IMMDevice_AddRef(dev
);
1017 TRACE("Could not find device %s\n", debugstr_w(name
));
1018 return E_INVALIDARG
;
1021 struct NotificationClientWrapper
{
1022 IMMNotificationClient
*client
;
1026 static struct list g_notif_clients
= LIST_INIT(g_notif_clients
);
1027 static HANDLE g_notif_thread
;
1029 static CRITICAL_SECTION g_notif_lock
;
1030 static CRITICAL_SECTION_DEBUG g_notif_lock_debug
=
1032 0, 0, &g_notif_lock
,
1033 { &g_notif_lock_debug
.ProcessLocksList
, &g_notif_lock_debug
.ProcessLocksList
},
1034 0, 0, { (DWORD_PTR
)(__FILE__
": g_notif_lock") }
1036 static CRITICAL_SECTION g_notif_lock
= { &g_notif_lock_debug
, -1, 0, 0, 0, 0 };
1038 static void notify_clients(EDataFlow flow
, ERole role
, const WCHAR
*id
)
1040 struct NotificationClientWrapper
*wrapper
;
1041 LIST_FOR_EACH_ENTRY(wrapper
, &g_notif_clients
,
1042 struct NotificationClientWrapper
, entry
)
1043 IMMNotificationClient_OnDefaultDeviceChanged(wrapper
->client
, flow
,
1046 /* Windows 7 treats changes to eConsole as changes to eMultimedia */
1047 if(role
== eConsole
)
1048 notify_clients(flow
, eMultimedia
, id
);
1051 static BOOL
notify_if_changed(EDataFlow flow
, ERole role
, HKEY key
,
1052 const WCHAR
*val_name
, WCHAR
*old_val
, IMMDevice
*def_dev
)
1054 WCHAR new_val
[64], *id
;
1058 size
= sizeof(new_val
);
1059 if(RegQueryValueExW(key
, val_name
, 0, NULL
,
1060 (BYTE
*)new_val
, &size
) != ERROR_SUCCESS
){
1061 if(old_val
[0] != 0){
1062 /* set by user -> system default */
1064 hr
= IMMDevice_GetId(def_dev
, &id
);
1066 ERR("GetId failed: %08x\n", hr
);
1072 notify_clients(flow
, role
, id
);
1079 /* system default -> system default, noop */
1083 if(!lstrcmpW(old_val
, new_val
)){
1084 /* set by user -> same value */
1088 if(new_val
[0] != 0){
1089 /* set by user -> different value */
1090 notify_clients(flow
, role
, new_val
);
1091 memcpy(old_val
, new_val
, sizeof(new_val
));
1095 /* set by user -> system default */
1097 hr
= IMMDevice_GetId(def_dev
, &id
);
1099 ERR("GetId failed: %08x\n", hr
);
1105 notify_clients(flow
, role
, id
);
1112 static DWORD WINAPI
notif_thread_proc(void *user
)
1116 WCHAR out_name
[64], vout_name
[64], in_name
[64], vin_name
[64];
1119 lstrcpyW(reg_key
, drv_keyW
);
1120 lstrcatW(reg_key
, slashW
);
1121 lstrcatW(reg_key
, drvs
.module_name
);
1123 if(RegCreateKeyExW(HKEY_CURRENT_USER
, reg_key
, 0, NULL
, 0,
1124 MAXIMUM_ALLOWED
, NULL
, &key
, NULL
) != ERROR_SUCCESS
){
1125 ERR("RegCreateKeyEx failed: %u\n", GetLastError());
1129 size
= sizeof(out_name
);
1130 if(RegQueryValueExW(key
, reg_out_nameW
, 0, NULL
,
1131 (BYTE
*)out_name
, &size
) != ERROR_SUCCESS
)
1134 size
= sizeof(vout_name
);
1135 if(RegQueryValueExW(key
, reg_vout_nameW
, 0, NULL
,
1136 (BYTE
*)vout_name
, &size
) != ERROR_SUCCESS
)
1139 size
= sizeof(in_name
);
1140 if(RegQueryValueExW(key
, reg_in_nameW
, 0, NULL
,
1141 (BYTE
*)in_name
, &size
) != ERROR_SUCCESS
)
1144 size
= sizeof(vin_name
);
1145 if(RegQueryValueExW(key
, reg_vin_nameW
, 0, NULL
,
1146 (BYTE
*)vin_name
, &size
) != ERROR_SUCCESS
)
1150 if(RegNotifyChangeKeyValue(key
, FALSE
, REG_NOTIFY_CHANGE_LAST_SET
,
1151 NULL
, FALSE
) != ERROR_SUCCESS
){
1152 ERR("RegNotifyChangeKeyValue failed: %u\n", GetLastError());
1154 g_notif_thread
= NULL
;
1158 EnterCriticalSection(&g_notif_lock
);
1160 notify_if_changed(eRender
, eConsole
, key
, reg_out_nameW
,
1161 out_name
, &MMDevice_def_play
->IMMDevice_iface
);
1162 notify_if_changed(eRender
, eCommunications
, key
, reg_vout_nameW
,
1163 vout_name
, &MMDevice_def_play
->IMMDevice_iface
);
1164 notify_if_changed(eCapture
, eConsole
, key
, reg_in_nameW
,
1165 in_name
, &MMDevice_def_rec
->IMMDevice_iface
);
1166 notify_if_changed(eCapture
, eCommunications
, key
, reg_vin_nameW
,
1167 vin_name
, &MMDevice_def_rec
->IMMDevice_iface
);
1169 LeaveCriticalSection(&g_notif_lock
);
1174 g_notif_thread
= NULL
;
1179 static HRESULT WINAPI
MMDevEnum_RegisterEndpointNotificationCallback(IMMDeviceEnumerator
*iface
, IMMNotificationClient
*client
)
1181 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
1182 struct NotificationClientWrapper
*wrapper
;
1184 TRACE("(%p)->(%p)\n", This
, client
);
1189 wrapper
= HeapAlloc(GetProcessHeap(), 0, sizeof(*wrapper
));
1191 return E_OUTOFMEMORY
;
1193 wrapper
->client
= client
;
1195 EnterCriticalSection(&g_notif_lock
);
1197 list_add_tail(&g_notif_clients
, &wrapper
->entry
);
1199 if(!g_notif_thread
){
1200 g_notif_thread
= CreateThread(NULL
, 0, notif_thread_proc
, NULL
, 0, NULL
);
1202 ERR("CreateThread failed: %u\n", GetLastError());
1205 LeaveCriticalSection(&g_notif_lock
);
1210 static HRESULT WINAPI
MMDevEnum_UnregisterEndpointNotificationCallback(IMMDeviceEnumerator
*iface
, IMMNotificationClient
*client
)
1212 MMDevEnumImpl
*This
= impl_from_IMMDeviceEnumerator(iface
);
1213 struct NotificationClientWrapper
*wrapper
, *wrapper2
;
1215 TRACE("(%p)->(%p)\n", This
, client
);
1220 EnterCriticalSection(&g_notif_lock
);
1222 LIST_FOR_EACH_ENTRY_SAFE(wrapper
, wrapper2
, &g_notif_clients
,
1223 struct NotificationClientWrapper
, entry
){
1224 if(wrapper
->client
== client
){
1225 list_remove(&wrapper
->entry
);
1226 HeapFree(GetProcessHeap(), 0, wrapper
);
1227 LeaveCriticalSection(&g_notif_lock
);
1232 LeaveCriticalSection(&g_notif_lock
);
1237 static const IMMDeviceEnumeratorVtbl MMDevEnumVtbl
=
1239 MMDevEnum_QueryInterface
,
1242 MMDevEnum_EnumAudioEndpoints
,
1243 MMDevEnum_GetDefaultAudioEndpoint
,
1244 MMDevEnum_GetDevice
,
1245 MMDevEnum_RegisterEndpointNotificationCallback
,
1246 MMDevEnum_UnregisterEndpointNotificationCallback
1249 static HRESULT
MMDevPropStore_Create(MMDevice
*parent
, DWORD access
, IPropertyStore
**ppv
)
1251 MMDevPropStore
*This
;
1252 if (access
!= STGM_READ
1253 && access
!= STGM_WRITE
1254 && access
!= STGM_READWRITE
)
1256 WARN("Invalid access %08x\n", access
);
1257 return E_INVALIDARG
;
1259 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
1260 *ppv
= &This
->IPropertyStore_iface
;
1262 return E_OUTOFMEMORY
;
1263 This
->IPropertyStore_iface
.lpVtbl
= &MMDevPropVtbl
;
1265 This
->parent
= parent
;
1266 This
->access
= access
;
1270 static void MMDevPropStore_Destroy(MMDevPropStore
*This
)
1272 HeapFree(GetProcessHeap(), 0, This
);
1275 static HRESULT WINAPI
MMDevPropStore_QueryInterface(IPropertyStore
*iface
, REFIID riid
, void **ppv
)
1277 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1278 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
1282 if (IsEqualIID(riid
, &IID_IUnknown
)
1283 || IsEqualIID(riid
, &IID_IPropertyStore
))
1288 return E_NOINTERFACE
;
1289 IUnknown_AddRef((IUnknown
*)*ppv
);
1293 static ULONG WINAPI
MMDevPropStore_AddRef(IPropertyStore
*iface
)
1295 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1296 LONG ref
= InterlockedIncrement(&This
->ref
);
1297 TRACE("Refcount now %i\n", ref
);
1301 static ULONG WINAPI
MMDevPropStore_Release(IPropertyStore
*iface
)
1303 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1304 LONG ref
= InterlockedDecrement(&This
->ref
);
1305 TRACE("Refcount now %i\n", ref
);
1307 MMDevPropStore_Destroy(This
);
1311 static HRESULT WINAPI
MMDevPropStore_GetCount(IPropertyStore
*iface
, DWORD
*nprops
)
1313 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1319 TRACE("(%p)->(%p)\n", iface
, nprops
);
1322 hr
= MMDevPropStore_OpenPropKey(&This
->parent
->devguid
, This
->parent
->flow
, &propkey
);
1327 DWORD len
= sizeof(buffer
)/sizeof(*buffer
);
1328 if (RegEnumValueW(propkey
, i
, buffer
, &len
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
)
1332 RegCloseKey(propkey
);
1333 TRACE("Returning %i\n", i
);
1338 static HRESULT WINAPI
MMDevPropStore_GetAt(IPropertyStore
*iface
, DWORD prop
, PROPERTYKEY
*key
)
1340 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1342 DWORD len
= sizeof(buffer
)/sizeof(*buffer
);
1346 TRACE("(%p)->(%u,%p)\n", iface
, prop
, key
);
1350 hr
= MMDevPropStore_OpenPropKey(&This
->parent
->devguid
, This
->parent
->flow
, &propkey
);
1354 if (RegEnumValueW(propkey
, prop
, buffer
, &len
, NULL
, NULL
, NULL
, NULL
) != ERROR_SUCCESS
1357 WARN("GetAt %u failed\n", prop
);
1358 return E_INVALIDARG
;
1360 RegCloseKey(propkey
);
1362 CLSIDFromString(buffer
, &key
->fmtid
);
1363 key
->pid
= atoiW(&buffer
[39]);
1367 static HRESULT WINAPI
MMDevPropStore_GetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, PROPVARIANT
*pv
)
1369 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1370 TRACE("(%p)->(\"%s,%u\", %p)\n", This
, key
? debugstr_guid(&key
->fmtid
) : NULL
, key
? key
->pid
: 0, pv
);
1374 if (This
->access
!= STGM_READ
1375 && This
->access
!= STGM_READWRITE
)
1376 return STG_E_ACCESSDENIED
;
1379 if (IsEqualPropertyKey(*key
, PKEY_AudioEndpoint_GUID
))
1382 pv
->u
.pwszVal
= CoTaskMemAlloc(39 * sizeof(WCHAR
));
1384 return E_OUTOFMEMORY
;
1385 StringFromGUID2(&This
->parent
->devguid
, pv
->u
.pwszVal
, 39);
1389 return MMDevice_GetPropValue(&This
->parent
->devguid
, This
->parent
->flow
, key
, pv
);
1392 static HRESULT WINAPI
MMDevPropStore_SetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, REFPROPVARIANT pv
)
1394 MMDevPropStore
*This
= impl_from_IPropertyStore(iface
);
1395 TRACE("(%p)->(\"%s,%u\", %p)\n", This
, key
? debugstr_guid(&key
->fmtid
) : NULL
, key
? key
->pid
: 0, pv
);
1400 if (This
->access
!= STGM_WRITE
1401 && This
->access
!= STGM_READWRITE
)
1402 return STG_E_ACCESSDENIED
;
1403 return MMDevice_SetPropValue(&This
->parent
->devguid
, This
->parent
->flow
, key
, pv
);
1406 static HRESULT WINAPI
MMDevPropStore_Commit(IPropertyStore
*iface
)
1412 static const IPropertyStoreVtbl MMDevPropVtbl
=
1414 MMDevPropStore_QueryInterface
,
1415 MMDevPropStore_AddRef
,
1416 MMDevPropStore_Release
,
1417 MMDevPropStore_GetCount
,
1418 MMDevPropStore_GetAt
,
1419 MMDevPropStore_GetValue
,
1420 MMDevPropStore_SetValue
,
1421 MMDevPropStore_Commit
1425 /* Property bag for IBaseFilter activation */
1426 static HRESULT WINAPI
PB_QueryInterface(IPropertyBag
*iface
, REFIID riid
, void **ppv
)
1428 ERR("Should not be called\n");
1430 return E_NOINTERFACE
;
1433 static ULONG WINAPI
PB_AddRef(IPropertyBag
*iface
)
1435 ERR("Should not be called\n");
1439 static ULONG WINAPI
PB_Release(IPropertyBag
*iface
)
1441 ERR("Should not be called\n");
1445 static HRESULT WINAPI
PB_Read(IPropertyBag
*iface
, LPCOLESTR name
, VARIANT
*var
, IErrorLog
*log
)
1447 static const WCHAR dsguid
[] = { 'D','S','G','u','i','d', 0 };
1448 IPropertyBagImpl
*This
= impl_from_IPropertyBag(iface
);
1449 TRACE("Trying to read %s, type %u\n", debugstr_w(name
), var
->n1
.n2
.vt
);
1450 if (!lstrcmpW(name
, dsguid
))
1453 StringFromGUID2(&This
->devguid
, guidstr
,sizeof(guidstr
)/sizeof(*guidstr
));
1454 var
->n1
.n2
.vt
= VT_BSTR
;
1455 var
->n1
.n2
.n3
.bstrVal
= SysAllocString(guidstr
);
1458 ERR("Unknown property '%s' queried\n", debugstr_w(name
));
1462 static HRESULT WINAPI
PB_Write(IPropertyBag
*iface
, LPCOLESTR name
, VARIANT
*var
)
1464 ERR("Should not be called\n");
1468 static const IPropertyBagVtbl PB_Vtbl
=
1477 static ULONG WINAPI
info_device_ps_AddRef(IPropertyStore
*iface
)
1482 static ULONG WINAPI
info_device_ps_Release(IPropertyStore
*iface
)
1487 static HRESULT WINAPI
info_device_ps_GetValue(IPropertyStore
*iface
,
1488 REFPROPERTYKEY key
, PROPVARIANT
*pv
)
1490 TRACE("(static)->(\"%s,%u\", %p)\n", debugstr_guid(&key
->fmtid
), key
? key
->pid
: 0, pv
);
1495 if (IsEqualPropertyKey(*key
, DEVPKEY_Device_Driver
))
1497 INT size
= (lstrlenW(drvs
.module_name
) + 1) * sizeof(WCHAR
);
1499 pv
->u
.pwszVal
= CoTaskMemAlloc(size
);
1501 return E_OUTOFMEMORY
;
1502 memcpy(pv
->u
.pwszVal
, drvs
.module_name
, size
);
1506 return E_INVALIDARG
;
1509 static const IPropertyStoreVtbl info_device_ps_Vtbl
=
1512 info_device_ps_AddRef
,
1513 info_device_ps_Release
,
1516 info_device_ps_GetValue
,
1521 static IPropertyStore info_device_ps
= {
1522 &info_device_ps_Vtbl
1525 static ULONG WINAPI
info_device_AddRef(IMMDevice
*iface
)
1530 static ULONG WINAPI
info_device_Release(IMMDevice
*iface
)
1535 static HRESULT WINAPI
info_device_OpenPropertyStore(IMMDevice
*iface
,
1536 DWORD access
, IPropertyStore
**ppv
)
1538 TRACE("(static)->(%x, %p)\n", access
, ppv
);
1539 *ppv
= &info_device_ps
;
1543 static const IMMDeviceVtbl info_device_Vtbl
=
1547 info_device_Release
,
1549 info_device_OpenPropertyStore
,
1554 static IMMDevice info_device
= {