dsound initialization patch

Robert Reif reif at earthlink.net
Sun Jul 18 21:54:43 CDT 2004


Do initialization to match windows behavior (with test).
-------------- next part --------------
Index: dlls/dsound/dsound.c
===================================================================
RCS file: /home/wine/wine/dlls/dsound/dsound.c,v
retrieving revision 1.5
diff -u -r1.5 dsound.c
--- dlls/dsound/dsound.c	13 Jul 2004 23:35:09 -0000	1.5
+++ dlls/dsound/dsound.c	19 Jul 2004 02:50:22 -0000
@@ -303,6 +303,11 @@
         return DSERR_INVALIDPARAM;
     }
 
+    if (This->initialized == FALSE) {
+        WARN("not initialized\n");
+        return DSERR_UNINITIALIZED;
+    }
+
     if (dsbd == NULL) {
         WARN("invalid parameter: dsbd == NULL\n");
         return DSERR_INVALIDPARAM;
@@ -379,6 +384,11 @@
         return DSERR_INVALIDPARAM;
     }
 
+    if (This->initialized == FALSE) {
+        WARN("not initialized\n");
+        return DSERR_UNINITIALIZED;
+    }
+
     if (lpDSCaps == NULL) {
         WARN("invalid parameter: lpDSCaps = NULL\n");
         return DSERR_INVALIDPARAM;
@@ -436,6 +446,11 @@
         return DSERR_INVALIDPARAM;
     }
 
+    if (This->initialized == FALSE) {
+        WARN("not initialized\n");
+        return DSERR_UNINITIALIZED;
+    }
+
     if (psb == NULL) {
         WARN("invalid parameter: psb == NULL\n");
         return DSERR_INVALIDPARAM;
@@ -577,6 +592,11 @@
     ICOM_THIS(IDirectSoundImpl,iface);
     TRACE("(%p, %p)\n",This,lpdwSpeakerConfig);
 
+    if (This->initialized == FALSE) {
+        WARN("not initialized\n");
+        return DSERR_UNINITIALIZED;
+    }
+
     if (lpdwSpeakerConfig == NULL) {
         WARN("invalid parameter: lpdwSpeakerConfig == NULL\n");
         return DSERR_INVALIDPARAM;
@@ -594,6 +614,11 @@
     ICOM_THIS(IDirectSoundImpl,iface);
     TRACE("(%p,0x%08lx)\n",This,config);
 
+    if (This->initialized == FALSE) {
+        WARN("not initialized\n");
+        return DSERR_UNINITIALIZED;
+    }
+
     This->speaker_config = config;
     WARN("not fully functional\n");
     return DS_OK;
@@ -606,6 +631,8 @@
     ICOM_THIS(IDirectSoundImpl,iface);
     TRACE("(%p,%s)\n",This,debugstr_guid(lpcGuid));
 
+    This->initialized = TRUE;
+
     return DS_OK;
 }
 
@@ -616,6 +643,11 @@
     ICOM_THIS(IDirectSoundImpl,iface);
     TRACE("(%p, %p)\n",This,pdwCertified);
 
+    if (This->initialized == FALSE) {
+        WARN("not initialized\n");
+        return DSERR_UNINITIALIZED;
+    }
+
     if (This->drvcaps.dwFlags & DSCAPS_CERTIFIED)
         *pdwCertified = DS_CERTIFIED;
     else
@@ -718,6 +750,7 @@
     pDS->buffers        = NULL;
     pDS->primary        = NULL;
     pDS->speaker_config = DSSPEAKER_STEREO | (DSSPEAKER_GEOMETRY_NARROW << 16);
+    pDS->initialized    = FALSE;
 
     /* 3D listener initial parameters */
     pDS->listener       = NULL;
@@ -1524,22 +1557,7 @@
     return DS_OK;
 }
 
-/*******************************************************************************
- *		DirectSoundCreate (DSOUND.1)
- *
- *  Creates and initializes a DirectSound interface.
- *
- *  PARAMS
- *     lpcGUID   [I] Address of the GUID that identifies the sound device.
- *     ppDS      [O] Address of a variable to receive the interface pointer.
- *     pUnkOuter [I] Must be NULL.
- *
- *  RETURNS
- *     Success: DS_OK
- *     Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
- *              DSERR_NODRIVER, DSERR_OUTOFMEMORY
- */
-HRESULT WINAPI DirectSoundCreate(
+HRESULT WINAPI DSOUND_Create(
     LPCGUID lpcGUID,
     LPDIRECTSOUND *ppDS,
     IUnknown *pUnkOuter)
@@ -1549,6 +1567,11 @@
 
     TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID),ppDS,pUnkOuter);
 
+    if (pUnkOuter != NULL) {
+        WARN("invalid parameter: pUnkOuter != NULL\n");
+        return DSERR_INVALIDPARAM;
+    }
+
     if (ppDS == NULL) {
         WARN("invalid parameter: ppDS == NULL\n");
         return DSERR_INVALIDPARAM;
@@ -1609,9 +1632,9 @@
 }
 
 /*******************************************************************************
- *        DirectSoundCreate8 (DSOUND.11)
+ *		DirectSoundCreate (DSOUND.1)
  *
- *  Creates and initializes a DirectSound8 interface.
+ *  Creates and initializes a DirectSound interface.
  *
  *  PARAMS
  *     lpcGUID   [I] Address of the GUID that identifies the sound device.
@@ -1623,7 +1646,23 @@
  *     Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
  *              DSERR_NODRIVER, DSERR_OUTOFMEMORY
  */
-HRESULT WINAPI DirectSoundCreate8(
+HRESULT WINAPI DirectSoundCreate(
+    LPCGUID lpcGUID,
+    LPDIRECTSOUND *ppDS,
+    IUnknown *pUnkOuter)
+{
+    HRESULT hr;
+
+    TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID),ppDS,pUnkOuter);
+
+    hr = DSOUND_Create(lpcGUID, ppDS, pUnkOuter);
+    if (hr == DS_OK)
+        IDirectSoundImpl_Initialize((LPDIRECTSOUND8)dsound, lpcGUID);
+
+    return hr;
+}
+
+HRESULT WINAPI DSOUND_Create8(
     LPCGUID lpcGUID,
     LPDIRECTSOUND8 *ppDS,
     IUnknown *pUnkOuter)
@@ -1633,6 +1672,11 @@
 
     TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID),ppDS,pUnkOuter);
 
+    if (pUnkOuter != NULL) {
+        WARN("invalid parameter: pUnkOuter != NULL\n");
+        return DSERR_INVALIDPARAM;
+    }
+
     if (ppDS == NULL) {
         WARN("invalid parameter: ppDS == NULL\n");
         return DSERR_INVALIDPARAM;
@@ -1688,6 +1732,37 @@
         } else
             WARN("IDirectSoundImpl_Create failed\n");
     }
+
+    return hr;
+}
+
+/*******************************************************************************
+ *        DirectSoundCreate8 (DSOUND.11)
+ *
+ *  Creates and initializes a DirectSound8 interface.
+ *
+ *  PARAMS
+ *     lpcGUID   [I] Address of the GUID that identifies the sound device.
+ *     ppDS      [O] Address of a variable to receive the interface pointer.
+ *     pUnkOuter [I] Must be NULL.
+ *
+ *  RETURNS
+ *     Success: DS_OK
+ *     Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
+ *              DSERR_NODRIVER, DSERR_OUTOFMEMORY
+ */
+HRESULT WINAPI DirectSoundCreate8(
+    LPCGUID lpcGUID,
+    LPDIRECTSOUND8 *ppDS,
+    IUnknown *pUnkOuter)
+{
+    HRESULT hr;
+
+    TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID),ppDS,pUnkOuter);
+
+    hr = DSOUND_Create8(lpcGUID, ppDS, pUnkOuter);
+    if (hr == DS_OK)
+        IDirectSoundImpl_Initialize((LPDIRECTSOUND8)dsound, lpcGUID);
 
     return hr;
 }
Index: dlls/dsound/dsound_main.c
===================================================================
RCS file: /home/wine/wine/dlls/dsound/dsound_main.c,v
retrieving revision 1.101
diff -u -r1.101 dsound_main.c
--- dlls/dsound/dsound_main.c	6 Jul 2004 19:25:59 -0000	1.101
+++ dlls/dsound/dsound_main.c	19 Jul 2004 02:50:23 -0000
@@ -478,10 +478,10 @@
 	*ppobj = NULL;
 
 	if ( IsEqualIID( &IID_IDirectSound, riid ) )
-		return DirectSoundCreate(0,(LPDIRECTSOUND*)ppobj,pOuter);
+		return DSOUND_Create(0,(LPDIRECTSOUND*)ppobj,pOuter);
 
 	if ( IsEqualIID( &IID_IDirectSound8, riid ) )
-		return DirectSoundCreate8(0,(LPDIRECTSOUND8*)ppobj,pOuter);
+		return DSOUND_Create8(0,(LPDIRECTSOUND8*)ppobj,pOuter);
 
 	WARN("(%p,%p,%s,%p) Interface not found!\n",This,pOuter,debugstr_guid(riid),ppobj);	
 	return E_NOINTERFACE;
Index: dlls/dsound/dsound_private.h
===================================================================
RCS file: /home/wine/wine/dlls/dsound/dsound_private.h,v
retrieving revision 1.17
diff -u -r1.17 dsound_private.h
--- dlls/dsound/dsound_private.h	13 Jul 2004 23:35:09 -0000	1.17
+++ dlls/dsound/dsound_private.h	19 Jul 2004 02:50:24 -0000
@@ -95,6 +95,7 @@
     PrimaryBufferImpl*          primary;
     DSBUFFERDESC                dsbd;
     DWORD                       speaker_config;
+    BOOL                        initialized;
 
     /* DirectSound3DListener fields */
     IDirectSound3DListenerImpl*	listener;
@@ -116,6 +117,16 @@
 HRESULT WINAPI IDirectSoundImpl_Create(
     LPCGUID lpcGUID,
     LPDIRECTSOUND8 * ppds);
+
+HRESULT WINAPI DSOUND_Create(
+    LPCGUID lpcGUID,
+    LPDIRECTSOUND *ppDS,
+    IUnknown *pUnkOuter);
+
+HRESULT WINAPI DSOUND_Create8(
+    LPCGUID lpcGUID,
+    LPDIRECTSOUND8 *ppDS,
+    IUnknown *pUnkOuter);
 
 /*****************************************************************************
  * IDirectSound COM components
Index: dlls/dsound/tests/dsound.c
===================================================================
RCS file: /home/wine/wine/dlls/dsound/tests/dsound.c,v
retrieving revision 1.27
diff -u -r1.27 dsound.c
--- dlls/dsound/tests/dsound.c	17 Jul 2004 00:04:17 -0000	1.27
+++ dlls/dsound/tests/dsound.c	19 Jul 2004 02:50:24 -0000
@@ -69,6 +69,10 @@
         if (rc==DS_OK)
             IDirectSound8_Release(ds8);
 
+        /* try unitialized object */
+        rc=IDirectSound_GetCaps(dso,0);
+        ok(rc==DSERR_UNINITIALIZED,"GetCaps should have returned DSERR_UNINITIALIZED, returned: %s\n",DXGetErrorString9(rc));
+
         rc=IDirectSound_Initialize(dso,NULL);
         ok(rc==DS_OK,"IDirectSound_Initialize(NULL) failed: %s\n",DXGetErrorString9(rc));
 
@@ -171,6 +175,10 @@
         if (rc==DS_OK)
             IDirectSound8_Release(ds8);
 
+        /* try unitialized object */
+        rc=IDirectSound8_GetCaps(dso,0);
+        ok(rc==DSERR_UNINITIALIZED,"GetCaps should have returned DSERR_UNINITIALIZED, returned: %s\n",DXGetErrorString9(rc));
+
         rc=IDirectSound8_Initialize(dso,NULL);
         ok(rc==DS_OK,"IDirectSound_Initialize(NULL) failed: %s\n",DXGetErrorString9(rc));
 


More information about the wine-patches mailing list