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

[RESOLVED] Invalid used of AddressOf operator

$
0
0
First time this has ever happened and the exact same code is in another project without the error.

Here is the Sub code that invokes the AddressOf

Code:

Public Function StartRecord(ByVal samplerate As Long, ByVal Channels As Integer) As Boolean
 Dim udtWFX  As WAVEFORMATEX
 Dim res    As Long
 Dim i      As Long
 Dim j      As Long

 ReDim udtBuffers(lngBufCnt - 1) As WaveInBuffer

 With udtWFX
  .wFormatTag = WAVE_FORMAT_PCM
  .nSamplesPerSec = samplerate
  .nChannels = Channels
  .wBitsPerSample = 16
  .nBlockAlign = Channels * (.wBitsPerSample / 8)
  .nAvgBytesPerSec = .nBlockAlign * .nSamplesPerSec
  .cbSize = 0
 End With

 Const CALLBACK_FUNCTION = &H30000
 res = waveInOpen(hWaveIn, lngCurDev, udtWFX, AddressOf waveInProc, 0, CALLBACK_FUNCTION)
   
 If res <> MMSYSERR_NOERROR Then
  DeinitWaveInWnd
  Exit Function
 End If

 ' prepare headers/buffers
 For i = 0 To lngBufCnt - 1
  With udtBuffers(i)
    ReDim .intBuffer(lngBufSize / 2 - 1) As Integer
   
    .pMem = VarPtr(.intBuffer(0))
    .hdr.dwBufferLen = lngBufSize
    .hdr.lpData = .pMem
    .hdr.dwUser = i

    res = waveInPrepareHeader(hWaveIn, .hdr, Len(.hdr))
           
    If res <> MMSYSERR_NOERROR Then
      ' on error unprepare all prepared headers
      For j = (i - 1) To 0 Step -1
        waveInUnprepareHeader hWaveIn, .hdr, Len(.hdr)
      Next

      waveInClose hWaveIn
      hWaveIn = 0

      DeinitWaveInWnd

      Exit Function
    End If
  End With
 Next

 res = waveInStart(hWaveIn)
   
 If res <> MMSYSERR_NOERROR Then
  For i = 0 To lngBufCnt - 1
    waveInUnprepareHeader hWaveIn, udtBuffers(i).hdr, Len(udtBuffers(i).hdr)
  Next

  waveInClose hWaveIn
  hWaveIn = 0

  DeinitWaveInWnd

  Exit Function
 End If

 For i = 0 To lngBufCnt - 1
  waveInAddBuffer hWaveIn, udtBuffers(i).hdr, Len(udtBuffers(i).hdr)
 Next

 StartRecord = True
End Function

Here is the Callback proc

Code:

Public Sub waveInProc(ByVal hwi As Long, _
                      ByVal uMsg As Long, _
                      ByVal dwInstance As Long, _
                      ByVal dwParam1 As Long, _
                      ByVal dwParam2 As Long)

 Dim udtHdr As WAVEHDR

 If RecordingStopped = True Then Exit Sub

 Select Case uMsg
  Case MM_WIM_DATA
    CopyMemory udtHdr, ByVal dwParam1, ByVal Len(udtHdr)

    intSamples = udtBuffers(udtHdr.dwUser).intBuffer

    lngMSEncoded = lngMSEncoded + ((udtHdr.dwBytesRecorded / lngBytesPerSec) * 1000)

    waveInAddBuffer ByVal hWaveIn, udtBuffers(udtHdr.dwUser), ByVal Len(udtHdr)
 End Select
End Sub

Both Subs are in a Class module

Error message occurs when Sub StartRecord is first called at the beginning of the sub

Viewing all articles
Browse latest Browse all 21089

Trending Articles



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