| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2417 人关注过本帖
标题:【课程设计】求教PlaySound()的使用指导
只看楼主 加入收藏
最大机密
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2010-6-23
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:15 
【课程设计】求教PlaySound()的使用指导
我还是大一的学生,这次的课程设计,想做些没有做过的东西,就选了这么一道题,题目是模拟十位以内数字的读音。
为了了解如何使用VC++6.0发音(我们还没有学。才学到类),我用Google查了一下,要使用到PlaySound()函数,所以编了一个小程序来测试一下这个函数的使用方法,程序如下:
===========================================
#include<iostream.h>
using namespace std;
void main()
{
    PlaySound(c:\\test.wav,NULL,SND_SYNC);
}
===========================================
发现没有相应的头文件。
然后把程序改成
===========================================
#include<iostream.h>
#include<mmsystem.h>
using namespace std;
void main()
{
    PlaySound(c:\\test.wav,NULL,SND_SYNC);
}
===========================================
返回错误如下:
--------------------Configuration: Cpp1 - Win32 Debug--------------------
Compiling...
Cpp1.cpp
d:\编程软件\vc6.0\vc98\include\mmsystem.h(113) : error C2146: syntax error : missing ';' before identifier 'MMVERSION'
d:\编程软件\vc6.0\vc98\include\mmsystem.h(113) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.


Cpp1.obj - 1 error(s), 0 warning(s)
===========================================
然后又去查找资料,先后在开头添加了
#include<winmm.lib>
#pragma   comment(lib,   "winmm.lib ")
返回的错误都没有变。请问这是因为什么问题呢?

搜索更多相关主题的帖子: PlaySound 课程 指导 设计 
2010-06-23 19:50
最大机密
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2010-6-23
收藏
得分:0 
对了,补充一下,在VS2008里面,运行相同的代码,报错的结果是
1>------ 已启动生成: 项目: Test Sound, 配置: Debug Win32 ------
1>正在编译...
1>Cpp1.cpp
1>c:\我的文档\桌面\cpp1.cpp(2) : fatal error C1083: 无法打开包括文件:“mmsystem”: No such file or directory
1>生成日志保存在“file://c:\我的文档\Visual Studio 2008\Projects\Test Sound\Test Sound\Debug\BuildLog.htm”
1>Test Sound - 1 个错误,0 个警告
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
求指导。。。
2010-06-23 20:22
debroa723
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:23
帖 子:862
专家分:1954
注 册:2008-10-12
收藏
得分:0 
可能性比较多,而你提供的线索太少,最好把mmsystem.h内容发上来,特别是第 113 行的代码注出来,才能做进一步的诊断。
2010-06-23 20:23
最大机密
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2010-6-23
收藏
得分:0 
回复 3楼 debroa723
好的,稍等。
2010-06-23 20:27
最大机密
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2010-6-23
收藏
得分:0 
回复 3楼 debroa723
mmsystem.h的内容如下,红色的是指向的错误行。
====================================================================
/*==========================================================================
 *
 *  mmsystem.h -- Include file for Multimedia API's
 *
 *  Version 4.00
 *
 *  Copyright 1992 - 1998 Microsoft Corporation.  All Rights Reserved.
 *
 *--------------------------------------------------------------------------
 *
 *  Define:         Prevent inclusion of:
 *  --------------  --------------------------------------------------------
 *  MMNODRV         Installable driver support
 *  MMNOSOUND       Sound support
 *  MMNOWAVE        Waveform support
 *  MMNOMIDI        MIDI support
 *  MMNOAUX         Auxiliary audio support
 *  MMNOMIXER       Mixer support
 *  MMNOTIMER       Timer support
 *  MMNOJOY         Joystick support
 *  MMNOMCI         MCI support
 *  MMNOMMIO        Multimedia file I/O support
 *  MMNOMMSYSTEM    General MMSYSTEM functions
 *
 *==========================================================================
 */

#ifndef _INC_MMSYSTEM
#define _INC_MMSYSTEM   /* #defined if mmsystem.h has been included */

#ifdef _WIN32
#include <pshpack1.h>
#else
#ifndef RC_INVOKED
#pragma pack(1)
#endif
#endif

#ifdef __cplusplus
extern "C" {            /* Assume C declarations for C++ */
#endif  /* __cplusplus */

#ifdef _WIN32
#ifndef _WINMM_
#define    WINMMAPI    DECLSPEC_IMPORT
#else
#define    WINMMAPI
#endif
#define _loadds
#define _huge
#else
#define    WINMMAPI
#endif

#ifdef _WIN32_VXD

#define NEAR
#define FAR

#define DECLARE_HANDLE(x) typedef WORD x
#define WINAPI

typedef DWORD LPSTR;
typedef DWORD LPVOID;
typedef DWORD LPCSTR;
typedef DWORD LPCWSTR;
typedef DWORD LRESULT;
typedef DWORD LPARAM;
typedef DWORD WPARAM;

typedef short WCHAR;

#endif

/****************************************************************************

            General constants and data types

****************************************************************************/

/* general constants */
#define MAXPNAMELEN      32     /* max product name length (including NULL) */
#define MAXERRORLENGTH   256    /* max error text length (including NULL) */
#define MAX_JOYSTICKOEMVXDNAME 260 /* max oem vxd name length (including NULL) */

/*
 *  Microsoft Manufacturer and Product ID's (these have been moved to
 *  MMREG.H for Windows 4.00 and above).
 */
#if (WINVER <= 0x030A)
#ifndef MM_MICROSOFT
#define MM_MICROSOFT            1   /* Microsoft Corporation */
#endif

#ifndef MM_MIDI_MAPPER
#define MM_MIDI_MAPPER          1   /* MIDI Mapper */
#define MM_WAVE_MAPPER          2   /* Wave Mapper */
#define MM_SNDBLST_MIDIOUT      3   /* Sound Blaster MIDI output port */
#define MM_SNDBLST_MIDIIN       4   /* Sound Blaster MIDI input port */
#define MM_SNDBLST_SYNTH        5   /* Sound Blaster internal synthesizer */
#define MM_SNDBLST_WAVEOUT      6   /* Sound Blaster waveform output */
#define MM_SNDBLST_WAVEIN       7   /* Sound Blaster waveform input */
#define MM_ADLIB                9   /* Ad Lib-compatible synthesizer */
#define MM_MPU401_MIDIOUT      10   /* MPU401-compatible MIDI output port */
#define MM_MPU401_MIDIIN       11   /* MPU401-compatible MIDI input port */
#define MM_PC_JOYSTICK         12   /* Joystick adapter */
#endif
#endif

/* general data types */

#ifdef _WIN32
typedef UINT        MMVERSION;  /* major (high byte), minor (low byte) */
#else
typedef UINT        VERSION;    /* major (high byte), minor (low byte) */
#endif
typedef UINT        MMRESULT;   /* error return code, 0 means no error */
                /* call as if(err=xxxx(...)) Error(err); else */
#define _MMRESULT_

typedef UINT FAR   *LPUINT;

/* MMTIME data structure */
typedef struct mmtime_tag
{
    UINT            wType;      /* indicates the contents of the union */
    union
    {
    DWORD       ms;         /* milliseconds */
    DWORD       sample;     /* samples */
    DWORD       cb;         /* byte count */
    DWORD       ticks;      /* ticks in MIDI stream */

    /* SMPTE */
    struct
    {
        BYTE    hour;       /* hours */
        BYTE    min;        /* minutes */
        BYTE    sec;        /* seconds */
        BYTE    frame;      /* frames  */
        BYTE    fps;        /* frames per second */
        BYTE    dummy;      /* pad */
#ifdef _WIN32
        BYTE    pad[2];
#endif
    } smpte;

    /* MIDI */
    struct
    {
        DWORD songptrpos;   /* song pointer position */
    } midi;
    } u;
} MMTIME, *PMMTIME, NEAR *NPMMTIME, FAR *LPMMTIME;

/* types for wType field in MMTIME struct */
#define TIME_MS         0x0001  /* time in milliseconds */
#define TIME_SAMPLES    0x0002  /* number of wave samples */
#define TIME_BYTES      0x0004  /* current byte offset */
#define TIME_SMPTE      0x0008  /* SMPTE time */
#define TIME_MIDI       0x0010  /* MIDI time */
#define TIME_TICKS      0x0020  /* Ticks within MIDI stream */

/*
 *
 *
 */
#define MAKEFOURCC(ch0, ch1, ch2, ch3)                              \
        ((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) |   \
        ((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24 ))
2010-06-23 20:32
最大机密
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2010-6-23
收藏
得分:0 
太长了,论坛提示说只能发3W字,下面一个标签后面的内容我都删掉了,还要么?
2010-06-23 20:33
最大机密
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2010-6-23
收藏
得分:0 
回复 3楼 debroa723
不过话说。。。头文件也会有错的吗?
2010-06-23 20:35
debroa723
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:23
帖 子:862
专家分:1954
注 册:2008-10-12
收藏
得分:0 
mmsystem.h是VC的文件呀。
看来不是它的问题,你能把工程上传来看看吗?
2010-06-23 20:48
debroa723
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:23
帖 子:862
专家分:1954
注 册:2008-10-12
收藏
得分:0 
PlaySound的参数应该是字符串呀。才看到。
PlaySound("c:\\test.wav",NULL,SND_SYNC);
要双引号引起来。
2010-06-23 20:51
最大机密
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2010-6-23
收藏
得分:0 
回复 9楼 debroa723
加了""还是不行。
cpp1.rar (351.87 KB)
2010-06-24 20:02
快速回复:【课程设计】求教PlaySound()的使用指导
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017994 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved