以下是引用心如荒岛在2017-2-11 23:18:57的发言:
编译器报的错误是SND_ASYNC和SND_LOOP未声明这是怎么回事呢?
编译器报的错误是SND_ASYNC和SND_LOOP未声明这是怎么回事呢?
可能是编译器不兼容微软的东西,可以自定义:
#define SND_ASYNC 0x00000001
#define SND_LOOP 0x00000008
#define SND_PURGE 0x00000040
#define SND_FILENAME 0x00020000
如果编译时连接不了库文件(如Winmm.lib),可以在编译器设置连接库文件或动态调用库文件。
如:
#include <stdio.h>
#include <windows.h>
typedef WINBOOL WINAPI (*PLAYSOUND)(LPCSTR, HMODULE, DWORD);
main()
{
HMODULE hLib;
hLib = LoadLibrary("Winmm.dll");
if (hLib == 0) return 0;
PLAYSOUND PlaySound = (PLAYSOUND)GetProcAddress(hLib, "PlaySoundA");
PlaySound("抹去泪水(韩宝仪).wav", NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);
printf("按任一键停止");
getch();
PlaySound(NULL, NULL, SND_PURGE);
FreeLibrary(hLib);
}