diff --git a/gstdirectsoundsink.c b/gstdirectsoundsink.c
index 56b0418..421a317 100755
--- a/gstdirectsoundsink.c
+++ b/gstdirectsoundsink.c
@@ -540,7 +540,7 @@ gst_directsound_sink_write (GstAudioSink * asink, gpointer data, guint length)
 {
   GstDirectSoundSink *dsoundsink;
   DWORD dwStatus;
-  HRESULT hRes;
+  HRESULT hRes, hRes2;
   LPVOID pLockedBuffer1 = NULL, pLockedBuffer2 = NULL;
   DWORD dwSizeBuffer1, dwSizeBuffer2;
   DWORD dwCurrentPlayCursor;
@@ -553,13 +553,14 @@ gst_directsound_sink_write (GstAudioSink * asink, gpointer data, guint length)
   hRes = IDirectSoundBuffer_GetStatus (dsoundsink->pDSBSecondary, &dwStatus);
 
   /* get current play cursor position */
-  hRes = IDirectSoundBuffer_GetCurrentPosition (dsoundsink->pDSBSecondary,
+  hRes2 = IDirectSoundBuffer_GetCurrentPosition (dsoundsink->pDSBSecondary,
       &dwCurrentPlayCursor, NULL);
 
-  if (SUCCEEDED (hRes) && (dwStatus & DSBSTATUS_PLAYING)) {
+  if (SUCCEEDED (hRes) && SUCCEEDED (hRes2) && (dwStatus & DSBSTATUS_PLAYING)) {
     DWORD dwFreeBufferSize;
 
   calculate_freesize:
+      
     /* calculate the free size of the circular buffer */
     if (dwCurrentPlayCursor < dsoundsink->current_circular_offset)
       dwFreeBufferSize =
@@ -574,9 +575,9 @@ gst_directsound_sink_write (GstAudioSink * asink, gpointer data, guint length)
       hRes = IDirectSoundBuffer_GetCurrentPosition (dsoundsink->pDSBSecondary,
           &dwCurrentPlayCursor, NULL);
 
-      hRes =
+      hRes2 =
           IDirectSoundBuffer_GetStatus (dsoundsink->pDSBSecondary, &dwStatus);
-      if (SUCCEEDED (hRes) && (dwStatus & DSBSTATUS_PLAYING))
+      if (SUCCEEDED (hRes) && SUCCEEDED (hRes2) && (dwStatus & DSBSTATUS_PLAYING))
         goto calculate_freesize;
       else {
         dsoundsink->first_buffer_after_reset = FALSE;
@@ -584,6 +585,7 @@ gst_directsound_sink_write (GstAudioSink * asink, gpointer data, guint length)
         return 0;
       }
     }
+    
   }
 
   if (dwStatus & DSBSTATUS_BUFFERLOST) {
@@ -640,7 +642,7 @@ gst_directsound_sink_delay (GstAudioSink * asink)
   /* get current buffer status */
   hRes = IDirectSoundBuffer_GetStatus (dsoundsink->pDSBSecondary, &dwStatus);
 
-  if (dwStatus & DSBSTATUS_PLAYING) {
+  if (SUCCEEDED (hRes) && (dwStatus & DSBSTATUS_PLAYING)) {
     /*evaluate the number of samples in queue in the circular buffer */
     hRes = IDirectSoundBuffer_GetCurrentPosition (dsoundsink->pDSBSecondary,
         &dwCurrentPlayCursor, NULL);
@@ -675,7 +677,7 @@ gst_directsound_sink_reset (GstAudioSink * asink)
   if (dsoundsink->pDSBSecondary) {
     /*stop playing */
     HRESULT hRes = IDirectSoundBuffer_Stop (dsoundsink->pDSBSecondary);
-
+    
     /*reset position */
     hRes = IDirectSoundBuffer_SetCurrentPosition (dsoundsink->pDSBSecondary, 0);
     dsoundsink->current_circular_offset = 0;
@@ -687,11 +689,11 @@ gst_directsound_sink_reset (GstAudioSink * asink)
 
     if (SUCCEEDED (hRes)) {
       memset (pLockedBuffer, 0, dwSizeBuffer);
-
+      
       hRes =
           IDirectSoundBuffer_Unlock (dsoundsink->pDSBSecondary, pLockedBuffer,
           dwSizeBuffer, NULL, 0);
-    }
+      }
   }
 
   dsoundsink->first_buffer_after_reset = TRUE;
