(Fwd) MCI Problem 
Author Message
 (Fwd) MCI Problem

I am forwarding this message to this newgroup on behalf of a collegue who
does not have net access;

                --- 8< --- Cut Here --- >8 ---

Microsoft Visual C++ MCI Problem

I am having trouble with changing the record settings of a
wave input device before recording a wave file.
The SET command returns error 282  (The parameter is out of range
for the specified command) unless all setting match the default
(which is not the setting I want to use).
I can get around this by openeing a file of zero length that has
the correct setting, but then I would not have the ability to
change them again.
Please Help ...

The article (in my online docs):

        Win32 SDK
                        Media Control Interface
                                        About MCI
                                                Working with MCI devices

states I can use the SET command after opening a new file.

My code follows. Most of it was cut from the online docs:

        Win32 SDK
                        Media Control Interface
                                        Using MCI Command Messages
                                                Recording with a waveform audio device

        // My Code Starts Here

    UINT myDeviceID;  
        DWORD dwReturn;
    MCI_WAVE_SET_PARMS mciWaveSetParms;
    MCI_RECORD_PARMS mciRecordParms;
    MCI_SAVE_PARMS mciSaveParms;
    MCI_OPEN_PARMS mciOpenParms;

    // Open a waveform-audio device with a new file for recording.

    mciOpenParms.lpstrDeviceType = "WaveAudio";
    mciOpenParms.lpstrElementName = "";
    mciOpenParms.lpstrAlias = "";
    if (dwReturn = mciSendCommand(NULL, MCI_OPEN,
                MCI_OPEN_ALIAS |
                MCI_WAIT |
                MCI_OPEN_ELEMENT |
                MCI_OPEN_TYPE ,
        (DWORD)(LPVOID) &mciOpenParms))
        // Failed to open device; don't close it, just return.

        myDeviceID = mciOpenParms.wDeviceID;

        // The device has been successfully opened, now
        // we want to change from the default settings.


        // Default settings :
//      mciWaveSetParms.wBitsPerSample=8;
//      mciWaveSetParms.nSamplesPerSec=11025L;
//      mciWaveSetParms.wFormatTag=WAVE_FORMAT_PCM;
//      mciWaveSetParms.nChannels=1;

        // Note: when using the default settings the SET procedure
        // does not return any errors.
        // However, when any of the parameters here are changed the SET
        // procedure returns error 282. (The parameter is out of range
        // for the specified command)
        // I have been unable to resolve this problem.

        dwReturn = mciSendCommand(myDeviceID, MCI_SET,
                MCI_WAVE_SET_FORMATTAG |
                MCI_WAVE_SET_CHANNELS |
        , (DWORD)(LPVOID) &mciWaveSetParms);

        if (dwReturn != 0)
        char myErrorText[255];
        UINT lenErrorText;
        lenErrorText = 255;    
        if (mciGetErrorString(dwReturn,
                                  lenErrorText  ))
                MessageBox(myErrorText,"Problem :");
                MessageBox("Unknown Error Returned !");

    // Record for 1 second
        mciRecordParms.dwTo = 1000;
    if (dwReturn = mciSendCommand(myDeviceID, MCI_RECORD,
        MCI_TO | MCI_WAIT, (DWORD)(LPVOID) &mciRecordParms))
        mciSendCommand(myDeviceID, MCI_CLOSE, 0, NULL);

        if (MessageBox("Do you want to save this recording?",
        "", MB_YESNO) == IDNO)
        mciSendCommand(myDeviceID, MCI_CLOSE, 0, NULL);

    // Save the recording to a file named TEMPFILE.WAV. Wait for
    // the operation to complete before continuing.
    mciSaveParms.lpfilename = "c:\\wav\\tempfile.wav";
    if (dwReturn = mciSendCommand(myDeviceID, MCI_SAVE,
        MCI_SAVE_FILE | MCI_WAIT, (DWORD)(LPVOID) &mciSaveParms))


        mciSendCommand(myDeviceID, MCI_CLOSE, 0, NULL);

        // My Code Ends Here

Sun, 26 Sep 1999 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. [Fwd: Source Code To Windows 98 (programmer humor) (fwd)]

2. [Fwd: Need help with fprintf problem]


4. [Fwd: MSCOMM32.OCX Disconnect Problem]

5. MCI problem's

6. LNK2001 problem with MCI commands

7. Problems with NT 4.0 and mci commands

8. Problems with MCI

9. Problems with MCI-Timer or serial ports in VC 5.0

10. MCI problems !

11. Problems with MCI....

12. MCI problem


Powered by phpBB® Forum Software