Problème avec WaveInAddBuffer en VB.net
Bonjour,
Je voudrais écrire un programme accordeur qui donne la fréquence d'un son joué devant un micro, en visual basic 2010 sous Windows 7 familial sur un PC 64 bits. Voici un extrait du programme :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| Public LongWhdr As Int32
Public Phwi As Int32
Public Structure WaveHdr
Public lpData As Int32
Public dwBufferLength As Int32
Public dwBytesRecorded As Int32
Public dwUser As Int32
Public dwFlags As Int32
Public dwLoops As Int32
Public lpNext As Int32
Public Reserved As Int32
End Structure
Public Xwhdr As WaveHdr
Public Whdr(0 To 1) As WaveHdr
Public Declare Function waveInAddBuffer Lib "winmm.dll" (ByVal hWaveIn As Int32, ByRef lpWaveInHdr As WaveHdr, ByVal uSize As Int32) As Int32
Public Declare Function waveInOpen Lib "winmm.dll" (ByRef lphWaveIn As Int32, ByVal uDeviceID As Int32, ByRef lpFormat As WaveFormatex, ByVal dwCallback As Int32, ByVal dwInstance As Int32, ByVal dwFlags As Int32) As Int32
Public Declare Function waveInPrepareHeader Lib "winmm.dll" (ByVal hWaveIn As Int32, ByRef lpWaveInHdr As WaveHdr, ByVal uSize As Int32) As Int32
LongWhdr = Len(Xwhdr)
Res = waveInOpen(Phwi, No_Periph, Wfe, Evt, 0, CallBack_Event)
Lig = "WaveInOpen"
Debug.Print(Lig)
Res = waveInPrepareHeader(Phwi, Whdr(0), LongWhdr)
Lig = " Res prepare " & Str(Res) & " " & Res.ToString
Debug.Print(Lig)
Res = waveInAddBuffer(Phwi, Whdr(0), LongWhdr)
Lig = "waveInAddBuffer 0 " & Str(Res) & " " & Res.ToString
Debug.Print (Lig) |
J'obtiens bien les deux premiers debug "mouchards", puis je suis bloqué à la dernière instruction waveInAddBuffer sur le message:
Citation:
A first chance exception of type 'System.AccessViolationException' occurred in Accordeur.exe
Que se passe t-il ? Comment avancer ? Merci à tous ceux qui ont une idée.