打开mp3文件时正常,但打开wav, midi文件时返回MCIERR_UNSUPPORTED_FUNCTION(The MCI device driver the system is using does not support the specified command.)。得到的解释是有些设备不能用共享方式打开。但是为什么mp3可以,wav和midi不行呢?
//-----------------------------------------------------------------------------
// LoadAwakeSound()
// 载入提醒声音
// 声音文件名主部和本程序一样,扩展名可以为:WAV, MP3,将依次尝试打开这几个文件
// 声音设备允许共享。本程序不能正常终止,最后设备没有被释放,因此不允许共享的话以后就不能用了。
//-----------------------------------------------------------------------------
int LoadAwakeSound()
{
TCHAR gcFilename[MAX_PATH]; // 声音文件名
PCTSTR ggcExtName[] = {_T("wav"), _T("mp3"), _T("mid")}; // 扩展名列表
PCTSTR ggcDeviceType[] = {_T("waveaudio"), _T("mpegvideo"), _T("sequencer")}; // 声音格式名列表 int const nExtName = sizeof(ggcExtName)/sizeof(PCTSTR); // 扩展名数目
GetExeFileName_WithExt(gcFilename, ggcExtName[0]); // 获取本程序文件名+指定扩展名 MCI_OPEN_PARMS mciOpen;
mciOpen.lpstrDeviceType = ggcDeviceType[0];
mciOpen.lpstrElementName = gcFilename; for (int i =1; i < nExtName +1; ++i) // 载入次数和扩展名数目相同
{
MCIERROR mciError = mciSendCommand(0, MCI_OPEN, // 不知道为什么,wav和midi不能用可共享方式打开
MCI_OPEN_TYPE | MCI_OPEN_ELEMENT | MCI_OPEN_SHAREABLE, (DWORD_PTR)&mciOpen);
if (mciError == 0) // 图像被载入则记录设备编号后返回
{
g_nSoundDeviceId = mciOpen.wDeviceID;
return 0;
}
else if (i == nExtName) // 最后一次载入失败也返回
return -1;
else //  载入失败,改格式和扩展名后继续载入
{
mciOpen.lpstrDeviceType = ggcDeviceType[i];
ChangeFilenameExt(gcFilename, ggcExtName[i]);
mciOpen.lpstrElementName = gcFilename;
}
} return -1; // 绝对到不了这里
}

解决方案 »

  1.   

    FROM MSDN
    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. If the device or file is already open and this flag is not specified, the call will fail even if the first open command specified MCI_OPEN_SHAREABLE. Files opened for the MCISEQ.DRV and MCIWAVE.DRV devices are nonshareable.
    //明确说明了wav和midi不支持共享方式
      

  2.   


    //今天周末,人少吧这个和DRV有关,就像串口绝对不支持共享一样
    //具体的机制不知道,也许要深入一下才能知道为什么。
      

  3.   


    原来这两个就是指的midi和wav...吐血……