Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    waveInStart problematica

    Sono un appassionato cultore di programmazione a livello amatoriale, ma devo ancora fare moltissima strada...

    Sono arrivato faticosamente a "decifrare" le API della serie "waveIn", ma adesso mi trovo di fronte a un problema che mi sta facendo diventare matto a proposito della funzione waveInStart in VB6. Dopo averla usata ottengo sempre un crash, sia in Vista sia in XP, sia in Win98, per cui credo che il problema sia in qualche mio errore, e non in qualcosa relativo al sistema operativo usato.
    Sul notebook con XP ottengo l'apertura di Visual C++ per il debugging, e qui mi appare una messageBox con scritto "Violazione di accesso..." seguita da un numero a 32 bit, mentre sul notebook con Vista il programma si "pianta" solamente, la finestra si opaca e quindi appare una finestra con scritto "il programma ha smesso di funzionare".

    Il codice è:
    <pre>
    Dim Caps As WAVEINCAPS
    Dim format As WAVEFORMATEX
    Dim Wave As WAVEHDR
    Const DEVICEID = 0
    Dim hWaveIn As Long
    Dim rc As Long
    Dim Buffer(0 To 511) As Byte


    ....qui vi sono tutte le strutture, le costanti, le dichiarazioni delle funzioni API...



    Private Sub Command1_Click()
    rc = waveInStart(hWaveIn)
    Debug.Print "Codice di errore di waveInStart: " & rc
    Sleep (10000)
    MsgBox "finito"
    End Sub




    Private Sub Form_Load()
    rc = waveInGetDevCaps(0, Caps, Len(Caps))
    Debug.Print "Codice di errore di waveInGetDevCaps: " & rc
    Debug.Print "nome del dispositivo: " & Caps.szPname

    'riempiamo la struttura WAVEFORMATEX
    format.wFormatTag = 1
    format.nChannels = 2
    format.wBitsPerSample = 16
    format.nSamplesPerSec = 44100
    format.nBlockAlign = format.nChannels * format.wBitsPerSample / 8
    format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign
    format.cbSize = 0

    'riempiamo la struttura WAVEHDR
    Wave.lpData = Buffer(0)
    Wave.dwBufferLength = 512
    Wave.dwFlags = 0

    rc = waveInOpen(hWaveIn, DEVICEID, format, 0, 0, 0)
    Debug.Print hWaveIn
    Debug.Print "codice errore di waveInOpen: " & rc

    rc = waveInPrepareHeader(hWaveIn, Wave, Len(Wave))
    Debug.Print "codice errore di waveInPrepareHeader: " & rc

    rc = waveInAddBuffer(hWaveIn, Wave, Len(Wave))
    Debug.Print "Codice di errore di waveInAddBuffer: " & rc

    End Sub
    </pre>
    Qualcuno può darmi qualche suggerimento in proposito?
    Grazie in anticipo

  2. #2
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,481
    Mancano le dichiarazioni delle API che hai usato ...

    E comunque questa

    Wave.lpData = Buffer(0)

    dovrebbe essere

    Wave.lpData = VarPtr( Buffer(0) )

    dato che lpData e' un puntatore al Buffer

    P.S. Usa i tag CODE e /CODE e non pre /pre
    No MP tecnici (non rispondo nemmeno!), usa il forum.

  3. #3
    Ecco: ho apportato la correzione (sì, in effetti l'avevo proprio dimenticata!), ma il problema resta ugualmente...
    Ecco tutto il codice del Form:


    Dim Caps As WAVEINCAPS
    Dim format As WAVEFORMATEX
    Dim Wave As WAVEHDR
    Const DEVICEID = 0
    Dim hWaveIn As Long
    Dim rc As Long
    Dim Buffer(0 To 511) As Byte

    'COSTANTI

    Private Const MAXPNAMELEN = 32 ' lunghezza max nome prodotto (incluso NULL)


    'STRUTTURE

    Private Type WAVEINCAPS
    wMid As Integer
    wPid As Integer
    vDriverVersion As Long
    szPname As String * MAXPNAMELEN
    dwFormats As Long
    wChannels As Integer
    End Type

    Private Type WAVEFORMATEX
    wFormatTag As Integer
    nChannels As Integer
    nSamplesPerSec As Long
    nAvgBytesPerSec As Long
    nBlockAlign As Integer
    wBitsPerSample As Integer
    cbSize As Integer
    End Type

    Private Type WAVEHDR
    lpData As String
    dwBufferLength As Long
    dwBytesRecorded As Long
    dwUser As Long
    dwFlags As Long
    dwLoops As Long
    lpNext As Long
    Reserved As Long
    End Type


    'DICHIARAZIONI API

    Private Declare Function waveInGetDevCaps Lib "winmm.dll" Alias "waveInGetDevCapsA" (ByVal uDeviceID As Long, lpCaps As WAVEINCAPS, ByVal uSize As Long) As Long
    Private Declare Function waveInOpen Lib "winmm.dll" (lphWaveIn As Long, ByVal uDeviceID As Long, lpFormat As WAVEFORMATEX, ByVal dwCallback As Long, ByVal dwInstance As Long, ByVal dwFlags As Long) As Long
    Private Declare Function waveInPrepareHeader Lib "winmm.dll" (ByVal hWaveIn As Long, lpWaveInHdr As WAVEHDR, ByVal uSize As Long) As Long
    Private Declare Function waveInAddBuffer Lib "winmm.dll" (ByVal hWaveIn As Long, lpWaveInHdr As WAVEHDR, ByVal uSize As Long) As Long
    Private Declare Function waveInStart Lib "winmm.dll" (ByVal hWaveIn As Long) As Long
    Private Declare Function waveInUnprepareHeader Lib "winmm.dll" (ByVal hWaveIn As Long, lpWaveInHdr As WAVEHDR, ByVal uSize As Long) As Long
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)


    Private Sub Command1_Click()
    rc = waveInStart(hWaveIn)
    Debug.Print "Codice di errore di waveInStart: " & rc
    Sleep (10000)
    MsgBox "finito"
    End Sub

    Private Sub Form_Load()

    rc = waveInGetDevCaps(0, Caps, Len(Caps))
    Debug.Print "Codice di errore di waveInGetDevCaps: " & rc
    Debug.Print "nome del dispositivo: " & Caps.szPname

    'riempiamo la struttura WAVEFORMATEX
    format.wFormatTag = 1
    format.nChannels = 2
    format.wBitsPerSample = 16
    format.nSamplesPerSec = 44100
    format.nBlockAlign = format.nChannels * format.wBitsPerSample / 8
    format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign
    format.cbSize = 0

    'riempiamo la struttura WAVEHDR
    Wave.lpData = VarPtr(Buffer(0))
    Wave.dwBufferLength = 512
    Wave.dwFlags = 0

    rc = waveInOpen(hWaveIn, DEVICEID, format, 0, 0, 0)
    Debug.Print hWaveIn
    Debug.Print "codice errore di open: " & rc
    rc = waveInPrepareHeader(hWaveIn, Wave, Len(Wave))
    Debug.Print "codice errire di prepareHeader: " & rc

    rc = waveInAddBuffer(hWaveIn, Wave, Len(Wave))
    Debug.Print "Codice di errore di waveInAddBuffer: " & rc

    End Sub


    Per brevità avevo voluto "stringerlo" un po' , ma sì, è meglio metterlo per esteso...

  4. #4
    Ehmmmm.... mi sta venendo in mente che forse il problema sta nel fatto che non ho allocato memoria per il buffer... sto investigando sulle funzioni che allocano memoria extra (heap)... chissà che non venga a capo di qualcosa... BOH?

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.