-
Mp3 play - MCI
Greetings!
I tried to play an mp3 using MCI function, play(). But Visual C++ 6.0 doesn’t recognize the function. Below is what I have written.
Code:
#define _WIN32_WINNT 0x0501
#define WINVER 0x0501
#include "stdafx.h"
DWORD Play(LPSTR lpstrAlias)
{
char achCommandBuff[128];
wsprintf(achCommandBuff, "play ", lpstrAlias);
return mciSendString(achCommandBuff, NULL, 0, NULL);
}
int main(int argc, char* argv[])
{
Play("C:\\Program Files\\Britannica\\2002\\multimedia\\mp3\\oharp00004u2.mp3");
return 0;
}
What are the means of fixing this problem?
Thanks.
-geek@02
-
#include <windows.h> and link with winmm.lib. See mciSendString for details. In general, the required header and library are listed at the bottom of the relevant msdn page for each api function.
Although that should enable you to compile and link your code it probably won't run as expected; this article discusses (console example, too) how to properly format the mci string (the lpstrAlias in your 'Play' function) to enable mp3 file playing.
-
Sorry to bother you again.
What must I do to link a library?
-
Add any library names in the linker option of your project settings for msvc6.
A quick and dirty way if using, in particular, ms compilers is to use a #pragma, for example:
Code:
#pragma comment(lib, "winmm.lib")
but I wouldn't advise making a habit of that as it's not supported by many compilers.
-
OK. Thanks a lot for the artical and the help.