propset.c 60.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*  			DirectSound
 *
 * Copyright 1998 Marcus Meissner
 * Copyright 1998 Rob Riggs
 * Copyright 2000-2002 TransGaming Technologies, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 21
 */

22
#define COBJMACROS
23
#include <stdarg.h>
24 25 26

#include "windef.h"
#include "winbase.h"
27
#include "winuser.h"
28
#include "mmsystem.h"
29
#include "winternl.h"
30
#include "winnls.h"
31
#include "vfwmsgs.h"
32 33 34 35 36
#include "mmddk.h"
#include "wine/debug.h"
#include "dsound.h"
#include "dsdriver.h"
#include "dsound_private.h"
37
#include "dsconf.h"
38

39 40 41 42 43 44
#ifdef NONAMELESSSTRUCT
# define S(x) (x).s
#else
# define S(x) (x)
#endif

45 46 47 48
WINE_DEFAULT_DEBUG_CHANNEL(dsound);


/*******************************************************************************
49
 *              IKsBufferPropertySet
50 51 52
 */

/* IUnknown methods */
53 54 55 56 57
static HRESULT WINAPI IKsBufferPropertySetImpl_QueryInterface(
    LPKSPROPERTYSET iface,
    REFIID riid,
    LPVOID *ppobj )
{
58
    IKsBufferPropertySetImpl *This = (IKsBufferPropertySetImpl *)iface;
59
    TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
60

61 62
    return IDirectSoundBuffer_QueryInterface((LPDIRECTSOUNDBUFFER8)This->dsb, riid, ppobj);
}
63

64 65
static ULONG WINAPI IKsBufferPropertySetImpl_AddRef(LPKSPROPERTYSET iface)
{
66
    IKsBufferPropertySetImpl *This = (IKsBufferPropertySetImpl *)iface;
67
    ULONG ref = InterlockedIncrement(&(This->ref));
68
    TRACE("(%p) ref was %d\n", This, ref - 1);
69
    return ref;
70 71
}

72 73
static ULONG WINAPI IKsBufferPropertySetImpl_Release(LPKSPROPERTYSET iface)
{
74
    IKsBufferPropertySetImpl *This = (IKsBufferPropertySetImpl *)iface;
75
    ULONG ref = InterlockedDecrement(&(This->ref));
76
    TRACE("(%p) ref was %d\n", This, ref + 1);
77

78
    if (!ref) {
79 80
	This->dsb->iks = 0;
	IDirectSoundBuffer_Release((LPDIRECTSOUND3DBUFFER)This->dsb);
81 82
	HeapFree(GetProcessHeap(), 0, This);
	TRACE("(%p) released\n", This);
83
    }
84
    return ref;
85 86 87 88 89 90 91 92 93 94 95 96
}

static HRESULT WINAPI IKsBufferPropertySetImpl_Get(
    LPKSPROPERTYSET iface,
    REFGUID guidPropSet,
    ULONG dwPropID,
    LPVOID pInstanceData,
    ULONG cbInstanceData,
    LPVOID pPropData,
    ULONG cbPropData,
    PULONG pcbReturned )
{
97
    IKsBufferPropertySetImpl *This = (IKsBufferPropertySetImpl *)iface;
98
    PIDSDRIVERPROPERTYSET ps;
99
    TRACE("(iface=%p,guidPropSet=%s,dwPropID=%d,pInstanceData=%p,cbInstanceData=%d,pPropData=%p,cbPropData=%d,pcbReturned=%p)\n",
100 101
	This,debugstr_guid(guidPropSet),dwPropID,pInstanceData,cbInstanceData,pPropData,cbPropData,pcbReturned);

102 103
    if (This->dsb->hwbuf) {
        IDsDriver_QueryInterface(This->dsb->hwbuf, &IID_IDsDriverPropertySet, (void **)&ps);
104

105 106 107
        if (ps) {
	    DSPROPERTY prop;
	    HRESULT hres;
108

109 110 111
	    S(prop).Set = *guidPropSet;
	    S(prop).Id = dwPropID;
	    S(prop).Flags = 0;	/* unused */
Robert Reif's avatar
Robert Reif committed
112
	    S(prop).InstanceId = (ULONG)This->dsb->device;
113

114
	    hres = IDsDriverPropertySet_Get(ps, &prop, pInstanceData, cbInstanceData, pPropData, cbPropData, pcbReturned);
115

116
	    IDsDriverPropertySet_Release(ps);
117

118 119
	    return hres;
        }
120 121
    }

122 123 124 125 126 127 128 129 130 131 132 133
    return E_PROP_ID_UNSUPPORTED;
}

static HRESULT WINAPI IKsBufferPropertySetImpl_Set(
    LPKSPROPERTYSET iface,
    REFGUID guidPropSet,
    ULONG dwPropID,
    LPVOID pInstanceData,
    ULONG cbInstanceData,
    LPVOID pPropData,
    ULONG cbPropData )
{
134
    IKsBufferPropertySetImpl *This = (IKsBufferPropertySetImpl *)iface;
135
    PIDSDRIVERPROPERTYSET ps;
136
    TRACE("(%p,%s,%d,%p,%d,%p,%d)\n",This,debugstr_guid(guidPropSet),dwPropID,pInstanceData,cbInstanceData,pPropData,cbPropData);
137

138 139
    if (This->dsb->hwbuf) {
        IDsDriver_QueryInterface(This->dsb->hwbuf, &IID_IDsDriverPropertySet, (void **)&ps);
140

141 142 143
        if (ps) {
	    DSPROPERTY prop;
	    HRESULT hres;
144

145 146 147
	    S(prop).Set = *guidPropSet;
	    S(prop).Id = dwPropID;
	    S(prop).Flags = 0;	/* unused */
Robert Reif's avatar
Robert Reif committed
148
	    S(prop).InstanceId = (ULONG)This->dsb->device;
149
	    hres = IDsDriverPropertySet_Set(ps,&prop,pInstanceData,cbInstanceData,pPropData,cbPropData);
150

151
	    IDsDriverPropertySet_Release(ps);
152

153 154
	    return hres;
        }
155
    }
156 157 158 159 160 161 162 163 164 165

    return E_PROP_ID_UNSUPPORTED;
}

static HRESULT WINAPI IKsBufferPropertySetImpl_QuerySupport(
    LPKSPROPERTYSET iface,
    REFGUID guidPropSet,
    ULONG dwPropID,
    PULONG pTypeSupport )
{
166
    IKsBufferPropertySetImpl *This = (IKsBufferPropertySetImpl *)iface;
167
    PIDSDRIVERPROPERTYSET ps;
168
    TRACE("(%p,%s,%d,%p)\n",This,debugstr_guid(guidPropSet),dwPropID,pTypeSupport);
169

170 171
    if (This->dsb->hwbuf) {
        IDsDriver_QueryInterface(This->dsb->hwbuf, &IID_IDsDriverPropertySet, (void **)&ps);
172

173 174
        if (ps) {
            HRESULT hres;
175

176
            hres = IDsDriverPropertySet_QuerySupport(ps,guidPropSet, dwPropID,pTypeSupport);
177

178
            IDsDriverPropertySet_Release(ps);
179

180 181
            return hres;
        }
182
    }
183 184 185 186

    return E_PROP_ID_UNSUPPORTED;
}

187
static const IKsPropertySetVtbl iksbvt = {
188 189 190 191 192 193 194 195
    IKsBufferPropertySetImpl_QueryInterface,
    IKsBufferPropertySetImpl_AddRef,
    IKsBufferPropertySetImpl_Release,
    IKsBufferPropertySetImpl_Get,
    IKsBufferPropertySetImpl_Set,
    IKsBufferPropertySetImpl_QuerySupport
};

196
HRESULT IKsBufferPropertySetImpl_Create(
197
    IDirectSoundBufferImpl *dsb,
198 199 200
    IKsBufferPropertySetImpl **piks)
{
    IKsBufferPropertySetImpl *iks;
201
    TRACE("(%p,%p)\n",dsb,piks);
202
    *piks = NULL;
203

204
    iks = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*iks));
205 206 207 208 209 210
    if (iks == 0) {
        WARN("out of memory\n");
        *piks = NULL;
        return DSERR_OUTOFMEMORY;
    }

211
    iks->ref = 0;
212 213
    iks->dsb = dsb;
    dsb->iks = iks;
214 215
    iks->lpVtbl = &iksbvt;

216 217
    IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER)dsb);

218 219 220 221
    *piks = iks;
    return S_OK;
}

222
HRESULT IKsBufferPropertySetImpl_Destroy(
223 224 225 226 227 228 229 230 231
    IKsBufferPropertySetImpl *piks)
{
    TRACE("(%p)\n",piks);

    while (IKsBufferPropertySetImpl_Release((LPKSPROPERTYSET)piks) > 0);

    return S_OK;
}

232 233 234 235 236 237 238 239 240 241
/*******************************************************************************
 *              IKsPrivatePropertySet
 */

/* IUnknown methods */
static HRESULT WINAPI IKsPrivatePropertySetImpl_QueryInterface(
    LPKSPROPERTYSET iface,
    REFIID riid,
    LPVOID *ppobj )
{
242
    IKsPrivatePropertySetImpl *This = (IKsPrivatePropertySetImpl *)iface;
243 244
    TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);

245 246 247 248 249 250
    if (IsEqualIID(riid, &IID_IUnknown) ||
        IsEqualIID(riid, &IID_IKsPropertySet)) {
        *ppobj = iface;
        IUnknown_AddRef(iface);
        return S_OK;
    }
251
    *ppobj = NULL;
252
    return E_NOINTERFACE;
253 254 255 256
}

static ULONG WINAPI IKsPrivatePropertySetImpl_AddRef(LPKSPROPERTYSET iface)
{
257
    IKsPrivatePropertySetImpl *This = (IKsPrivatePropertySetImpl *)iface;
258
    ULONG ref = InterlockedIncrement(&(This->ref));
259
    TRACE("(%p) ref was %d\n", This, ref - 1);
260
    return ref;
261 262
}

263 264
static ULONG WINAPI IKsPrivatePropertySetImpl_Release(LPKSPROPERTYSET iface)
{
265
    IKsPrivatePropertySetImpl *This = (IKsPrivatePropertySetImpl *)iface;
266
    ULONG ref = InterlockedDecrement(&(This->ref));
267
    TRACE("(%p) ref was %d\n", This, ref + 1);
268

269 270 271
    if (!ref) {
        HeapFree(GetProcessHeap(), 0, This);
	TRACE("(%p) released\n", This);
272
    }
273
    return ref;
274 275
}

276
static HRESULT WINAPI DSPROPERTY_WaveDeviceMappingA(
277
    LPVOID pPropData,
278 279 280
    ULONG cbPropData,
    PULONG pcbReturned )
{
281
    HRESULT hr = DSERR_INVALIDPARAM;
282
    PDSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_A_DATA ppd;
283
    TRACE("(pPropData=%p,cbPropData=%d,pcbReturned=%p)\n",
284
	  pPropData,cbPropData,pcbReturned);
285 286 287 288 289 290 291 292

    ppd = (PDSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_A_DATA) pPropData;

    if (!ppd) {
	WARN("invalid parameter: pPropData\n");
	return DSERR_INVALIDPARAM;
    }

293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
    if (ppd->DataFlow == DIRECTSOUNDDEVICE_DATAFLOW_RENDER) {
        ULONG wod;
        unsigned int wodn;
        TRACE("DataFlow=DIRECTSOUNDDEVICE_DATAFLOW_RENDER\n");
        wodn = waveOutGetNumDevs();
        for (wod = 0; wod < wodn; wod++) {
            WAVEOUTCAPSA capsA;
            MMRESULT res;
            res = waveOutGetDevCapsA(wod, &capsA, sizeof(capsA));
            if (res == MMSYSERR_NOERROR) {
                if (lstrcmpA(capsA.szPname, ppd->DeviceName) == 0) {
                    ppd->DeviceId = DSOUND_renderer_guids[wod];
                    hr = DS_OK;
                    TRACE("found %s for %s\n", debugstr_guid(&ppd->DeviceId),
                          ppd->DeviceName);
                    break;
                }
            }
        }
    } else if (ppd->DataFlow == DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE) {
        ULONG wid;
        unsigned int widn;
        TRACE("DataFlow=DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE\n");
        widn = waveInGetNumDevs();
        for (wid = 0; wid < widn; wid++) {
            WAVEINCAPSA capsA;
            MMRESULT res;
            res = waveInGetDevCapsA(wid, &capsA, sizeof(capsA));
            if (res == MMSYSERR_NOERROR) {
                if (lstrcmpA(capsA.szPname, ppd->DeviceName) == 0) {
                    ppd->DeviceId = DSOUND_capture_guids[wid];
                    TRACE("found %s for %s\n", debugstr_guid(&ppd->DeviceId),
                          ppd->DeviceName);
                    hr = DS_OK;
                    break;
                }
            }
        }
    }
332

333
    if (pcbReturned)
334
	*pcbReturned = cbPropData;
335

336
    return hr;
337 338 339
}

static HRESULT WINAPI DSPROPERTY_WaveDeviceMappingW(
340
    LPVOID pPropData,
341 342 343
    ULONG cbPropData,
    PULONG pcbReturned )
{
344
    HRESULT hr = DSERR_INVALIDPARAM;
345
    PDSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_W_DATA ppd;
346
    TRACE("(pPropData=%p,cbPropData=%d,pcbReturned=%p)\n",
347
	  pPropData,cbPropData,pcbReturned);
348 349 350 351 352 353 354 355

    ppd = (PDSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_W_DATA) pPropData;

    if (!ppd) {
	WARN("invalid parameter: pPropData\n");
	return DSERR_INVALIDPARAM;
    }

356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
    if (ppd->DataFlow == DIRECTSOUNDDEVICE_DATAFLOW_RENDER) {
        ULONG wod;
        unsigned int wodn;
        TRACE("DataFlow=DIRECTSOUNDDEVICE_DATAFLOW_RENDER\n");
        wodn = waveOutGetNumDevs();
        for (wod = 0; wod < wodn; wod++) {
            WAVEOUTCAPSW capsW;
            MMRESULT res;
            res = waveOutGetDevCapsW(wod, &capsW, sizeof(capsW));
            if (res == MMSYSERR_NOERROR) {
                if (lstrcmpW(capsW.szPname, ppd->DeviceName) == 0) {
                    ppd->DeviceId = DSOUND_renderer_guids[wod];
                    hr = DS_OK;
                    TRACE("found %s for %s\n", debugstr_guid(&ppd->DeviceId),
                          debugstr_w(ppd->DeviceName));
                    break;
                }
            }
        }
    } else if (ppd->DataFlow == DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE) {
        ULONG wid;
        unsigned int widn;
        TRACE("DataFlow=DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE\n");
        widn = waveInGetNumDevs();
        for (wid = 0; wid < widn; wid++) {
            WAVEINCAPSW capsW;
            MMRESULT res;
            res = waveInGetDevCapsW(wid, &capsW, sizeof(capsW));
            if (res == MMSYSERR_NOERROR) {
                if (lstrcmpW(capsW.szPname, ppd->DeviceName) == 0) {
                    ppd->DeviceId = DSOUND_capture_guids[wid];
                    hr = DS_OK;
                    TRACE("found %s for %s\n", debugstr_guid(&ppd->DeviceId),
                          debugstr_w(ppd->DeviceName));
                    break;
                }
            }
        }
394 395
    }

396 397 398 399
    if (pcbReturned)
        *pcbReturned = cbPropData;

    return hr;
400 401 402 403 404 405 406 407 408 409
}

static HRESULT WINAPI DSPROPERTY_Description1(
    LPVOID pPropData,
    ULONG cbPropData,
    PULONG pcbReturned )
{
    HRESULT err;
    GUID guid, dev_guid;
    PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_1_DATA ppd;
410
    TRACE("(pPropData=%p,cbPropData=%d,pcbReturned=%p)\n",
411
	pPropData,cbPropData,pcbReturned);
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429

    ppd = (PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_1_DATA) pPropData;

    if (!ppd) {
	WARN("invalid parameter: pPropData\n");
	return DSERR_INVALIDPARAM;
    }

    TRACE("DeviceId=%s\n",debugstr_guid(&ppd->DeviceId));
    if ( IsEqualGUID( &ppd->DeviceId , &GUID_NULL) ) {
	/* default device of type specified by ppd->DataFlow */
	if (ppd->DataFlow == DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE) {
	    TRACE("DataFlow=DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE\n");
	} else if (ppd->DataFlow == DIRECTSOUNDDEVICE_DATAFLOW_RENDER) {
	    TRACE("DataFlow=DIRECTSOUNDDEVICE_DATAFLOW_RENDER\n");
	} else {
	    TRACE("DataFlow=Unknown(%d)\n", ppd->DataFlow);
	}
430
	FIXME("(pPropData=%p,cbPropData=%d,pcbReturned=%p) GUID_NULL not implemented!\n",
431
	      pPropData,cbPropData,pcbReturned);
432
	return E_PROP_ID_UNSUPPORTED;
433
    }
434

435 436 437
    ppd->Type = DIRECTSOUNDDEVICE_TYPE_EMULATED;
    GetDeviceID(&ppd->DeviceId, &dev_guid);

438
    if ( IsEqualGUID( &ppd->DeviceId, &DSDEVID_DefaultPlayback) ||
439 440
	 IsEqualGUID( &ppd->DeviceId, &DSDEVID_DefaultVoicePlayback) ) {
	ULONG wod;
441
	unsigned int wodn;
442 443 444 445
	TRACE("DataFlow=DIRECTSOUNDDEVICE_DATAFLOW_RENDER\n");
	ppd->DataFlow = DIRECTSOUNDDEVICE_DATAFLOW_RENDER;
	wodn = waveOutGetNumDevs();
	for (wod = 0; wod < wodn; wod++) {
446
            if (IsEqualGUID( &dev_guid, &DSOUND_renderer_guids[wod] ) ) {
447 448 449
                DSDRIVERDESC desc;
                ppd->WaveDeviceId = wod;
                ppd->Devnode = wod;
450
                err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD_PTR)&(desc),0));
451 452
                if (err == DS_OK) {
                    PIDSDRIVER drv = NULL;
453 454
                    lstrcpynA(ppd->DescriptionA, desc.szDesc, sizeof(ppd->DescriptionA));
                    lstrcpynA(ppd->ModuleA, desc.szDrvname, sizeof(ppd->ModuleA));
455
                    MultiByteToWideChar( CP_ACP, 0, desc.szDesc, -1, ppd->DescriptionW, sizeof(ppd->DescriptionW)/sizeof(WCHAR) );
456
                    MultiByteToWideChar( CP_ACP, 0, desc.szDrvname, -1, ppd->ModuleW, sizeof(ppd->ModuleW)/sizeof(WCHAR) );
457
                    err = mmErr(waveOutMessage((HWAVEOUT)wod, DRV_QUERYDSOUNDIFACE, (DWORD_PTR)&drv, 0));
458 459
                    if (err == DS_OK && drv)
                        ppd->Type = DIRECTSOUNDDEVICE_TYPE_VXD;
Robert Reif's avatar
Robert Reif committed
460 461
                    else
                        WARN("waveOutMessage(DRV_QUERYDSOUNDIFACE) failed\n");
462 463
                    break;
                } else {
Robert Reif's avatar
Robert Reif committed
464
                    WARN("waveOutMessage(DRV_QUERYDSOUNDDESC) failed\n");
465 466 467
                    return E_PROP_ID_UNSUPPORTED;
                }
            }
468 469 470 471
	}
    } else if ( IsEqualGUID( &ppd->DeviceId , &DSDEVID_DefaultCapture) ||
	        IsEqualGUID( &ppd->DeviceId , &DSDEVID_DefaultVoiceCapture) ) {
	ULONG wid;
472
	unsigned int widn;
473 474 475 476
	TRACE("DataFlow=DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE\n");
	ppd->DataFlow = DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE;
	widn = waveInGetNumDevs();
	for (wid = 0; wid < widn; wid++) {
477 478 479 480
            if (IsEqualGUID( &dev_guid, &guid) ) {
                DSDRIVERDESC desc;
                ppd->WaveDeviceId = wid;
                ppd->Devnode = wid;
481
                err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDDESC,(DWORD_PTR)&(desc),0));
482 483
                if (err == DS_OK) {
                    PIDSCDRIVER drv;
484 485
                    lstrcpynA(ppd->DescriptionA, desc.szDesc, sizeof(ppd->DescriptionA));
                    lstrcpynA(ppd->ModuleA, desc.szDrvname, sizeof(ppd->ModuleA));
486
                    MultiByteToWideChar( CP_ACP, 0, desc.szDesc, -1, ppd->DescriptionW, sizeof(ppd->DescriptionW)/sizeof(WCHAR) );
487
                    MultiByteToWideChar( CP_ACP, 0, desc.szDrvname, -1, ppd->ModuleW, sizeof(ppd->ModuleW)/sizeof(WCHAR) );
488
                    err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDIFACE,(DWORD_PTR)&drv,0));
489 490
                    if (err == DS_OK && drv)
                        ppd->Type = DIRECTSOUNDDEVICE_TYPE_VXD;
Robert Reif's avatar
Robert Reif committed
491 492
                    else
                        WARN("waveInMessage(DRV_QUERYDSOUNDIFACE) failed\n");
493 494
                    break;
                } else {
Robert Reif's avatar
Robert Reif committed
495
                    WARN("waveInMessage(DRV_QUERYDSOUNDDESC) failed\n");
496 497 498
                    return E_PROP_ID_UNSUPPORTED;
                }
            }
499
	}
500
    } else {
501 502
	BOOL found = FALSE;
	ULONG wod;
503
	unsigned int wodn;
504 505 506
	/* given specific device so try the render devices first */
	wodn = waveOutGetNumDevs();
	for (wod = 0; wod < wodn; wod++) {
507
            if (IsEqualGUID( &ppd->DeviceId, &DSOUND_renderer_guids[wod] ) ) {
508 509 510 511 512
                DSDRIVERDESC desc;
                TRACE("DataFlow=DIRECTSOUNDDEVICE_DATAFLOW_RENDER\n");
                ppd->DataFlow = DIRECTSOUNDDEVICE_DATAFLOW_RENDER;
                ppd->WaveDeviceId = wod;
                ppd->Devnode = wod;
513
                err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD_PTR)&(desc),0));
514 515
                if (err == DS_OK) {
                    PIDSDRIVER drv = NULL;
516 517
                    lstrcpynA(ppd->DescriptionA, desc.szDesc, sizeof(ppd->DescriptionA));
                    lstrcpynA(ppd->ModuleA, desc.szDrvname, sizeof(ppd->ModuleA));
518
                    MultiByteToWideChar( CP_ACP, 0, desc.szDesc, -1, ppd->DescriptionW, sizeof(ppd->DescriptionW)/sizeof(WCHAR) );
519
                    MultiByteToWideChar( CP_ACP, 0, desc.szDrvname, -1, ppd->ModuleW, sizeof(ppd->ModuleW)/sizeof(WCHAR) );
520
                    err = mmErr(waveOutMessage((HWAVEOUT)wod, DRV_QUERYDSOUNDIFACE, (DWORD_PTR)&drv, 0));
521 522
                    if (err == DS_OK && drv)
                        ppd->Type = DIRECTSOUNDDEVICE_TYPE_VXD;
Robert Reif's avatar
Robert Reif committed
523 524
                    else
                        WARN("waveOutMessage(DRV_QUERYDSOUNDIFACE) failed\n");
525 526 527
                    found = TRUE;
                    break;
                } else {
Robert Reif's avatar
Robert Reif committed
528
                    WARN("waveOutMessage(DRV_QUERYDSOUNDDESC) failed\n");
529 530 531
                    return E_PROP_ID_UNSUPPORTED;
                }
            }
532 533 534
	}

	if (found == FALSE) {
535
            ULONG wid;
536
            unsigned int widn;
537 538 539
            /* given specific device so try the capture devices next */
            widn = waveInGetNumDevs();
            for (wid = 0; wid < widn; wid++) {
540
                if (IsEqualGUID( &ppd->DeviceId, &DSOUND_capture_guids[wid] ) ) {
541 542 543 544 545
                    DSDRIVERDESC desc;
                    TRACE("DataFlow=DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE\n");
                    ppd->DataFlow = DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE;
                    ppd->WaveDeviceId = wid;
                    ppd->Devnode = wid;
546
                    err = mmErr(waveInMessage((HWAVEIN)wod,DRV_QUERYDSOUNDDESC,(DWORD_PTR)&(desc),0));
547 548
                    if (err == DS_OK) {
                        PIDSDRIVER drv = NULL;
549 550
                        lstrcpynA(ppd->DescriptionA, desc.szDesc, sizeof(ppd->DescriptionA));
                        lstrcpynA(ppd->ModuleA, desc.szDrvname, sizeof(ppd->ModuleA));
551
                        MultiByteToWideChar( CP_ACP, 0, desc.szDesc, -1, ppd->DescriptionW, sizeof(ppd->DescriptionW)/sizeof(WCHAR) );
552
                        MultiByteToWideChar( CP_ACP, 0, desc.szDrvname, -1, ppd->ModuleW, sizeof(ppd->ModuleW)/sizeof(WCHAR) );
553
                        err = mmErr(waveInMessage((HWAVEIN)wod, DRV_QUERYDSOUNDIFACE, (DWORD_PTR)&drv, 0));
554 555
                        if (err == DS_OK && drv)
                            ppd->Type = DIRECTSOUNDDEVICE_TYPE_VXD;
Robert Reif's avatar
Robert Reif committed
556 557
                        else
                            WARN("waveInMessage(DRV_QUERYDSOUNDIFACE) failed\n");
558 559 560
                        found = TRUE;
                        break;
                    } else {
Robert Reif's avatar
Robert Reif committed
561
                        WARN("waveInMessage(DRV_QUERYDSOUNDDESC) failed\n");
562 563 564 565 566 567 568 569 570
                        return E_PROP_ID_UNSUPPORTED;
                    }
                }
            }

            if (found == FALSE) {
                WARN("device not found\n");
                return E_PROP_ID_UNSUPPORTED;
            }
571
	}
572 573 574
    }

    if (pcbReturned) {
575
	*pcbReturned = cbPropData;
576
	TRACE("*pcbReturned=%d\n", *pcbReturned);
577 578 579 580 581 582 583 584 585 586
    }

    return S_OK;
}

static HRESULT WINAPI DSPROPERTY_DescriptionA(
    LPVOID pPropData,
    ULONG cbPropData,
    PULONG pcbReturned )
{
587 588
    PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A_DATA ppd = (PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A_DATA) pPropData;
    HRESULT err;
589
    GUID dev_guid;
590
    TRACE("(pPropData=%p,cbPropData=%d,pcbReturned=%p)\n",
591
	  pPropData,cbPropData,pcbReturned);
592 593 594 595 596 597 598 599 600 601 602

    TRACE("DeviceId=%s\n",debugstr_guid(&ppd->DeviceId));
    if ( IsEqualGUID( &ppd->DeviceId , &GUID_NULL) ) {
	/* default device of type specified by ppd->DataFlow */
	if (ppd->DataFlow == DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE) {
	    TRACE("DataFlow=DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE\n");
	} else if (ppd->DataFlow == DIRECTSOUNDDEVICE_DATAFLOW_RENDER) {
	    TRACE("DataFlow=DIRECTSOUNDDEVICE_DATAFLOW_RENDER\n");
	} else {
	    TRACE("DataFlow=Unknown(%d)\n", ppd->DataFlow);
	}
603
	FIXME("(pPropData=%p,cbPropData=%d,pcbReturned=%p) GUID_NULL not implemented!\n",
604
	      pPropData,cbPropData,pcbReturned);
605 606 607 608 609 610 611 612 613
	return E_PROP_ID_UNSUPPORTED;
    }

    ppd->Type = DIRECTSOUNDDEVICE_TYPE_EMULATED;
    GetDeviceID(&ppd->DeviceId, &dev_guid);

    if ( IsEqualGUID( &ppd->DeviceId , &DSDEVID_DefaultPlayback) ||
	 IsEqualGUID( &ppd->DeviceId , &DSDEVID_DefaultVoicePlayback) ) {
	ULONG wod;
614
	unsigned int wodn;
615 616 617 618
        if (IsEqualGUID( &ppd->DeviceId , &DSDEVID_DefaultPlayback) )
            TRACE("DSDEVID_DefaultPlayback\n");
        else
            TRACE("DSDEVID_DefaultVoicePlayback\n");
619 620 621
	ppd->DataFlow = DIRECTSOUNDDEVICE_DATAFLOW_RENDER;
	wodn = waveOutGetNumDevs();
	for (wod = 0; wod < wodn; wod++) {
622
            if (IsEqualGUID( &dev_guid, &DSOUND_renderer_guids[wod] ) ) {
Robert Reif's avatar
Robert Reif committed
623 624
                DSDRIVERDESC desc;
                ppd->WaveDeviceId = wod;
625
                err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD_PTR)&(desc),0));
Robert Reif's avatar
Robert Reif committed
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
                if (err == DS_OK) {
                    PIDSDRIVER drv = NULL;
                    /* FIXME: this is a memory leak */
                    CHAR * szDescription = HeapAlloc(GetProcessHeap(),0,strlen(desc.szDesc) + 1);
                    CHAR * szModule = HeapAlloc(GetProcessHeap(),0,strlen(desc.szDrvname) + 1);
                    CHAR * szInterface = HeapAlloc(GetProcessHeap(),0,strlen("Interface") + 1);

                    if (szDescription && szModule && szInterface) {
                        strcpy(szDescription, desc.szDesc);
                        strcpy(szModule, desc.szDrvname);
                        strcpy(szInterface, "Interface");

                        ppd->Description = szDescription;
                        ppd->Module = szModule;
                        ppd->Interface = szInterface;
641
                        err = mmErr(waveOutMessage((HWAVEOUT)wod, DRV_QUERYDSOUNDIFACE, (DWORD_PTR)&drv, 0));
Robert Reif's avatar
Robert Reif committed
642 643 644 645 646
                        if (err == DS_OK && drv)
                            ppd->Type = DIRECTSOUNDDEVICE_TYPE_VXD;
                        else
                            WARN("waveOutMessage(DRV_QUERYDSOUNDIFACE) failed\n");
                        break;
647
		    } else {
Robert Reif's avatar
Robert Reif committed
648 649 650 651 652
                        WARN("no memory\n");
                        HeapFree(GetProcessHeap(), 0, szDescription);
                        HeapFree(GetProcessHeap(), 0, szModule);
                        HeapFree(GetProcessHeap(), 0, szInterface);
                        return E_OUTOFMEMORY;
653
		    }
Robert Reif's avatar
Robert Reif committed
654 655 656
                } else {
                    WARN("waveOutMessage(DRV_QUERYDSOUNDDESC) failed\n");
                    return E_PROP_ID_UNSUPPORTED;
657
		}
Robert Reif's avatar
Robert Reif committed
658
            }
659 660 661 662
	}
    } else if (IsEqualGUID( &ppd->DeviceId , &DSDEVID_DefaultCapture) ||
	       IsEqualGUID( &ppd->DeviceId , &DSDEVID_DefaultVoiceCapture) ) {
	ULONG wid;
663
	unsigned int widn;
664 665 666 667
        if (IsEqualGUID( &ppd->DeviceId , &DSDEVID_DefaultCapture) )
            TRACE("DSDEVID_DefaultCapture\n");
        else
            TRACE("DSDEVID_DefaultVoiceCapture\n");
668 669 670
	ppd->DataFlow = DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE;
	widn = waveInGetNumDevs();
	for (wid = 0; wid < widn; wid++) {
671
            if (IsEqualGUID( &dev_guid, &DSOUND_capture_guids[wid] ) ) {
Robert Reif's avatar
Robert Reif committed
672 673
                DSDRIVERDESC desc;
                ppd->WaveDeviceId = wid;
674
                err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDDESC,(DWORD_PTR)&(desc),0));
Robert Reif's avatar
Robert Reif committed
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
                if (err == DS_OK) {
                    PIDSCDRIVER drv;
                    /* FIXME: this is a memory leak */
                    CHAR * szDescription = HeapAlloc(GetProcessHeap(),0,strlen(desc.szDesc) + 1);
                    CHAR * szModule = HeapAlloc(GetProcessHeap(),0,strlen(desc.szDrvname) + 1);
                    CHAR * szInterface = HeapAlloc(GetProcessHeap(),0,strlen("Interface") + 1);

                    if (szDescription && szModule && szInterface) {
                        strcpy(szDescription, desc.szDesc);
                        strcpy(szModule, desc.szDrvname);
                        strcpy(szInterface, "Interface");

                        ppd->Description = szDescription;
                        ppd->Module = szModule;
                        ppd->Interface = szInterface;
690
                        err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDIFACE,(DWORD_PTR)&drv,0));
Robert Reif's avatar
Robert Reif committed
691 692 693
                        if (err == DS_OK && drv)
                            ppd->Type = DIRECTSOUNDDEVICE_TYPE_VXD;
                        else
694
                            WARN("waveInMessage(DRV_QUERYDSOUNDIFACE) failed\n");
Robert Reif's avatar
Robert Reif committed
695
                        break;
696
		    } else {
Robert Reif's avatar
Robert Reif committed
697 698 699 700 701
                        WARN("no memory\n");
                        HeapFree(GetProcessHeap(), 0, szDescription);
                        HeapFree(GetProcessHeap(), 0, szModule);
                        HeapFree(GetProcessHeap(), 0, szInterface);
                        return E_OUTOFMEMORY;
702
		    }
Robert Reif's avatar
Robert Reif committed
703 704 705
                } else {
                    WARN("waveInMessage(DRV_QUERYDSOUNDDESC) failed\n");
                    return E_PROP_ID_UNSUPPORTED;
706
		}
Robert Reif's avatar
Robert Reif committed
707
            }
708
	}
709 710 711
    } else {
	BOOL found = FALSE;
	ULONG wod;
712
	unsigned int wodn;
713
	/* given specific device so try the render devices first */
714
        TRACE("Checking renderer devices\n");
715 716
	wodn = waveOutGetNumDevs();
	for (wod = 0; wod < wodn; wod++) {
717
            if (IsEqualGUID( &ppd->DeviceId, &DSOUND_renderer_guids[wod] ) ) {
Robert Reif's avatar
Robert Reif committed
718
                DSDRIVERDESC desc;
719
                TRACE("DSOUND_renderer_guids[%d]\n", wod);
Robert Reif's avatar
Robert Reif committed
720 721
                ppd->DataFlow = DIRECTSOUNDDEVICE_DATAFLOW_RENDER;
                ppd->WaveDeviceId = wod;
722
                err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD_PTR)&(desc),0));
Robert Reif's avatar
Robert Reif committed
723 724 725 726 727 728
                if (err == DS_OK) {
                    PIDSDRIVER drv = NULL;
                    /* FIXME: this is a memory leak */
                    CHAR * szDescription = HeapAlloc(GetProcessHeap(),0,strlen(desc.szDesc) + 1);
                    CHAR * szModule = HeapAlloc(GetProcessHeap(),0,strlen(desc.szDrvname) + 1);
                    CHAR * szInterface = HeapAlloc(GetProcessHeap(),0,strlen("Interface") + 1);
729

Robert Reif's avatar
Robert Reif committed
730
                    if (szDescription && szModule && szInterface) {
731
			strcpy(szDescription, desc.szDesc);
732
			strcpy(szModule, desc.szDrvname);
733 734 735 736 737
			strcpy(szInterface, "Interface");

			ppd->Description = szDescription;
			ppd->Module = szModule;
			ppd->Interface = szInterface;
738
			err = mmErr(waveOutMessage((HWAVEOUT)wod, DRV_QUERYDSOUNDIFACE, (DWORD_PTR)&drv, 0));
739 740
			if (err == DS_OK && drv)
				ppd->Type = DIRECTSOUNDDEVICE_TYPE_VXD;
Robert Reif's avatar
Robert Reif committed
741 742
                        else
                            WARN("waveOutMessage(DRV_QUERYDSOUNDIFACE) failed\n");
743 744 745
			found = TRUE;
			break;
		    } else {
Robert Reif's avatar
Robert Reif committed
746 747 748 749 750
                        WARN("no memory\n");
                        HeapFree(GetProcessHeap(), 0, szDescription);
                        HeapFree(GetProcessHeap(), 0, szModule);
                        HeapFree(GetProcessHeap(), 0, szInterface);
                        return E_OUTOFMEMORY;
751
		    }
Robert Reif's avatar
Robert Reif committed
752 753 754
                } else {
                    WARN("waveOutMessage(DRV_QUERYDSOUNDDESC) failed\n");
                    return E_PROP_ID_UNSUPPORTED;
755
		}
Robert Reif's avatar
Robert Reif committed
756 757 758 759 760 761
            }
        }

        if (found == FALSE) {
            ULONG wid;
            unsigned int widn;
762
            TRACE("Checking capture devices\n");
Robert Reif's avatar
Robert Reif committed
763 764 765
            ppd->DataFlow = DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE;
            widn = waveInGetNumDevs();
            for (wid = 0; wid < widn; wid++) {
766
                if (IsEqualGUID( &ppd->DeviceId, &DSOUND_capture_guids[wid] ) ) {
Robert Reif's avatar
Robert Reif committed
767
                    DSDRIVERDESC desc;
768
                    TRACE("DSOUND_capture_guids[%d]\n", wid);
Robert Reif's avatar
Robert Reif committed
769
                    ppd->WaveDeviceId = wid;
770
                    err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDDESC,(DWORD_PTR)&(desc),0));
Robert Reif's avatar
Robert Reif committed
771 772 773 774 775 776 777 778 779 780 781 782 783 784 785
                    if (err == DS_OK) {
                        PIDSCDRIVER drv;
                        /* FIXME: this is a memory leak */
                        CHAR * szDescription = HeapAlloc(GetProcessHeap(),0,strlen(desc.szDesc) + 1);
                        CHAR * szModule = HeapAlloc(GetProcessHeap(),0,strlen(desc.szDrvname) + 1);
                        CHAR * szInterface = HeapAlloc(GetProcessHeap(),0,strlen("Interface") + 1);

                        if (szDescription && szModule && szInterface) {
                            strcpy(szDescription, desc.szDesc);
                            strcpy(szModule, desc.szDrvname);
                            strcpy(szInterface, "Interface");

                            ppd->Description = szDescription;
                            ppd->Module = szModule;
                            ppd->Interface = szInterface;
786
                            err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDIFACE,(DWORD_PTR)&drv,0));
Robert Reif's avatar
Robert Reif committed
787 788 789
                            if (err == DS_OK && drv)
                                ppd->Type = DIRECTSOUNDDEVICE_TYPE_VXD;
                            else
790
                                WARN("waveInMessage(DRV_QUERYDSOUNDIFACE) failed\n");
Robert Reif's avatar
Robert Reif committed
791 792 793 794 795 796 797 798 799 800 801 802 803 804 805
                            found = TRUE;
                            break;
                        } else {
                            WARN("no memory\n");
                            HeapFree(GetProcessHeap(), 0, szDescription);
                            HeapFree(GetProcessHeap(), 0, szModule);
                            HeapFree(GetProcessHeap(), 0, szInterface);
                            return E_OUTOFMEMORY;
                        }
                    } else {
                        WARN("waveInMessage(DRV_QUERYDSOUNDDESC) failed\n");
                        return E_PROP_ID_UNSUPPORTED;
                    }
                }
            }
806 807 808 809 810 811
	}

	if (found == FALSE) {
	    WARN("device not found\n");
	    return E_PROP_ID_UNSUPPORTED;
	}
812 813 814 815
    }

    if (pcbReturned) {
	*pcbReturned = cbPropData;
816
	TRACE("*pcbReturned=%d\n", *pcbReturned);
817 818 819
    }

    return S_OK;
820 821 822 823 824 825 826 827 828
}

static HRESULT WINAPI DSPROPERTY_DescriptionW(
    LPVOID pPropData,
    ULONG cbPropData,
    PULONG pcbReturned )
{
    PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_W_DATA ppd = (PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_W_DATA) pPropData;
    HRESULT err;
829
    GUID dev_guid;
830
    TRACE("pPropData=%p,cbPropData=%d,pcbReturned=%p)\n",
831
	  pPropData,cbPropData,pcbReturned);
832 833 834 835 836 837 838 839 840 841 842

    TRACE("DeviceId=%s\n",debugstr_guid(&ppd->DeviceId));
    if ( IsEqualGUID( &ppd->DeviceId , &GUID_NULL) ) {
	/* default device of type specified by ppd->DataFlow */
	if (ppd->DataFlow == DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE) {
	    TRACE("DataFlow=DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE\n");
	} else if (ppd->DataFlow == DIRECTSOUNDDEVICE_DATAFLOW_RENDER) {
	    TRACE("DataFlow=DIRECTSOUNDDEVICE_DATAFLOW_RENDER\n");
	} else {
	    TRACE("DataFlow=Unknown(%d)\n", ppd->DataFlow);
	}
843
	FIXME("(pPropData=%p,cbPropData=%d,pcbReturned=%p) GUID_NULL not implemented!\n",
844
	      pPropData,cbPropData,pcbReturned);
845
	return E_PROP_ID_UNSUPPORTED;
846
    }
847

848 849 850
    ppd->Type = DIRECTSOUNDDEVICE_TYPE_EMULATED;
    GetDeviceID(&ppd->DeviceId, &dev_guid);

851
    if ( IsEqualGUID( &ppd->DeviceId , &DSDEVID_DefaultPlayback) ||
852 853
	 IsEqualGUID( &ppd->DeviceId , &DSDEVID_DefaultVoicePlayback) ) {
	ULONG wod;
854
	unsigned int wodn;
855 856 857 858
        if (IsEqualGUID( &ppd->DeviceId , &DSDEVID_DefaultPlayback) )
            TRACE("DSDEVID_DefaultPlayback\n");
        else
            TRACE("DSDEVID_DefaultVoicePlayback\n");
859 860 861
	ppd->DataFlow = DIRECTSOUNDDEVICE_DATAFLOW_RENDER;
	wodn = waveOutGetNumDevs();
	for (wod = 0; wod < wodn; wod++) {
862
            if (IsEqualGUID( &dev_guid, &DSOUND_renderer_guids[wod] ) ) {
Robert Reif's avatar
Robert Reif committed
863
                DSDRIVERDESC desc;
864
                TRACE("DSOUND_renderer_guids[%d]\n", wod);
Robert Reif's avatar
Robert Reif committed
865
                ppd->WaveDeviceId = wod;
866
                err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD_PTR)&(desc),0));
Robert Reif's avatar
Robert Reif committed
867 868 869 870 871 872 873 874 875 876 877 878 879 880 881
                if (err == DS_OK) {
                    PIDSDRIVER drv = NULL;
                    /* FIXME: this is a memory leak */
                    WCHAR * wDescription = HeapAlloc(GetProcessHeap(),0,0x200);
                    WCHAR * wModule = HeapAlloc(GetProcessHeap(),0,0x200);
                    WCHAR * wInterface = HeapAlloc(GetProcessHeap(),0,0x200);

                    if (wDescription && wModule && wInterface) {
                        MultiByteToWideChar( CP_ACP, 0, desc.szDesc, -1, wDescription, 0x100  );
                        MultiByteToWideChar( CP_ACP, 0, desc.szDrvname, -1, wModule, 0x100 );
                        MultiByteToWideChar( CP_ACP, 0, "Interface", -1, wInterface, 0x100 );

                        ppd->Description = wDescription;
                        ppd->Module = wModule;
                        ppd->Interface = wInterface;
882
                        err = mmErr(waveOutMessage((HWAVEOUT)wod, DRV_QUERYDSOUNDIFACE, (DWORD_PTR)&drv, 0));
Robert Reif's avatar
Robert Reif committed
883 884 885 886 887
                        if (err == DS_OK && drv)
                            ppd->Type = DIRECTSOUNDDEVICE_TYPE_VXD;
                        else
                            WARN("waveOutMessage(DRV_QUERYDSOUNDIFACE) failed\n");
                        break;
888
		    } else {
Robert Reif's avatar
Robert Reif committed
889 890 891 892 893
                        WARN("no memory\n");
                        HeapFree(GetProcessHeap(), 0, wDescription);
                        HeapFree(GetProcessHeap(), 0, wModule);
                        HeapFree(GetProcessHeap(), 0, wInterface);
                        return E_OUTOFMEMORY;
894
		    }
Robert Reif's avatar
Robert Reif committed
895 896 897
                } else {
                    WARN("waveOutMessage(DRV_QUERYDSOUNDDESC) failed\n");
                    return E_PROP_ID_UNSUPPORTED;
898
		}
Robert Reif's avatar
Robert Reif committed
899
            }
900 901 902 903
	}
    } else if (IsEqualGUID( &ppd->DeviceId , &DSDEVID_DefaultCapture) ||
	       IsEqualGUID( &ppd->DeviceId , &DSDEVID_DefaultVoiceCapture) ) {
	ULONG wid;
904
	unsigned int widn;
905 906 907 908
        if (IsEqualGUID( &ppd->DeviceId , &DSDEVID_DefaultCapture))
            TRACE("DSDEVID_DefaultCapture\n");
        else
            TRACE("DSDEVID_DefaultVoiceCapture\n");
909 910 911
	ppd->DataFlow = DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE;
	widn = waveInGetNumDevs();
	for (wid = 0; wid < widn; wid++) {
912
            if (IsEqualGUID( &dev_guid, &DSOUND_capture_guids[wid] ) ) {
Robert Reif's avatar
Robert Reif committed
913 914
                DSDRIVERDESC desc;
                ppd->WaveDeviceId = wid;
915
                err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDDESC,(DWORD_PTR)&(desc),0));
Robert Reif's avatar
Robert Reif committed
916 917 918 919 920 921 922 923 924 925 926 927 928 929 930
                if (err == DS_OK) {
                    PIDSCDRIVER drv;
                    /* FIXME: this is a memory leak */
                    WCHAR * wDescription = HeapAlloc(GetProcessHeap(),0,0x200);
                    WCHAR * wModule = HeapAlloc(GetProcessHeap(),0,0x200);
                    WCHAR * wInterface = HeapAlloc(GetProcessHeap(),0,0x200);

                    if (wDescription && wModule && wInterface) {
                        MultiByteToWideChar( CP_ACP, 0, desc.szDesc, -1, wDescription, 0x100  );
                        MultiByteToWideChar( CP_ACP, 0, desc.szDrvname, -1, wModule, 0x100 );
                        MultiByteToWideChar( CP_ACP, 0, "Interface", -1, wInterface, 0x100 );

                        ppd->Description = wDescription;
                        ppd->Module = wModule;
                        ppd->Interface = wInterface;
931
                        err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDIFACE,(DWORD_PTR)&drv,0));
Robert Reif's avatar
Robert Reif committed
932 933 934 935
                        if (err == DS_OK && drv)
                            ppd->Type = DIRECTSOUNDDEVICE_TYPE_VXD;
                        else
                            WARN("waveInMessage(DRV_QUERYDSOUNDIFACE) failed\n");
936
			break;
937
		    } else {
Robert Reif's avatar
Robert Reif committed
938 939 940 941 942
                        WARN("no memory\n");
                        HeapFree(GetProcessHeap(), 0, wDescription);
                        HeapFree(GetProcessHeap(), 0, wModule);
                        HeapFree(GetProcessHeap(), 0, wInterface);
                        return E_OUTOFMEMORY;
943
		    }
Robert Reif's avatar
Robert Reif committed
944 945 946
                } else {
                    WARN("waveInMessage(DRV_QUERYDSOUNDDESC) failed\n");
                    return E_PROP_ID_UNSUPPORTED;
947
		}
Robert Reif's avatar
Robert Reif committed
948
            }
949
	}
950
    } else {
951 952
	BOOL found = FALSE;
	ULONG wod;
953
	unsigned int wodn;
954
        TRACE("Checking renderer devices\n");
955 956 957
	/* given specific device so try the render devices first */
	wodn = waveOutGetNumDevs();
	for (wod = 0; wod < wodn; wod++) {
958
            if (IsEqualGUID( &ppd->DeviceId, &DSOUND_renderer_guids[wod] ) ) {
Robert Reif's avatar
Robert Reif committed
959
                DSDRIVERDESC desc;
960
                TRACE("DSOUND_renderer_guids[%d]\n", wod);
Robert Reif's avatar
Robert Reif committed
961 962
                ppd->DataFlow = DIRECTSOUNDDEVICE_DATAFLOW_RENDER;
                ppd->WaveDeviceId = wod;
963
                err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD_PTR)&(desc),0));
Robert Reif's avatar
Robert Reif committed
964 965 966 967 968 969
                if (err == DS_OK) {
                    PIDSDRIVER drv = NULL;
                    /* FIXME: this is a memory leak */
                    WCHAR * wDescription = HeapAlloc(GetProcessHeap(),0,0x200);
                    WCHAR * wModule = HeapAlloc(GetProcessHeap(),0,0x200);
                    WCHAR * wInterface = HeapAlloc(GetProcessHeap(),0,0x200);
970

Robert Reif's avatar
Robert Reif committed
971
                    if (wDescription && wModule && wInterface) {
972
			MultiByteToWideChar( CP_ACP, 0, desc.szDesc, -1, wDescription, 0x100  );
973
			MultiByteToWideChar( CP_ACP, 0, desc.szDrvname, -1, wModule, 0x100 );
974 975 976 977 978
			MultiByteToWideChar( CP_ACP, 0, "Interface", -1, wInterface, 0x100 );

			ppd->Description = wDescription;
			ppd->Module = wModule;
			ppd->Interface = wInterface;
979
			err = mmErr(waveOutMessage((HWAVEOUT)wod, DRV_QUERYDSOUNDIFACE, (DWORD_PTR)&drv, 0));
980
			if (err == DS_OK && drv)
Robert Reif's avatar
Robert Reif committed
981 982 983
                            ppd->Type = DIRECTSOUNDDEVICE_TYPE_VXD;
                        else
                            WARN("waveOutMessage(DRV_QUERYDSOUNDIFACE) failed\n");
984 985 986
			found = TRUE;
			break;
		    } else {
Robert Reif's avatar
Robert Reif committed
987 988 989 990 991
                        WARN("no memory\n");
                        HeapFree(GetProcessHeap(), 0, wDescription);
                        HeapFree(GetProcessHeap(), 0, wModule);
                        HeapFree(GetProcessHeap(), 0, wInterface);
                        return E_OUTOFMEMORY;
992
		    }
Robert Reif's avatar
Robert Reif committed
993 994 995
                } else {
                    WARN("waveOutMessage(DRV_QUERYDSOUNDDESC) failed\n");
                    return E_PROP_ID_UNSUPPORTED;
996
		}
Robert Reif's avatar
Robert Reif committed
997 998 999 1000 1001 1002
            }
        }

        if (found == FALSE) {
            ULONG wid;
            unsigned int widn;
1003
            TRACE("Checking capture devices\n");
Robert Reif's avatar
Robert Reif committed
1004 1005 1006
            ppd->DataFlow = DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE;
            widn = waveInGetNumDevs();
            for (wid = 0; wid < widn; wid++) {
1007
                if (IsEqualGUID( &dev_guid, &DSOUND_capture_guids[wid] ) ) {
Robert Reif's avatar
Robert Reif committed
1008
                    DSDRIVERDESC desc;
1009
                    TRACE("DSOUND_capture_guids[%d]\n", wid);
Robert Reif's avatar
Robert Reif committed
1010
                    ppd->WaveDeviceId = wid;
1011
                    err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDDESC,(DWORD_PTR)&(desc),0));
Robert Reif's avatar
Robert Reif committed
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026
                    if (err == DS_OK) {
                        PIDSCDRIVER drv;
                        /* FIXME: this is a memory leak */
                        WCHAR * wDescription = HeapAlloc(GetProcessHeap(),0,0x200);
                        WCHAR * wModule = HeapAlloc(GetProcessHeap(),0,0x200);
                        WCHAR * wInterface = HeapAlloc(GetProcessHeap(),0,0x200);

                        if (wDescription && wModule && wInterface) {
                            MultiByteToWideChar( CP_ACP, 0, desc.szDesc, -1, wDescription, 0x100  );
                            MultiByteToWideChar( CP_ACP, 0, desc.szDrvname, -1, wModule, 0x100 );
                            MultiByteToWideChar( CP_ACP, 0, "Interface", -1, wInterface, 0x100 );

                            ppd->Description = wDescription;
                            ppd->Module = wModule;
                            ppd->Interface = wInterface;
1027
                            err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDIFACE,(DWORD_PTR)&drv,0));
Robert Reif's avatar
Robert Reif committed
1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046
                            if (err == DS_OK && drv)
                                ppd->Type = DIRECTSOUNDDEVICE_TYPE_VXD;
                            else
                                WARN("waveInMessage(DRV_QUERYDSOUNDIFACE) failed\n");
                            found = TRUE;
                            break;
                        } else {
                            WARN("no memory\n");
                            HeapFree(GetProcessHeap(), 0, wDescription);
                            HeapFree(GetProcessHeap(), 0, wModule);
                            HeapFree(GetProcessHeap(), 0, wInterface);
                            return E_OUTOFMEMORY;
                        }
                    } else {
                        WARN("waveInMessage(DRV_QUERYDSOUNDDESC) failed\n");
                        return E_PROP_ID_UNSUPPORTED;
                    }
                }
            }
1047
        }
1048 1049 1050 1051 1052

	if (found == FALSE) {
	    WARN("device not found\n");
	    return E_PROP_ID_UNSUPPORTED;
	}
1053 1054 1055
    }

    if (pcbReturned) {
1056
	*pcbReturned = cbPropData;
1057
	TRACE("*pcbReturned=%d\n", *pcbReturned);
1058
    }
1059

1060 1061 1062 1063 1064 1065 1066 1067
    return S_OK;
}

static HRESULT WINAPI DSPROPERTY_Enumerate1(
    LPVOID pPropData,
    ULONG cbPropData,
    PULONG pcbReturned )
{
Robert Reif's avatar
Robert Reif committed
1068 1069
    PDSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_1_DATA ppd = (PDSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_1_DATA) pPropData;
    HRESULT err;
1070
    TRACE("(pPropData=%p,cbPropData=%d,pcbReturned=%p)\n",
1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089
          pPropData,cbPropData,pcbReturned);

    if (ppd) {
        if (ppd->Callback) {
            unsigned devs, wod, wid;
            DSDRIVERDESC desc;
            DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_1_DATA data;

            devs = waveOutGetNumDevs();
            for (wod = 0; wod < devs; ++wod) {
                err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,0));
                if (err == DS_OK) {
                    PIDSCDRIVER drv;
                    ZeroMemory(&data, sizeof(data));
                    data.DataFlow = DIRECTSOUNDDEVICE_DATAFLOW_RENDER;
                    data.WaveDeviceId = wod;
                    data.DeviceId = DSOUND_renderer_guids[wod];
                    lstrcpynA(data.DescriptionA, desc.szDesc, sizeof(data.DescriptionA));
                    lstrcpynA(data.ModuleA, desc.szDrvname, sizeof(data.ModuleA));
Robert Reif's avatar
Robert Reif committed
1090

1091 1092
                    MultiByteToWideChar( CP_ACP, 0, data.DescriptionA, -1, data.DescriptionW, sizeof(data.DescriptionW)/sizeof(WCHAR) );
                    MultiByteToWideChar( CP_ACP, 0, data.ModuleA, -1, data.ModuleW, sizeof(data.ModuleW)/sizeof(WCHAR) );
Robert Reif's avatar
Robert Reif committed
1093

1094 1095 1096 1097 1098 1099
                    data.Type = DIRECTSOUNDDEVICE_TYPE_EMULATED;
                    err = mmErr(waveOutMessage((HWAVEOUT)wod, DRV_QUERYDSOUNDIFACE, (DWORD_PTR)&drv, 0));
                    if (err == DS_OK && drv)
                        data.Type = DIRECTSOUNDDEVICE_TYPE_VXD;
                    else
                        WARN("waveOutMessage(DRV_QUERYDSOUNDIFACE) failed\n");
Robert Reif's avatar
Robert Reif committed
1100

1101 1102
                    TRACE("calling Callback(%p,%p)\n", &data, ppd->Context);
                    (ppd->Callback)(&data, ppd->Context);
Robert Reif's avatar
Robert Reif committed
1103
                }
1104
            }
Robert Reif's avatar
Robert Reif committed
1105

1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126
            devs = waveInGetNumDevs();
            for (wid = 0; wid < devs; ++wid) {
                err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,0));
                if (err == DS_OK) {
                    PIDSCDRIVER drv;
                    ZeroMemory(&data, sizeof(data));
                    data.DataFlow = DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE;
                    data.WaveDeviceId = wid;
                    data.DeviceId = DSOUND_capture_guids[wid];
                    lstrcpynA(data.DescriptionA, desc.szDesc, sizeof(data.DescriptionA));
                    lstrcpynA(data.ModuleA, desc.szDrvname, sizeof(data.ModuleA));

                    MultiByteToWideChar( CP_ACP, 0, data.DescriptionA, -1, data.DescriptionW, sizeof(data.DescriptionW)/sizeof(WCHAR) );
                    MultiByteToWideChar( CP_ACP, 0, data.ModuleA, -1, data.ModuleW, sizeof(data.ModuleW)/sizeof(WCHAR) );

                    data.Type = DIRECTSOUNDDEVICE_TYPE_EMULATED;
                    err = mmErr(waveInMessage((HWAVEIN)wid, DRV_QUERYDSOUNDIFACE, (DWORD_PTR)&drv, 0));
                    if (err == DS_OK && drv)
                        data.Type = DIRECTSOUNDDEVICE_TYPE_VXD;
                    else
                        WARN("waveInMessage(DRV_QUERYDSOUNDIFACE) failed\n");
Robert Reif's avatar
Robert Reif committed
1127

1128 1129
                    TRACE("calling Callback(%p,%p)\n", &data, ppd->Context);
                    (ppd->Callback)(&data, ppd->Context);
Robert Reif's avatar
Robert Reif committed
1130 1131
                }
            }
1132 1133

            return S_OK;
Robert Reif's avatar
Robert Reif committed
1134 1135 1136 1137 1138
        }
    }

    if (pcbReturned) {
        *pcbReturned = 0;
1139
        FIXME("*pcbReturned=%d\n", *pcbReturned);
Robert Reif's avatar
Robert Reif committed
1140 1141
    }

1142 1143 1144 1145 1146 1147 1148 1149
    return E_PROP_ID_UNSUPPORTED;
}

static HRESULT WINAPI DSPROPERTY_EnumerateA(
    LPVOID pPropData,
    ULONG cbPropData,
    PULONG pcbReturned )
{
1150 1151
    PDSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_A_DATA ppd = (PDSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_A_DATA) pPropData;
    HRESULT err;
1152
    TRACE("(pPropData=%p,cbPropData=%d,pcbReturned=%p)\n",
1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192
          pPropData,cbPropData,pcbReturned);

    if (ppd) {
        if (ppd->Callback) {
            unsigned devs, wod, wid;
            DSDRIVERDESC desc;
            DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A_DATA data;

            devs = waveOutGetNumDevs();
            for (wod = 0; wod < devs; ++wod) {
                err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,0));
                if (err == DS_OK) {
                    DWORD size;
                    err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDEVICEINTERFACESIZE,(DWORD_PTR)&size,0));
                    if (err == DS_OK) {
                        WCHAR * nameW = HeapAlloc(GetProcessHeap(),0,size);
                        if (nameW) {
                            err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDEVICEINTERFACE,(DWORD_PTR)nameW,size));
                            if (err == DS_OK) {
                                CHAR * szInterface = HeapAlloc(GetProcessHeap(),0,size/sizeof(WCHAR));
                                if (szInterface) {
                                    PIDSCDRIVER drv;
                                    ZeroMemory(&data, sizeof(data));
                                    data.DataFlow = DIRECTSOUNDDEVICE_DATAFLOW_RENDER;
                                    data.WaveDeviceId = wod;
                                    data.DeviceId = DSOUND_renderer_guids[wod];
                                    data.Description = desc.szDesc;
                                    data.Module = desc.szDrvname;
                                    WideCharToMultiByte( CP_ACP, 0, nameW, size/sizeof(WCHAR), szInterface, size/sizeof(WCHAR), NULL, NULL );
                                    data.Interface = szInterface;

                                    data.Type = DIRECTSOUNDDEVICE_TYPE_EMULATED;
                                    err = mmErr(waveOutMessage((HWAVEOUT)wod, DRV_QUERYDSOUNDIFACE, (DWORD_PTR)&drv, 0));
                                    if (err == DS_OK && drv)
                                        data.Type = DIRECTSOUNDDEVICE_TYPE_VXD;
                                    else
                                        WARN("waveOutMessage(DRV_QUERYDSOUNDIFACE) failed\n");

                                    TRACE("calling Callback(%p,%p)\n", &data, ppd->Context);
                                    (ppd->Callback)(&data, ppd->Context);
Robert Reif's avatar
Robert Reif committed
1193
                                }
1194 1195 1196 1197 1198 1199 1200
                                HeapFree(GetProcessHeap(),0,szInterface);
                            }
                        }
                        HeapFree(GetProcessHeap(),0,nameW);
                    }
                }
            }
1201

1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233
            devs = waveInGetNumDevs();
            for (wid = 0; wid < devs; ++wid) {
                err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,0));
                if (err == DS_OK) {
                    DWORD size;
                    err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDEVICEINTERFACESIZE,(DWORD_PTR)&size,0));
                    if (err == DS_OK) {
                        WCHAR * nameW = HeapAlloc(GetProcessHeap(),0,size);
                        if (nameW) {
                            err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDEVICEINTERFACE,(DWORD_PTR)nameW,size));
                            if (err == DS_OK) {
                                CHAR * szInterface = HeapAlloc(GetProcessHeap(),0,size/sizeof(WCHAR));
                                if (szInterface) {
                                    PIDSCDRIVER drv;
                                    ZeroMemory(&data, sizeof(data));
                                    data.DataFlow = DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE;
                                    data.WaveDeviceId = wid;
                                    data.DeviceId = DSOUND_capture_guids[wid];
                                    data.Description = desc.szDesc;
                                    data.Module = desc.szDrvname;
                                    WideCharToMultiByte( CP_ACP, 0, nameW, size/sizeof(WCHAR), szInterface, size/sizeof(WCHAR), NULL, NULL );
                                    data.Interface = szInterface;

                                    data.Type = DIRECTSOUNDDEVICE_TYPE_EMULATED;
                                    err = mmErr(waveInMessage((HWAVEIN)wid, DRV_QUERYDSOUNDIFACE, (DWORD_PTR)&drv, 0));
                                    if (err == DS_OK && drv)
                                        data.Type = DIRECTSOUNDDEVICE_TYPE_VXD;
                                    else
                                        WARN("waveInMessage(DRV_QUERYDSOUNDIFACE) failed\n");

                                    TRACE("calling Callback(%p,%p)\n", &data, ppd->Context);
                                    (ppd->Callback)(&data, ppd->Context);
Robert Reif's avatar
Robert Reif committed
1234
                                }
1235 1236 1237 1238 1239 1240 1241
                                HeapFree(GetProcessHeap(),0,szInterface);
                            }
                        }
                        HeapFree(GetProcessHeap(),0,nameW);
                    }
                }
            }
1242

1243 1244
            return S_OK;
        }
1245 1246 1247
    }

    if (pcbReturned) {
1248
        *pcbReturned = 0;
1249
        FIXME("*pcbReturned=%d\n", *pcbReturned);
1250
    }
1251

1252 1253 1254 1255 1256 1257 1258 1259
    return E_PROP_ID_UNSUPPORTED;
}

static HRESULT WINAPI DSPROPERTY_EnumerateW(
    LPVOID pPropData,
    ULONG cbPropData,
    PULONG pcbReturned )
{
1260 1261
    PDSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_W_DATA ppd = (PDSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_W_DATA) pPropData;
    HRESULT err;
1262
    TRACE("(pPropData=%p,cbPropData=%d,pcbReturned=%p)\n",
1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306
          pPropData,cbPropData,pcbReturned);

    if (ppd) {
        if (ppd->Callback) {
            unsigned devs, wod, wid;
            DSDRIVERDESC desc;
            DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_W_DATA data;

            devs = waveOutGetNumDevs();
            for (wod = 0; wod < devs; ++wod) {
                err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,0));
                if (err == DS_OK) {
                    WCHAR * wDescription = HeapAlloc(GetProcessHeap(),0,0x200);
                    WCHAR * wModule = HeapAlloc(GetProcessHeap(),0,0x200);
                    if (wDescription && wModule) {
                        DWORD size;
                        err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDEVICEINTERFACESIZE, (DWORD_PTR)&size, 0));
                        if (err == DS_OK) {
                            WCHAR * wInterface = HeapAlloc(GetProcessHeap(),0,size);
                            if (wInterface) {
                                err = mmErr(waveOutMessage((HWAVEOUT)wod, DRV_QUERYDEVICEINTERFACE, (DWORD_PTR)wInterface, size));
                                if (err == DS_OK) {
                                    PIDSCDRIVER drv;
                                    ZeroMemory(&data, sizeof(data));
                                    data.DataFlow = DIRECTSOUNDDEVICE_DATAFLOW_RENDER;
                                    data.WaveDeviceId = wod;
                                    data.DeviceId = DSOUND_renderer_guids[wod];

                                    MultiByteToWideChar( CP_ACP, 0, desc.szDesc, -1, wDescription, 0x100 );
                                    MultiByteToWideChar( CP_ACP, 0, desc.szDrvname, -1, wModule, 0x100 );

                                    data.Description = wDescription;
                                    data.Module = wModule;
                                    data.Interface = wInterface;

                                    data.Type = DIRECTSOUNDDEVICE_TYPE_EMULATED;
                                    err = mmErr(waveOutMessage((HWAVEOUT)wod, DRV_QUERYDSOUNDIFACE, (DWORD_PTR)&drv, 0));
                                    if (err == DS_OK && drv)
                                        data.Type = DIRECTSOUNDDEVICE_TYPE_VXD;
                                    else
                                        WARN("waveOutMessage(DRV_QUERYDSOUNDIFACE) failed\n");

                                    TRACE("calling Callback(%p,%p)\n", &data, ppd->Context);
                                    (ppd->Callback)(&data, ppd->Context);
Robert Reif's avatar
Robert Reif committed
1307
                                    }
1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351
                            }
                            HeapFree(GetProcessHeap(),0,wInterface);
                        }
                    }
                    HeapFree(GetProcessHeap(),0,wDescription);
                    HeapFree(GetProcessHeap(),0,wModule);
                }
            }

            devs = waveInGetNumDevs();
            for (wid = 0; wid < devs; ++wid) {
                err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,0));
                if (err == DS_OK) {
                    WCHAR * wDescription = HeapAlloc(GetProcessHeap(),0,0x200);
                    WCHAR * wModule = HeapAlloc(GetProcessHeap(),0,0x200);
                    if (wDescription && wModule) {
                        DWORD size;
                        err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDEVICEINTERFACESIZE, (DWORD_PTR)&size, 0));
                        if (err == DS_OK) {
                            WCHAR * wInterface = HeapAlloc(GetProcessHeap(),0,size);
                            if (wInterface) {
                                err = mmErr(waveInMessage((HWAVEIN)wid, DRV_QUERYDEVICEINTERFACE, (DWORD_PTR)wInterface, size));
                                if (err == DS_OK) {
                                    PIDSCDRIVER drv;
                                    ZeroMemory(&data, sizeof(data));
                                    data.DataFlow = DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE;
                                    data.WaveDeviceId = wid;
                                    data.DeviceId = DSOUND_capture_guids[wid];

                                    MultiByteToWideChar( CP_ACP, 0, desc.szDesc, -1, wDescription, 0x100 );
                                    MultiByteToWideChar( CP_ACP, 0, desc.szDrvname, -1, wModule, 0x100 );

                                    data.Description = wDescription;
                                    data.Module = wModule;
                                    data.Interface = wInterface;
                                    data.Type = DIRECTSOUNDDEVICE_TYPE_EMULATED;
                                    err = mmErr(waveInMessage((HWAVEIN)wid, DRV_QUERYDSOUNDIFACE, (DWORD_PTR)&drv, 0));
                                    if (err == DS_OK && drv)
                                        data.Type = DIRECTSOUNDDEVICE_TYPE_VXD;
                                    else
                                        WARN("waveInMessage(DRV_QUERYDSOUNDIFACE) failed\n");

                                    TRACE("calling Callback(%p,%p)\n", &data, ppd->Context);
                                    (ppd->Callback)(&data, ppd->Context);
Robert Reif's avatar
Robert Reif committed
1352
                                }
1353 1354 1355 1356 1357 1358 1359 1360
                            }
                            HeapFree(GetProcessHeap(),0,wInterface);
                        }
                    }
                    HeapFree(GetProcessHeap(),0,wDescription);
                    HeapFree(GetProcessHeap(),0,wModule);
                }
            }
1361

1362 1363
            return S_OK;
        }
1364 1365 1366
    }

    if (pcbReturned) {
1367
        *pcbReturned = 0;
1368
        FIXME("*pcbReturned=%d\n", *pcbReturned);
1369
    }
1370

1371 1372 1373
    return E_PROP_ID_UNSUPPORTED;
}

1374 1375 1376 1377 1378 1379 1380 1381
static HRESULT WINAPI IKsPrivatePropertySetImpl_Get(
    LPKSPROPERTYSET iface,
    REFGUID guidPropSet,
    ULONG dwPropID,
    LPVOID pInstanceData,
    ULONG cbInstanceData,
    LPVOID pPropData,
    ULONG cbPropData,
Robert Reif's avatar
Robert Reif committed
1382 1383
    PULONG pcbReturned )
{
1384
    IKsPrivatePropertySetImpl *This = (IKsPrivatePropertySetImpl *)iface;
1385
    TRACE("(iface=%p,guidPropSet=%s,dwPropID=%d,pInstanceData=%p,cbInstanceData=%d,pPropData=%p,cbPropData=%d,pcbReturned=%p)\n",
1386
          This,debugstr_guid(guidPropSet),dwPropID,pInstanceData,cbInstanceData,pPropData,cbPropData,pcbReturned);
1387 1388

    if ( IsEqualGUID( &DSPROPSETID_DirectSoundDevice, guidPropSet) ) {
1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406
        switch (dwPropID) {
        case DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_A:
            return DSPROPERTY_WaveDeviceMappingA(pPropData,cbPropData,pcbReturned);
        case DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_1:
            return DSPROPERTY_Description1(pPropData,cbPropData,pcbReturned);
        case DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_1:
            return DSPROPERTY_Enumerate1(pPropData,cbPropData,pcbReturned);
        case DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_W:
            return DSPROPERTY_WaveDeviceMappingW(pPropData,cbPropData,pcbReturned);
        case DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A:
            return DSPROPERTY_DescriptionA(pPropData,cbPropData,pcbReturned);
        case DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_W:
            return DSPROPERTY_DescriptionW(pPropData,cbPropData,pcbReturned);
        case DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_A:
            return DSPROPERTY_EnumerateA(pPropData,cbPropData,pcbReturned);
        case DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_W:
            return DSPROPERTY_EnumerateW(pPropData,cbPropData,pcbReturned);
        default:
1407
            FIXME("unsupported ID: %d\n",dwPropID);
1408 1409
            break;
        }
1410
    } else {
1411
        FIXME("unsupported property: %s\n",debugstr_guid(guidPropSet));
1412
    }
1413

1414
    if (pcbReturned) {
1415
        *pcbReturned = 0;
1416
        FIXME("*pcbReturned=%d\n", *pcbReturned);
1417
    }
1418

1419
    return E_PROP_ID_UNSUPPORTED;
1420 1421
}

1422 1423 1424 1425 1426 1427 1428 1429 1430
static HRESULT WINAPI IKsPrivatePropertySetImpl_Set(
    LPKSPROPERTYSET iface,
    REFGUID guidPropSet,
    ULONG dwPropID,
    LPVOID pInstanceData,
    ULONG cbInstanceData,
    LPVOID pPropData,
    ULONG cbPropData )
{
1431
    IKsPrivatePropertySetImpl *This = (IKsPrivatePropertySetImpl *)iface;
1432

1433
    FIXME("(%p,%s,%d,%p,%d,%p,%d), stub!\n",This,debugstr_guid(guidPropSet),dwPropID,pInstanceData,cbInstanceData,pPropData,cbPropData);
1434
    return E_PROP_ID_UNSUPPORTED;
1435 1436
}

1437 1438 1439 1440 1441 1442
static HRESULT WINAPI IKsPrivatePropertySetImpl_QuerySupport(
    LPKSPROPERTYSET iface,
    REFGUID guidPropSet,
    ULONG dwPropID,
    PULONG pTypeSupport )
{
1443
    IKsPrivatePropertySetImpl *This = (IKsPrivatePropertySetImpl *)iface;
1444
    TRACE("(%p,%s,%d,%p)\n",This,debugstr_guid(guidPropSet),dwPropID,pTypeSupport);
1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472

    if ( IsEqualGUID( &DSPROPSETID_DirectSoundDevice, guidPropSet) ) {
	switch (dwPropID) {
	case DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_A:
	    *pTypeSupport = KSPROPERTY_SUPPORT_GET;
	    return S_OK;
	case DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_1:
	    *pTypeSupport = KSPROPERTY_SUPPORT_GET;
	    return S_OK;
	case DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_1:
	    *pTypeSupport = KSPROPERTY_SUPPORT_GET;
	    return S_OK;
	case DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_W:
	    *pTypeSupport = KSPROPERTY_SUPPORT_GET;
	    return S_OK;
	case DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A:
	    *pTypeSupport = KSPROPERTY_SUPPORT_GET;
	    return S_OK;
	case DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_W:
	    *pTypeSupport = KSPROPERTY_SUPPORT_GET;
	    return S_OK;
	case DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_A:
	    *pTypeSupport = KSPROPERTY_SUPPORT_GET;
	    return S_OK;
	case DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_W:
	    *pTypeSupport = KSPROPERTY_SUPPORT_GET;
	    return S_OK;
	default:
1473
            FIXME("unsupported ID: %d\n",dwPropID);
1474 1475 1476 1477 1478
	    break;
	}
    } else {
	FIXME("unsupported property: %s\n",debugstr_guid(guidPropSet));
    }
1479

1480
    return E_PROP_ID_UNSUPPORTED;
1481 1482
}

1483
static const IKsPropertySetVtbl ikspvt = {
1484 1485 1486 1487 1488 1489
    IKsPrivatePropertySetImpl_QueryInterface,
    IKsPrivatePropertySetImpl_AddRef,
    IKsPrivatePropertySetImpl_Release,
    IKsPrivatePropertySetImpl_Get,
    IKsPrivatePropertySetImpl_Set,
    IKsPrivatePropertySetImpl_QuerySupport
1490 1491
};

1492
HRESULT IKsPrivatePropertySetImpl_Create(
1493
    REFIID riid,
1494
    IKsPrivatePropertySetImpl **piks)
1495
{
1496
    IKsPrivatePropertySetImpl *iks;
1497 1498 1499 1500 1501 1502 1503
    TRACE("(%s, %p)\n", debugstr_guid(riid), piks);

    if (!IsEqualIID(riid, &IID_IUnknown) &&
        !IsEqualIID(riid, &IID_IKsPropertySet)) {
        *piks = 0;
        return E_NOINTERFACE;
    }
1504

1505
    iks = HeapAlloc(GetProcessHeap(),0,sizeof(*iks));
1506
    iks->ref = 1;
1507
    iks->lpVtbl = &ikspvt;
1508

1509 1510
    *piks = iks;
    return S_OK;
1511
}