Problem using waveInOpen from VB.NET

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm having a problem calling waveInOpen from a VB.NET application, every time
I call it I get a return value of 11 which is MMSYSERR_INVALPARAM.

I can call waveInGetNumDevs and waveInGetDevCaps just fine. Below is the
format of the waveInOpen call and WaveFormatEx structure.

<DllImport("winmm.dll", SetLastError:=False, ExactSpelling:=True)> _
Public Shared Function waveInOpen(ByVal lphWaveIn As Int32 _
, ByVal uDeviceID As Int32 _
, ByRef lpFormat As APIStructures.WaveFormatEx _
, ByVal dwCallback As Int32 _
, ByVal dwInstance As Int32 _
, ByVal dwFlags As Int32) As Int32
End Function

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto, Pack:=1)> _
Public Structure WaveFormatEx
Public FormatTag As Int16
Public Channels As Int16
Public SamplesPerSec As Int32
Public AvgBytesPerSec As Int32
Public BlockAlign As Int16
Public BitsPerSample As Int16
Public ExtraDataSize As Int16
End Structure

A sample solution is available upon request. Any help would be much
appreciated.
 
Fred,
<DllImport("winmm.dll", SetLastError:=False, ExactSpelling:=True)> _
Public Shared Function waveInOpen(ByVal lphWaveIn As Int32 _
, ByVal uDeviceID As Int32 _
, ByRef lpFormat As APIStructures.WaveFormatEx _
, ByVal dwCallback As Int32 _
, ByVal dwInstance As Int32 _
, ByVal dwFlags As Int32) As Int32
End Function

Try it like this

<DllImport("winmm.dll", SetLastError:=False, ExactSpelling:=True)> _
Public Shared Function waveInOpen(ByRef lphWaveIn As IntPtr _
, ByVal uDeviceID As IntPtr _
, ByRef lpFormat As APIStructures.WaveFormatEx _
, ByVal dwCallback As IntPtr _
, ByVal dwInstance As IntPtr _
, ByVal dwFlags As Int32) As Int32
End Function



Mattias
 
Thanks for the change, I updated the app to use IntPtr for the device handle
instead of Int32s and it worked the first time.

Thanks again for the hugh help!
 
Back
Top