请问playsound这样写错在哪里?
c语言吧
全部回复
仅看楼主
level 10
我看了函数库的解释后是这么写的
BOOL PlaySound("hhw.wav", NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);
这个是报错,到底是哪里错了
error C2078: too many initializers
2013年03月24日 07点03分 1
level 7
这个错误不应该是说这个问题吧。。
2013年03月24日 07点03分 2
可是双击以后指在这里了。。
2013年03月24日 07点03分
回复 随机的旋律 :不过这错误是过多的初始化啊 函数调用的话应该是参数个数的问题 你在附近找找试试
2013年03月24日 07点03分
回复 troyhit :前面是输出,后面是Sleep(2000)。。。怎么想怎么没错
2013年03月24日 07点03分
回复 随机的旋律 :再找找吧。。
2013年03月24日 07点03分
level 10
cout << "啊哈哈哈哈哈哈哈,该电脑将在十分钟后关机!" << endl;S2;cout << "(别不信啊,不信你放他十分钟,看他关不关!)" << endl;S2;cout << "(解除方法是win+R,然后打开cmd,输入shutdown -a(注意有空格))" << endl;BOOL PlaySound("hhw.wav", NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);S2;S2;system("shutdown -s -t 600");_getch();
发给同学玩的,他说想让我插个音乐进去,然后就这样了。。S2是宏就是Sleep(2000) @troyhit
2013年03月24日 07点03分 3
调用函数 还需要加返回类型吗?bool多余了吧
2013年03月24日 07点03分
回复 troyhit :查函数库说BOOL必须加,例子也是加了的,而且打上去以后是没有变色的,鼠标放上去是typedef int BOOL
2013年03月24日 07点03分
回复 随机的旋律 :好吧 头一次听说
2013年03月24日 08点03分
回复 troyhit :。。我也是头一次,可是他就这么发生了,而且删掉就更错了。。
2013年03月24日 08点03分
level 7
@随机的旋律
#include "stdafx.h"
#include <iostream>
#include <windows.h>
#include <mmsystem.h>
#pragma comment(lib, "WINMM.LIB")
#define S2 Sleep(2000)
using namespace std;
int main()
{
cout << "啊哈哈哈哈哈哈哈,该电脑将在十分钟后关机!" << endl;
S2;
cout << "(别不信啊,不信你放他十分钟,看他关不关!)" << endl;
S2;
cout << "(解除方法是win+R,然后打开cmd,输入shutdown -a(注意有空格))" << endl;
PlaySound((LPCWSTR)"hhw.wav", NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);
S2;S2;
system("shutdown -s -t 600");
getchar();
}
2013年03月24日 08点03分 4
lpcwstr不是要把音乐放到资源里么?
2013年03月24日 09点03分
回复 随机的旋律 :是指针类型转换吧
2013年03月24日 09点03分
回复 troyhit :你那边成功了是么
2013年03月24日 09点03分
回复 troyhit :还有 "stdafx.h"是什么啊?
2013年03月24日 09点03分
level 11
简单的音乐播放器其实没有什么难度,具体做法看下面的代码:
#include <windows.h>
#include <mmsystem.h>
#include <commctrl.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#pragma comment(lib, "winmm.lib")
int main()
{
char buf[50] = {0}; //存放错误信息
char cmd[100] = "open \"e:\\xx\\xx.mp3\" alias aa_music"; //这里xx是音乐文件路径
MCIERROR mciError;
int mp3_alltime = 0; mciError = mciSendString(cmd, buf, 50, NULL);
if (mciError)
{
printf("%s err1 \n", buf);
return 1;
}
//设置音量
mciSendString("setaudio aa_music to 500", NULL, 0, 0);
//播放音乐
mciError = mciSendString("play aa_music",NULL,0,NULL); //Play music
if (mciError)
{
printf("%s err2 \n", buf);
}
//获取该mp3文件的播放时间
char sPosition[256]; //存取当前播放音乐的总时间
mciSendString("status aa_music length",sPosition,255,0); mp3_alltime = atol(sPosition);
Sleep(mp3_alltime); //这个主要是起到让程序不会挂起,要不然直接结束了。
return 0;
}
2013年03月24日 10点03分 5
level 10
抱歉我是小白,这段代码看的不是太懂,所以复制过来编译了下,然后VS2005的提示:
[$1]>.\main.cpp(65) : error C2664: 'mciSendStringW' : cannot convert parameter 1 from 'char [100]' to 'LPCWSTR'1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast1>.\main.cpp(72) : error C2664: 'mciSendStringW' : cannot convert parameter 1 from 'const char [25]' to 'LPCWSTR'1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast1>.\main.cpp(75) : error C2664: 'mciSendStringW' : cannot convert parameter 1 from 'const char [14]' to 'LPCWSTR'1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast1>.\main.cpp(83) : error C2664: 'mciSendStringW' : cannot convert parameter 1 from 'const char [23]' to 'LPCWSTR'1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
@_SevenMIT
2013年03月24日 11点03分 6
@ __SevenMIT
2013年03月24日 11点03分
回复 随机的旋律 :..@__SevenMIT
2013年03月24日 11点03分
回复 随机的旋律 :这个是用VC6.0啊!
2013年03月24日 12点03分
回复 __SevenMIT :这段代码是完全不能用VS编译么?
2013年03月24日 13点03分
level 14
bool是返回值啊…而且函数…
2013年03月24日 12点03分 7
我把它去掉是报错了的1>.\main.cpp(58) : error C2664: 'PlaySoundW' : cannot convert parameter 1 from 'const char [8]' to 'LPCWSTR'1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast这样
2013年03月24日 13点03分
回复@随机的旋律 :和BOOL没有关系
2013年03月24日 13点03分
你用的什么编译器
2013年03月24日 13点03分
回复 被袭胸的炮姐 :VS2005啊。。
2013年03月24日 14点03分
1