MCISendCommand Can't find file, but Fstream can so I know it exists, why?

212 Views Asked by At

I'm trying to play a midi file using MCISendCommand but I keep getting a DWORD error code 275 (File Not found). I have since placed the relevant code inside a fstream open call which DOES find the file. I then close the file to allow the MCISendCommand code to access it but it still cannot find the file.

Here is the relevant code:

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;
  }
}

I should also mention that this code works in a sample project from a textbook of mine "Beginning Game Programming" by Michael Morrison. As far as I can tell all project properties are identical. For some reason, however, the code does not work for me in my own project, even though I have since copy/pasted every single line of code over from the sample project (there is not that much, 3/5 small classes).

1

There are 1 best solutions below

0
On

Two things you might want to try:

  1. from the msdn remarks

To use automatic type selection (via the entries in the registry), assign the filename and file extension to the lpstrElementName member of the structure identified by lpOpen, set the lpstrDeviceType member to NULL, and set the MCI_OPEN_ELEMENT flag.

In other words, let the system choose for you the device type, rather than setting it to "Sequencer".

  1. The other thing you can try - some API don't like blank spaces in the path. So you might want to try this theory out by moving your media file to C:\ and remove all (possible) spaces you might have in your file name, and see if that's it.