Valhalla Legends Forums Archive | C/C++ Programming | Undefined function?

AuthorMessageTime
Eli_1
I'm just trying to port a VB example on playing an mp3 to C++, but when I try to compile it can't find the mciExecute function.

Info on mciExecute:
msdn.microsoft.com/library/en-us/multimed/ htm/_win32_mciexecute.asp

Here's the code I'm using:
[code]
#include <windows.h>
#include <Mmsystem.h>
#include <winuser.h>
#include <stdio.h>
#include <string.h>

int main() {
char *command = new char[512];

   strcpy(command, "OPEN C:\WINDOWS\DESKTOP\KYLES\My Shared Folder\soil test.mp3 TYPE CDAUDIO ALIAS mp3test");
   mciExecute(command);
   strcpy(command, "PLAY mp3test WAIT");
   mciExecute(command);
   strcpy(command, "CLOSE mp3test");
   mciExecute(command);

   delete command;
   return 0;
}
[/code]

Any help would be appreciated :-\
April 12, 2004, 7:46 PM
Eibro
strcpy(command, "OPEN C:\WINDOWS\DESKTOP\KYLES\My Shared Folder\soil test.mp3 TYPE CDAUDIO ALIAS mp3test");
You need to use / for directories, or a double backslash (\\). A single backslash is interpreted as an escape sequence by the compiler.
April 12, 2004, 8:04 PM
Eli_1
[quote author=Eibro link=board=30;threadid=6276;start=0#msg54807 date=1081800291]
strcpy(command, "OPEN C:\WINDOWS\DESKTOP\KYLES\My Shared Folder\soil test.mp3 TYPE CDAUDIO ALIAS mp3test");
You need to use / for directories, or a double backslash (\\). A single backslash is interpreted as an escape sequence by the compiler.
[/quote]
Oh yea, I keep forgetting about that. Thanks, Eibro. I still don't know why it isn't finding that function though.
April 12, 2004, 8:08 PM
K
The page you linked to was a 404 for me, but I assume the problem is that you need to link against Winmm.lib.
April 12, 2004, 9:07 PM
Eli_1
Ok, I did some more searching on google, and I couldn't find a single example in C++ that used mciExecute. But I did see tons of examples using mciSendString, so that's what I ended up using, and it works flawlessly now.

Another problem I was having is trying to use an incorrect MCI device for playing mp3's. I found out I actually need to use MPEGVideo and not cdaudio like I was trying to use in my first post.

Stated in Win.ini:
[quote]
[mci extensions]
...
wav=waveaudio
avi=AVIVideo
mp3=MPEGVideo
...
[/quote]

Here's the new working code:
[code]
/* Main.cpp
* This will the song 'Soil - Redefine' :-O
*/
#include <windows.h>
#include <mmsystem.h>
#include <winuser.h> // <-- I don't think this is needed
#include <stdio.h>
#include <string.h>

int main() {
char *command = new char[512];
int i;
   /* I found out that the main reason I was failing
    * was that I was using the wrong type of device to
    * to play files with an mp3 extension.
    * I later noticed that I need to use 'MPEGVideo' and 'MPEGVideo2'
    * for almost everything, as stated in WIN.ini
    */
   
   /* Open my file */
   strcpy(command, "open c:\\soil.mp3 type MPEGVideo alias mp3test wait");
   i = mciSendString(command, NULL, 0, 0);
   if (i != 0) {
      char buffer[128];
      mciGetErrorString(i, buffer, 128);
      printf("Error in 'open': %s\n", buffer);
   }
   
   /* Play the file. */
   strcpy(command, "play mp3test wait");
   i = mciSendString(command, NULL, 0, 0);
   if (i != 0) {
      char buffer[128];
      mciGetErrorString(i, buffer, 128);
      printf("Error in 'play': %s\n", buffer);
   }
   
   /*
    * Sending "all" in the with the 'close' command will
    * close all devices opened by this app.
    */

   strcpy(command, "close all wait");
   mciSendString(command, NULL, 0, 0);
   delete command; // !! :D
   return 0;
}   
[/code]
April 12, 2004, 11:23 PM

Search