VB3 How to Detect If Your Computer Has a Sound Card

Last reviewed: January 9, 1997
Article ID: Q123974
The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic for

  Windows, versions 2.0 and 3.0

SUMMARY

It is often useful to be able to detect if a system has a sound card capable of playing back wave audio data (.WAV files). This article demonstrates how to do this.

MORE INFORMATION

The multimedia Application Programming Interface (API) has a function, waveOutGetNumDevs(), which returns the number of devices in the system capable of playing back wave audio data.

Step by Step Example

  1. Start a new project in Visual Basic (ALT, F, N), and place a Command' button (Command1) on Form1.

  2. Add the following declaration to the General Declarations section of Form1:

       Declare Function waveOutGetNumDevs Lib "MMSYSTEM" () As Integer
    
    

  3. Add the following code to the Command1_Click event:

       Sub Command1_Click ()
          Dim i As Integer
    
          i = waveOutGetNumDevs()
          If i > 0 Then         ' There is at least one.
             MsgBox "You Can Play Wave Data"
          Else
             MsgBox "Cannot Play Wave Data"
          End If
       End Sub
    
    

  4. Press the F5 key to run the code. Then click the command button. An appropriate message will let you know if your computer play wave audio data.


KBCategory: kbprg kbsound
KBSubCategory: APrgWindow
Additional reference words: 2.00 3.00 vb3only


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 9, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.