Ashish
Ashish

Reputation: 8529

why MCI_OPEN fails and returns invalid device id?

dwReturn = mciSendCommand(0, MCI_OPEN, MCI_OPEN_ELEMENT | MCI_OPEN_TYPE
                         , (DWORD_PTR)(LPVOID) &mciOpenParms);

error -message is "The device name is already being used as an alias by this application. Use a unique alias."

Why is it giving an error ?

Upvotes: 0

Views: 3055

Answers (2)

user5108_Dan
user5108_Dan

Reputation: 379

While technically correct, this answer didn't help me much.

"If the MCI_OPEN_SHAREABLE flag is not specified when a device or file is initially opened, all subsequent MCI_OPEN commands to the device or file will fail."

I found I had to do an MCI_CLOSE before any MCI_OPEN, like this:

MciClose(void)
{
 int Result;
 MCI_GENERIC_PARMS mciGenericParams;
 DWORD dwFlags;

 mciGenericParams.dwCallback = (long)TestSoundForm->Handle;

 dwFlags = MCI_NOTIFY | MCI_WAIT;
 Result = mciSendCommand(MciDeviceID, MCI_CLOSE, dwFlags, (long)&mciGenericParams);

 // MCIERR_INVALID_DEVICE_ID occurs if the device is already closed.
 if(Result == 0 || Result == MCIERR_INVALID_DEVICE_ID)return;
 else MciError(Result, "MCI_CLOSE  Error"); // display the error
}

Also, here is a very nice article on programming these audio devices.

http://www.c-sharpcorner.com/uploadfile/GemingLeader/creating-a-sound-recorder-in-c-and-C-Sharp/

Upvotes: 1

Ashish
Ashish

Reputation: 8529

This might happen when one attempts to reopen an already opened mci device.

If the MCI_OPEN_SHAREABLE flag is not specified when a device or file is initially opened, all subsequent MCI_OPEN commands to the device or file will fail.

Upvotes: 0

Related Questions