Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

waveInGetNumDevs

12 views
Skip to first unread message

bretts...@hotmail.com

unread,
Dec 21, 2005, 7:57:52 PM12/21/05
to

Sub InitDevices()

Dim Caps As WaveInCaps, x As Long

For x = 0 To waveInGetNumDevs - 1
Call waveInGetDevCaps(x, VarPtr(Caps), Len(Caps))
If Caps.Formats And WAVE_FORMAT_1M16 Then '16-bit mono devices
Call DevicesBox.AddItem(StrConv(Caps.ProductName,
vbUnicode), x)
End If
Next x


That code is supposed to fill a listbox full of the audio devices
available, but I can't seem to be able to convert this to VB.NET. It
really doesn't like the structure(or type) of WaveInCaps. Could anyone
attempt to convert this code over? .Net really complains about
whichever method I use to send the pointer of the structure into the
API.
Any ideas?
Thanks,
Brett

Herfried K. Wagner [MVP]

unread,
Dec 21, 2005, 8:32:47 PM12/21/05
to
<bretts...@hotmail.com> schrieb:

> Dim Caps As WaveInCaps, x As Long
>
> For x = 0 To waveInGetNumDevs - 1
> Call waveInGetDevCaps(x, VarPtr(Caps), Len(Caps))
> If Caps.Formats And WAVE_FORMAT_1M16 Then '16-bit mono devices
> Call DevicesBox.AddItem(StrConv(Caps.ProductName,
> vbUnicode), x)
> End If
> Next x
>
> That code is supposed to fill a listbox full of the audio devices
> available, but I can't seem to be able to convert this to VB.NET.

I have written a small working sample for you :-):

\\\
Private Declare Function waveInGetNumDevs Lib "winmm.dll" () As Int32

Private Declare Auto Function waveInGetDevCaps Lib "winmm.dll" ( _
ByVal uDeviceID As Int32, _
ByRef pwic As WAVEINCAPS, _
ByVal cbwic As Int32 _
) As Int32

Private Const MAXPNAMELEN As Int32 = 32

Private Const MMSYSERR_BASE As Int32 = 0

Private Enum MMRESULT
MMSYSERR_NOERROR = 0
MMSYSERR_ERROR = (MMSYSERR_BASE + 1)
MMSYSERR_BADDEVICEID = (MMSYSERR_BASE + 2)
MMSYSERR_NOTENABLED = (MMSYSERR_BASE + 3)
MMSYSERR_ALLOCATED = (MMSYSERR_BASE + 4)
MMSYSERR_INVALHANDLE = (MMSYSERR_BASE + 5)
MMSYSERR_NODRIVER = (MMSYSERR_BASE + 6)
MMSYSERR_NOMEM = (MMSYSERR_BASE + 7)
MMSYSERR_NOTSUPPORTED = (MMSYSERR_BASE + 8)
MMSYSERR_BADERRNUM = (MMSYSERR_BASE + 9)
MMSYSERR_INVALFLAG = (MMSYSERR_BASE + 10)
MMSYSERR_INVALPARAM = (MMSYSERR_BASE + 11)
MMSYSERR_HANDLEBUSY = (MMSYSERR_BASE + 12)
MMSYSERR_INVALIDALIAS = (MMSYSERR_BASE + 13)
MMSYSERR_BADDB = (MMSYSERR_BASE + 14)
MMSYSERR_KEYNOTFOUND = (MMSYSERR_BASE + 15)
MMSYSERR_READERROR = (MMSYSERR_BASE + 16)
MMSYSERR_WRITEERROR = (MMSYSERR_BASE + 17)
MMSYSERR_DELETEERROR = (MMSYSERR_BASE + 18)
MMSYSERR_VALNOTFOUND = (MMSYSERR_BASE + 19)
MMSYSERR_NODRIVERCB = (MMSYSERR_BASE + 20)
MMSYSERR_LASTERROR = (MMSYSERR_BASE + 20)
End Enum

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Private Structure WAVEINCAPS
Public wMid As Int16
Public wPid As Int16
Public vDriverVersion As Int32
< _
MarshalAs( _
UnmanagedType.ByValTStr, _
SizeConst:=MAXPNAMELEN _
) _
> _
Public szPname As String
Public dwFormats As Int32
Public wChannels As Int16
Public wReserved1 As Int16
End Structure

Private Sub Form1_Load(...) Handles MyBase.Load
Dim Caps As WAVEINCAPS
For i As Integer = 0 To waveInGetNumDevs() - 1
Dim r As MMRESULT = waveInGetDevCaps(i, Caps, Marshal.SizeOf(Caps))
If r = MMRESULT.MMSYSERR_NOERROR Then
MsgBox(Caps.szPname)
Else
Debug.WriteLine("Error " & r.ToString() & " occured!")
End If
Next i
End Sub
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

0 new messages