HOWTO: Select Soundcard in Visual Basic with Multimedia Control

Last reviewed: February 2, 1998
Article ID: Q180032
The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Windows 95
        - Windows NT
    

SUMMARY

This article describes how to set the WaveAudio device (soundcard) used by the Multimedia Control (MCI32.ocx) using Visual Basic.

MORE INFORMATION

To set the WaveAudio device (soundcard) used by the Multimedia Control, you must use the mciSendCommand API. The Multimedia Control does not directly provide a method to let you set the device used for playing or recording.

The following Visual Basic sample code shows how to use mciSendCommand to specify the device used for WaveAudio output.

Sample Code

Following are the required definitions and declarations. Place these in a module file:

   Public Const MMSYSERR_NOERROR = 0
   Public Const MCI_SET = &H80D
   Public Const MCI_WAVE_OUTPUT = &H800000
   Type MCI_WAVE_SET_PARMS
       dwCallback As Long
       dwTimeFormat As Long
       dwAudio As Long
       wInput As Long
       wOutput As Long
       wFormatTag As Integer
       wReserved2 As Integer
       nChannels As Integer
       wReserved3 As Integer
       nSamplesPerSec As Long
       nAvgBytesPerSec As Long
       nBlockAlign As Integer
       wReserved4 As Integer
       wBitsPerSample As Integer
       wReserved5 As Integer
   End Type

   Declare Function mciGetErrorString Lib "winmm.dll" _
       Alias "mciGetErrorStringA" (ByVal dwError As Long, _
       ByVal lpstrBuffer As String, ByVal uLength As Long) As Long

   Declare Function mciSendCommand Lib "winmm.dll" Alias _
       "mciSendCommandA" (ByVal wDeviceID As Long, _
       ByVal uMessage As Long, ByVal dwParam1 As Long, _
       ByRef dwParam2 As Any) As Long

Sample Code

The following code sets the output device. This code assumes that you have a Multimedia Control called "MMControl1." This code should be called after the wave file to be played has been opened by MMControl1.

    Dim parms As MCI_WAVE_SET_PARMS
    Dim rc As Long

    ' Specify the soundcard. This specifies the soundcard with a deviceID
    ' of 0. If you have a single soundcard, then this will open it. If you
    ' have multiple soundcards, the deviceIDs will be 0, 1, 2, etc.
    parms.wOutput = 0

    ' Send the MCI command to set the output device.
    rc = mciSendCommand(MMControl1.DeviceID, MCI_SET, _
        MCI_WAVE_OUTPUT, parms)

    if (rc <> MMSYSERR_NOERROR) then
        ' The command failed.
    End If

REFERENCES

See the mciSendCommand documentation in the Win32 SDK documentation.

Keywords          : MMWave kbcode
Version           : WINNT:4.0;WIN95
Platform          : Win95 winnt
Issue type        : kbhowto


================================================================================


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: February 2, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.