我正在尝试使用 MCISendCommand 播放 MIDI 文件,但我不断收到 DWORD 错误代码 275(找不到文件)。从那以后,我将相关代码放在确实找到文件的 fstream open 调用中。然后我关闭该文件以允许 MCISendCommand 代码访问它,但它仍然找不到该文件。
以下是相关代码:
fstream f;
f.open(szMIDIFileName);
if(f.is_open())
// Then the file exists
{
f.close();
// See if the MIDI player needs to be opened
if (m_uiMIDIPlayerID == 0)
{
// Open the MIDI player by specifying the device and filename
MCI_OPEN_PARMS mciOpenParms;
mciOpenParms.lpstrDeviceType = "sequencer";
mciOpenParms.lpstrElementName = szMIDIFileName; //The name of the file passed in as a param
if (mciSendCommand(NULL, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT,
(DWORD_PTR)&mciOpenParms) == 0)
// Get the ID for the MIDI player
m_uiMIDIPlayerID = mciOpenParms.wDeviceID;
else
// There was a problem, so just return
// This is where I keep ending up in my code with DWORD error 275
return;
}
}
我还应该提到,这段代码在我的迈克尔·莫里森 (Michael Morrison) 的教科书“开始游戏编程”中的示例项目中工作。据我所知,所有项目属性都是相同的。然而,由于某种原因,代码在我自己的项目中对我不起作用,即使我已经从示例项目中复制/粘贴了每一行代码(没有那么多,3/5 的小类)。