为什么 MCI_OPEN 失败并返回无效的设备 ID?

发布于 2024-08-20 10:25:01 字数 220 浏览 4 评论 0原文

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

错误消息是“设备名称已被此应用程序用作别名。请使用唯一的别名。”

为什么会出错?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

栀子花开つ 2024-08-27 10:25:01

虽然从技术上讲是正确的,但这个答案对我没有多大帮助。

“如果在最初打开设备或文件时未指定 MCI_OPEN_SHAREABLE 标志,则对该设备或文件的所有后续 MCI_OPEN 命令都将失败。”

我发现我必须在任何 MCI_OPEN 之前执行 MCI_CLOSE,如下所示:

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
}

另外,这里有一篇关于对这些音频设备进行编程的非常好的文章。

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

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/

只是偏爱你 2024-08-27 10:25:01

当尝试重新打开已打开的 mci 设备时可能会发生这种情况。

如果在最初打开设备或文件时未指定 MCI_OPEN_SHAREABLE 标志,则对该设备或文件的所有后续 MCI_OPEN 命令都将失败。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文