Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21127

Callback Sub causes App to crash on Form_Unload

$
0
0
Everytime I unload the app it crashes. I have narrowed it down to code in a callback sub but for the likes of me I can't understand why the code will cause the crash.

Here is the callback sub in a BAS module

Code:

Public Sub WaveCallbackProc(ByVal hwi As Long, _
                            ByVal uMsg As Long, _
                            ByVal dwInstance As Long, _
                            ByVal dwParam1 As Long, _
                            ByVal dwParam2 As Long)
 
 Select Case uMsg
  Case MM_WIM_OPEN
    ' Here when waveInOpen called

 
  Case MM_WIM_DATA
    ' Here when sound buffer is full
 
  Case MM_WIM_CLOSE
    ' Here when waveInClose called
 
  Case MM_WOM_OPEN
    ' Here when waveOutOpen called
 
  Case MM_WOM_DONE
    'Here when sound buffer has finished or empty

    Form1.Timer1.Enabled = False
    Form1.picFreq(0).Cls
    Form1.picFreq(1).Cls
    Form1.Command2.Enabled = False
    Form1.Command1.Enabled = True
   
  Case MM_WOM_CLOSE
    ' Here when waveOutClose called

 End Select
End Sub

Here is the Form_Unload

Code:

Private Sub Form_Unload(Cancel As Integer)
 Timer1.Enabled = False
End Sub

Here is the Timer Sub

Code:

Private Sub MyTmrVis_Timer()
 On Error GoTo ER

 CopyMemory intSamples(0), WavSound(iOffset), FFT_SAMPLES
 
 iOffset = iOffset + FFT_SAMPLES
 
 DrawFrequencies intSamples, picFreq(0), picFreq(1)

 Exit Sub
ER:
 Form1.MyTmrVis.Enabled = False
 Form1.picFreq(0).Cls
 Form1.picFreq(1).Cls
 Form1.Command2.Enabled = False
 Form1.Command1.Enabled = True
 CloseWaveOut
End Sub

In all cases I have not unloaded the App until after the code in the callback had finished so that means I do not kill app during the sound out (playing) time.

The only error that could occur in the timer sub is an index out of bounds but in the case of my testing that does not occur because the size of the WavSound buffer is exactly divisible by FFT_SAMPLES so I never get an odd results which would cause the CopyMemory function to fail and it is in sync with the callback sub which means that the callback at Case MM_WOM_DONE is executed when the last chunk has be extracted from the buffer in the timer event.

Viewing all articles
Browse latest Browse all 21127

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>