Search code examples
winapivb6audiomcisendstring

How to specify a sound card for use with mciSendString API


I am updating an old VB6 app. Back in the day, I coded a wrapper around the mciSendString command to be able to record and playback audio. Back then, computers typically had a single audio card.

Now, many of the customers have multiple sound cards (typically a built in one and a USB headset).

I can't seem to find the API to specify which sound card to use with mciSendString. Can someone point me in the right direction?


Solution

  • Microsoft has provided the answer.

    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.

    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)