How to check if a computer has a playback or input Soundcard in VB and VB.NET

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
 

Thankfully, Microsoft has a couple simple little API calls that will determine how many playback devices the target computer has and how many audio input devices for recording. The API calls are listed below…


Visual Basic.NET, Visual Basic 2008, VB 2010, VB 2013

   Private Declare Function waveOutGetNumDevs Lib "winmm.dll" Alias "waveOutGetNumDevs" () As Int32

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

Then you simply need to call those 2 functions and check what the retturn value. The return value will be how many devices on the target computer with playback and input capabilities. And if it happens to return a 0, then the computer does not have any…

        Dim audioPlaybackDevices As Int32

        Dim audioInputDevices As Int32

        audioInputDevices = waveInGetNumDevs

        audioPlaybackDevices = waveOutGetNumDevs

        MsgBox("This computer has: " & audioPlaybackDevices.ToString & " playback devices")

        MsgBox("This computer also has: " & audioInputDevices.ToString & " recording devices")

Visual Basic 6.0

VB 6.0 uses the same functions as .NET but with Long types instead of Integer.

    Private Declare Function waveOutGetNumDevs Lib "winmm.dll" () As Long

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

 


        Dim audioPlaybackDevices As Long

        Dim audioInputDevices As Long

        audioInputDevices = waveInGetNumDevs

        audioPlaybackDevices = waveOutGetNumDevs

        MsgBox("This computer has: " & audioPlaybackDevices & " playback devices")

        MsgBox("This computer also has: " & audioInputDevices & " recording devices")


That’s all there is to it for VB Classic and for Visual Basic.NET.     🙂

Jason

Minor Revision: 2015

2 thoughts on “How to check if a computer has a playback or input Soundcard in VB and VB.NET

  1. Jason Post author

    Hi, directshow should be able to make it pretty easy. There is DirectShow.NET if you use VB.NET. There are some libraries for VB 5/6.0 as well.

    If you don’t need the sound then you can use the BitBlt API to copy the screen a certain amount of times a second and then use the Windows Media Encoder library to compile the images as a .wmv movie format.

    I don’t have any specific code for either way though. Directshow would probably be the best way to do it.

    Jason

    Reply

Leave a Reply

Your email address will not be published.